GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_mountdir2.cc Lines: 160 160 100.0 %
Date: 2018-11-12 Branches: 1098 2756 39.8 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2016-2018  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "unittests/unittests.h"
22
23
#include "fs/virtfs/direntry.h"
24
#include "fs/virtfs/fs.h"
25
26
#include "utils/checkutils.h"
27
28
#ifndef UNITTESTS_CATCH
29
#include <algorithm>
30
#endif  // UNITTESTS_CATCH
31
32
#include "debug.h"
33
34
12
TEST_CASE("VirtFs1 mountDir2", "")
35
{
36
30
    VirtFs::init(".");
37
40
    const std::string sep = dirSeparator;
38



70
    SECTION("subDir 1")
39
    {
40





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
41
            dirSeparator,
42
            Append_false));
43




7
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
44
            nullptr);
45




7
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
46
            nullptr);
47




5
        REQUIRE(VirtFs::getEntries().size() == 1);
48




5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
49




4
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
50




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
51




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
52
            VirtFs::getEntries()[0])->userDir == "dir1");
53
    }
54
55



70
    SECTION("subDir 1.2")
56
    {
57





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
58
            "dir2",
59
            Append_false));
60





6
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) !=
61
            nullptr);
62





6
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) ==
63
            nullptr);
64





6
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) ==
65
            nullptr);
66




5
        REQUIRE(VirtFs::getEntries().size() == 1);
67




5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
68




5
        REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep);
69




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
70




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
71
            VirtFs::getEntries()[0])->userDir == "dir1");
72
    }
73
74



70
    SECTION("subDir 2")
75
    {
76





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1/",
77
            "dir2",
78
            Append_true));
79





6
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) !=
80
            nullptr);
81





6
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) ==
82
            nullptr);
83





6
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) ==
84
            nullptr);
85




5
        REQUIRE(VirtFs::getEntries().size() == 1);
86




5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
87




5
        REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep);
88




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
89




5
        REQUIRE(static_cast<VirtFs::DirEntry*>(
90
            VirtFs::getEntries()[0])->userDir == "dir1" + sep);
91
    }
92
93



70
    SECTION("subDir 3")
94
    {
95





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
96
            "dir3",
97
            Append_false));
98





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir2",
99
            "dir4",
100
            Append_false));
101





6
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) !=
102
            nullptr);
103





6
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) ==
104
            nullptr);
105





6
        REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) !=
106
            nullptr);
107





6
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) ==
108
            nullptr);
109




5
        REQUIRE(VirtFs::getEntries().size() == 2);
110




5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir2" + sep);
111




5
        REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
112




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
113




4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
114




5
        REQUIRE(VirtFs::getEntries()[0]->subDir == "dir4" + sep);
115




5
        REQUIRE(VirtFs::getEntries()[1]->subDir == "dir3" + sep);
116




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
117
            VirtFs::getEntries()[0])->userDir == "dir2");
118




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
119
            VirtFs::getEntries()[1])->userDir == "dir1");
120
    }
121
122



70
    SECTION("subDir 4")
123
    {
124





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1\\",
125
            "dir3",
126
            Append_true));
127





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir2",
128
            "dir4",
129
            Append_true));
130





6
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) !=
131
            nullptr);
132





6
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) ==
133
            nullptr);
134





6
        REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) !=
135
            nullptr);
136





6
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) ==
137
            nullptr);
138




5
        REQUIRE(VirtFs::getEntries().size() == 2);
139




5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
140




5
        REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep);
141




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
142




4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
143




5
        REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep);
144




5
        REQUIRE(VirtFs::getEntries()[1]->subDir == "dir4" + sep);
145




5
        REQUIRE(static_cast<VirtFs::DirEntry*>(
146
            VirtFs::getEntries()[0])->userDir == "dir1" + sep);
147




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
148
            VirtFs::getEntries()[1])->userDir == "dir2");
149
    }
150
151



70
    SECTION("subDir 5")
152
    {
153





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
154
            "dir3",
155
            Append_true));
156





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir2",
157
            "dir4",
158
            Append_true));
159





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir3/test",
160
            "dir5",
161
            Append_true));
162





6
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) !=
163
            nullptr);
164





6
        REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) !=
165
            nullptr);
166






8
        REQUIRE(VirtFs::searchByRootInternal(
167
            "dir3" + sep + "test" + sep, "dir5" + sep) != nullptr);
168





6
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) ==
169
            nullptr);
170




5
        REQUIRE(VirtFs::getEntries().size() == 3);
171




5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
172




5
        REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep);
173





7
        REQUIRE(VirtFs::getEntries()[2]->root == "dir3" + sep + "test" + sep);
174




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
175




4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
176




4
        REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Dir);
177




5
        REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep);
178




5
        REQUIRE(VirtFs::getEntries()[1]->subDir == "dir4" + sep);
179




5
        REQUIRE(VirtFs::getEntries()[2]->subDir == "dir5" + sep);
180




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
181
            VirtFs::getEntries()[0])->userDir == "dir1");
182




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
183
            VirtFs::getEntries()[1])->userDir == "dir2");
184





6
        REQUIRE(static_cast<VirtFs::DirEntry*>(
185
            VirtFs::getEntries()[2])->userDir == "dir3" + sep + "test");
186
    }
187
188



70
    SECTION("subDir 6")
189
    {
190





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
191
            "dir1",
192
            Append_true));
193





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir2",
194
            "dir2",
195
            Append_true));
196





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir3\\test",
197
            "dir3\\test",
198
            Append_false));
199





7
        REQUIRE(VirtFs::searchByRootInternal(
200
            "dir1" + sep + "", "dir1" + sep) != nullptr);
201





7
        REQUIRE(VirtFs::searchByRootInternal(
202
            "dir2" + sep + "", "dir2" + sep) != nullptr);
203







10
        REQUIRE(VirtFs::searchByRootInternal(
204
            "dir3" + sep + "test" + sep,
205
            "dir3" + sep + "test" + sep) != nullptr);
206





7
        REQUIRE(VirtFs::searchByRootInternal(
207
            "test" + sep + "", "dir1" + sep) == nullptr);
208




5
        REQUIRE(VirtFs::getEntries().size() == 3);
209





7
        REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep + "test" + sep);
210




5
        REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
211




5
        REQUIRE(VirtFs::getEntries()[2]->root == "dir2" + sep);
212




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
213




4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
214




4
        REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Dir);
215





7
        REQUIRE(VirtFs::getEntries()[0]->subDir ==
216
            "dir3" + sep + "test" + sep);
217




5
        REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1" + sep);
218




5
        REQUIRE(VirtFs::getEntries()[2]->subDir == "dir2" + sep);
219





6
        REQUIRE(static_cast<VirtFs::DirEntry*>(
220
            VirtFs::getEntries()[0])->userDir == "dir3" + sep + "test");
221




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
222
            VirtFs::getEntries()[1])->userDir == "dir1");
223




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
224
            VirtFs::getEntries()[2])->userDir == "dir2");
225
    }
226
227



70
    SECTION("subDir 7")
228
    {
229




6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
230
            Append_true));
231





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
232
            "dir2",
233
            Append_true));
234




7
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
235
            nullptr);
236





6
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) !=
237
            nullptr);
238





6
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) ==
239
            nullptr);
240




5
        REQUIRE(VirtFs::getEntries().size() == 2);
241




5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
242




4
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
243




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
244




5
        REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
245




5
        REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep);
246




4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
247




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
248
            VirtFs::getEntries()[0])->userDir == "dir1");
249




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
250
            VirtFs::getEntries()[1])->userDir == "dir1");
251
252




6
        REQUIRE(VirtFs::unmountDirSilent("dir1"));
253




5
        REQUIRE(VirtFs::getEntries().size() == 1);
254




5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
255




5
        REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep);
256




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
257




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
258
            VirtFs::getEntries()[0])->userDir == "dir1");
259
    }
260
261



70
    SECTION("subDir 8")
262
    {
263




6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
264
            Append_true));
265





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
266
            "dir2",
267
            Append_true));
268




7
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
269
            nullptr);
270





6
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) !=
271
            nullptr);
272





6
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) ==
273
            nullptr);
274




5
        REQUIRE(VirtFs::getEntries().size() == 2);
275




5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
276




4
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
277




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
278




5
        REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
279




5
        REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep);
280




4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
281




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
282
            VirtFs::getEntries()[0])->userDir == "dir1");
283




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
284
            VirtFs::getEntries()[1])->userDir == "dir1");
285
286





9
        REQUIRE(VirtFs::unmountDirSilent2("dir1", "dir2"));
287




5
        REQUIRE(VirtFs::getEntries().size() == 1);
288




5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
289




4
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
290




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
291




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
292
            VirtFs::getEntries()[0])->userDir == "dir1");
293
    }
294
295



70
    SECTION("subDir 9")
296
    {
297





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
298
            dirSeparator,
299
            Append_false));
300




7
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
301
            nullptr);
302





8
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") ==
303
            nullptr);
304




7
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
305
            nullptr);
306




5
        REQUIRE(VirtFs::getEntries().size() == 1);
307




5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
308




4
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
309




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
310




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
311
            VirtFs::getEntries()[0])->userDir == "dir1");
312
    }
313
314
10
    VirtFs::deinit();
315

13
}