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

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



70
    SECTION("subDir 1")
40
    {
41





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




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




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




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




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




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




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




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



70
    SECTION("subDir 1.2")
57
    {
58





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





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





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





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




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




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




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




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




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



70
    SECTION("subDir 2")
76
    {
77





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





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





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





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




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




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




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




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




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



70
    SECTION("subDir 3")
95
    {
96





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





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





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





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





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





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




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




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




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




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




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




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




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




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




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



70
    SECTION("subDir 4")
124
    {
125





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





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





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





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





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





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




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




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




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




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




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




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




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




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




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



70
    SECTION("subDir 5")
153
    {
154





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





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





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





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





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






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





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




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




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




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





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




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




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




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




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




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




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




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




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





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



70
    SECTION("subDir 6")
190
    {
191





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





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





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





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





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







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





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




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





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




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




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




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




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




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





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




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




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





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




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




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



70
    SECTION("subDir 7")
229
    {
230




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





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




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





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





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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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



70
    SECTION("subDir 8")
263
    {
264




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





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




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





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





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




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




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




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




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




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




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




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




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




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





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




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




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




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




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




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



70
    SECTION("subDir 9")
297
    {
298





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




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





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




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




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




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




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




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




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

13
}