GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_unmount.cc Lines: 200 200 100.0 %
Date: 2021-03-17 Branches: 1415 3514 40.3 %

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/files.h"
25
26
#include "fs/virtfs/direntry.h"
27
#include "fs/virtfs/fs.h"
28
29
#include "utils/checkutils.h"
30
31
#ifndef UNITTESTS_CATCH
32
#include <algorithm>
33
#endif  // UNITTESTS_CATCH
34
35
#include "debug.h"
36
37
12
TEST_CASE("VirtFs1 unmount", "")
38
{
39
40
    VirtFs::init(".");
40
40
    std::string name("data/test/test.zip");
41
20
    std::string prefix;
42
40
    const std::string sep = dirSeparator;
43

10
    if (Files::existsLocal(name) == false)
44
        prefix = "../";
45
46



70
    SECTION("simple 2")
47
    {
48




6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
49
            Append_true));
50




6
        REQUIRE(VirtFs::unmountDir("dir1"));
51
    }
52
53



70
    SECTION("simple 3")
54
    {
55




6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
56
            Append_true));
57




6
        REQUIRE(VirtFs::mountDirSilentTest("dir2//dir3",
58
            Append_true));
59




6
        REQUIRE(VirtFs::mountDirSilentTest("dir3",
60
            Append_false));
61




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




6
        REQUIRE(VirtFs::unmountDir("dir1"));
63




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




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




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




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




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
68
            VirtFs::getEntries()[0])->userDir == "dir3");
69





7
        REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep + "dir3" + sep);
70




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




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





6
        REQUIRE(static_cast<VirtFs::DirEntry*>(
73
            VirtFs::getEntries()[1])->userDir == "dir2" + sep + "dir3");
74




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




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




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




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




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
79
            VirtFs::getEntries()[0])->userDir == "dir3");
80





7
        REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep + "dir3" + sep);
81




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




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





6
        REQUIRE(static_cast<VirtFs::DirEntry*>(
84
            VirtFs::getEntries()[1])->userDir == "dir2" + sep + "dir3");
85




6
        REQUIRE(VirtFs::unmountDir("dir2/dir3"));
86




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




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




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




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




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



70
    SECTION("simple 4")
95
    {
96




6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
97
            Append_true));
98




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




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




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




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




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




6
        REQUIRE(VirtFs::unmountDir("dir1"));
105




4
        REQUIRE(VirtFs::getEntries().empty());
106




6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
107
            Append_true));
108




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




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




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




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




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
113
            VirtFs::getEntries()[0])->userDir == "dir1");
114
    }
115
116



70
    SECTION("simple 5")
117
    {
118




4
        REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip",
119
            Append_true));
120




4
        REQUIRE(VirtFs::mountZip(prefix + "data/test/test2.zip",
121
            Append_true));
122






11
        REQUIRE(VirtFs::searchByRootInternal(
123
            prefix + "data" + sep + "test" + sep + "test.zip",
124
            std::string()) != nullptr);
125






11
        REQUIRE(VirtFs::searchByRootInternal(
126
            prefix + "data" + sep + "test" + sep + "test2.zip",
127
            std::string()) != nullptr);
128




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






9
        REQUIRE(VirtFs::getEntries()[0]->root ==
130
            prefix + "data" + sep + "test" + sep + "test.zip");
131




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




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






9
        REQUIRE(VirtFs::getEntries()[1]->root ==
134
            prefix + "data" + sep + "test" + sep + "test2.zip");
135




4
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
136




4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip);
137
138

2
        VirtFs::unmountZip(prefix + "data/test/test.zip");
139






11
        REQUIRE(VirtFs::searchByRootInternal(
140
            prefix + "data" + sep + "test" + sep + "test.zip",
141
            std::string()) == nullptr);
142






11
        REQUIRE(VirtFs::searchByRootInternal(
143
            prefix + "data" + sep + "test" + sep + "test2.zip",
144
            std::string()) != nullptr);
145




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






9
        REQUIRE(VirtFs::getEntries()[0]->root ==
147
            prefix + "data" + sep + "test" + sep + "test2.zip");
148




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




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
150
    }
151
152



70
    SECTION("simple 6")
153
    {
154




4
        REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip",
155
            Append_false));
156




4
        REQUIRE(VirtFs::mountDir(prefix + "data/test",
157
            Append_false));
158




4
        REQUIRE(VirtFs::mountZip(prefix + "data\\test/test2.zip",
159
            Append_false));
160
161






11
        REQUIRE(VirtFs::searchByRootInternal(
162
            prefix + "data" + sep + "test" + sep + "test.zip",
163
            std::string()) != nullptr);
164






11
        REQUIRE(VirtFs::searchByRootInternal(
165
            prefix + "data" + sep + "test" + sep + "test2.zip",
166
            std::string()) != nullptr);
167






11
        REQUIRE(VirtFs::searchByRootInternal(
168
            prefix + "data" + sep + "test" + sep + "",
169
            std::string()) != nullptr);
170




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






9
        REQUIRE(VirtFs::getEntries()[0]->root ==
172
            prefix + "data" + sep + "test" + sep + "test2.zip");
173




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




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






8
        REQUIRE(VirtFs::getEntries()[1]->root ==
176
            prefix + "data" + sep + "test" + sep);
177




4
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
178




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






9
        REQUIRE(VirtFs::getEntries()[2]->root ==
180
            prefix + "data" + sep + "test" + sep + "test.zip");
181




4
        REQUIRE(VirtFs::getEntries()[2]->subDir.empty());
182




4
        REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip);
183
184

2
        VirtFs::unmountZip(prefix + "data/test/test.zip");
185






11
        REQUIRE(VirtFs::searchByRootInternal(
186
            prefix + "data" + sep + "test" + sep + "test.zip",
187
            std::string()) == nullptr);
188






11
        REQUIRE(VirtFs::searchByRootInternal(
189
            prefix + "data" + sep + "test" + sep + "test2.zip",
190
            std::string()) != nullptr);
191






11
        REQUIRE(VirtFs::searchByRootInternal(
192
            prefix + "data" + sep + "test" + sep + "",
193
            std::string()) != nullptr);
194




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






9
        REQUIRE(VirtFs::getEntries()[0]->root ==
196
            prefix + "data" + sep + "test" + sep + "test2.zip");
197




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




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






8
        REQUIRE(VirtFs::getEntries()[1]->root ==
200
            prefix + "data" + sep + "test" + sep);
201




4
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
202




4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
203
    }
204
205



70
    SECTION("subDir 2")
206
    {
207





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
208
            "dir2",
209
            Append_true));
210





9
        REQUIRE(VirtFs::unmountDir2("dir1", "dir2"));
211
    }
212
213



70
    SECTION("subDir 3")
214
    {
215





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
216
            "dir2",
217
            Append_true));
218




6
        REQUIRE(VirtFs::mountDirSilentTest("dir2//dir3",
219
            Append_true));
220





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir3",
221
            "dir4",
222
            Append_false));
223




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





9
        REQUIRE(VirtFs::unmountDir2("dir1", "dir2"));
225




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




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




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




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




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
230
            VirtFs::getEntries()[0])->userDir == "dir3");
231





7
        REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep + "dir3" + sep);
232




4
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
233




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





6
        REQUIRE(static_cast<VirtFs::DirEntry*>(
235
            VirtFs::getEntries()[1])->userDir == "dir2" + sep + "dir3");
236




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




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




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




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




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
241
            VirtFs::getEntries()[0])->userDir == "dir3");
242





7
        REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep + "dir3" + sep);
243




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




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





6
        REQUIRE(static_cast<VirtFs::DirEntry*>(
246
            VirtFs::getEntries()[1])->userDir == "dir2" + sep + "dir3");
247




6
        REQUIRE(VirtFs::unmountDir("dir2/dir3"));
248




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




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




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




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




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
253
            VirtFs::getEntries()[0])->userDir == "dir3");
254
    }
255
256



70
    SECTION("subDir 4")
257
    {
258





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
259
            "dir2",
260
            Append_true));
261




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




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




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




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




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





9
        REQUIRE(VirtFs::unmountDir2("dir1", "dir2"));
268




4
        REQUIRE(VirtFs::getEntries().empty());
269





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
270
            "dir3",
271
            Append_true));
272




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




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




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




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




4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
277
            VirtFs::getEntries()[0])->userDir == "dir1");
278
    }
279
280



70
    SECTION("subDir 5")
281
    {
282





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip",
283
            "dir1",
284
            Append_true));
285





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip",
286
            "dir2",
287
            Append_true));
288
289







10
        REQUIRE(VirtFs::searchByRootInternal(
290
            prefix + "data" + sep + "test" + sep + "test.zip",
291
            "dir1" + sep) != nullptr);
292







10
        REQUIRE(VirtFs::searchByRootInternal(
293
            prefix + "data" + sep + "test" + sep + "test2.zip",
294
            "dir2" + sep) != nullptr);
295




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






9
        REQUIRE(VirtFs::getEntries()[0]->root ==
297
            prefix + "data" + sep + "test" + sep + "test.zip");
298




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




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






9
        REQUIRE(VirtFs::getEntries()[1]->root ==
301
            prefix + "data" + sep + "test" + sep + "test2.zip");
302




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




4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip);
304
305

5
        VirtFs::unmountZip2(prefix + "data/test/test.zip",
306
1
            "dir1");
307






11
        REQUIRE(VirtFs::searchByRootInternal(
308
            prefix + "data" + sep + "test" + sep + "test.zip",
309
            std::string()) == nullptr);
310







10
        REQUIRE(VirtFs::searchByRootInternal(
311
            prefix + "data" + sep + "test" + sep + "test2.zip",
312
            "dir2" + sep) != nullptr);
313




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






9
        REQUIRE(VirtFs::getEntries()[0]->root ==
315
            prefix + "data" + sep + "test" + sep + "test2.zip");
316




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




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
318
    }
319
320



70
    SECTION("subDir 6")
321
    {
322





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip",
323
            "dir1",
324
            Append_false));
325





7
        REQUIRE(VirtFs::mountDir2(prefix + "data/test",
326
            "dir2",
327
            Append_false));
328





7
        REQUIRE(VirtFs::mountZip2(prefix + "data\\test/test2.zip",
329
            "dir3",
330
            Append_false));
331
332







10
        REQUIRE(VirtFs::searchByRootInternal(
333
            prefix + "data" + sep + "test" + sep + "test.zip",
334
            "dir1" + sep) != nullptr);
335







10
        REQUIRE(VirtFs::searchByRootInternal(
336
            prefix + "data" + sep + "test" + sep + "test2.zip",
337
            "dir3" + sep) != nullptr);
338







10
        REQUIRE(VirtFs::searchByRootInternal(
339
            prefix + "data" + sep + "test" + sep + "",
340
            "dir2" + sep) != nullptr);
341




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






9
        REQUIRE(VirtFs::getEntries()[0]->root ==
343
            prefix + "data" + sep + "test" + sep + "test2.zip");
344




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




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






8
        REQUIRE(VirtFs::getEntries()[1]->root ==
347
            prefix + "data" + sep + "test" + sep);
348




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




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






9
        REQUIRE(VirtFs::getEntries()[2]->root ==
351
            prefix + "data" + sep + "test" + sep + "test.zip");
352




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




4
        REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip);
354
355

5
        VirtFs::unmountZip2(prefix + "data/test/test.zip",
356
1
            "dir1");
357







10
        REQUIRE(VirtFs::searchByRootInternal(
358
            prefix + "data" + sep + "test" + sep + "test.zip",
359
            "dir1" + sep) == nullptr);
360







10
        REQUIRE(VirtFs::searchByRootInternal(
361
            prefix + "data" + sep + "test" + sep + "test2.zip",
362
            "dir3" + sep) != nullptr);
363







10
        REQUIRE(VirtFs::searchByRootInternal(
364
            prefix + "data" + sep + "test" + sep + "",
365
            "dir2" + sep) != nullptr);
366




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






9
        REQUIRE(VirtFs::getEntries()[0]->root ==
368
            prefix + "data" + sep + "test" + sep + "test2.zip");
369




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




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






8
        REQUIRE(VirtFs::getEntries()[1]->root ==
372
            prefix + "data" + sep + "test" + sep);
373




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




4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
375
    }
376
377
10
    VirtFs::deinit();
378

13
}