GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_mountdir2.cc Lines: 160 160 100.0 %
Date: 2017-11-29 Branches: 1099 2758 39.8 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2016-2017  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
24
TEST_CASE("VirtFs1 mountDir2", "")
35
{
36

80
    VirtFs::init(".");
37
80
    const std::string sep = dirSeparator;
38



140
    SECTION("subDir 1")
39
    {
40





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




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




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




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




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




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




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




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



140
    SECTION("subDir 1.2")
56
    {
57





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





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





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





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




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




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




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




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




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



140
    SECTION("subDir 2")
75
    {
76





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





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





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





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




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




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




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




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




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



140
    SECTION("subDir 3")
94
    {
95





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





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





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





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





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





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




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




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




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




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




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




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




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




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




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



140
    SECTION("subDir 4")
123
    {
124





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





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





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





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





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





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




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




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




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




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




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




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




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




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




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



140
    SECTION("subDir 5")
152
    {
153





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





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





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





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





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






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





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




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




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




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





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




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




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




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




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




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




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




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




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





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



140
    SECTION("subDir 6")
189
    {
190





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





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





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





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





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







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





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




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





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




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




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




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




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




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





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




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




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





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




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




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



140
    SECTION("subDir 7")
228
    {
229




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





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




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





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





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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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



140
    SECTION("subDir 8")
262
    {
263




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





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




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





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





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




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




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




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




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




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




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




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




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




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





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




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




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




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




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




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



140
    SECTION("subDir 9")
296
    {
297





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




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





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




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




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




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




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




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




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

26
}