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

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

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



70
    SECTION("simple 2")
46
    {
47




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




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



70
    SECTION("simple 3")
53
    {
54




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




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




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




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




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




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




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




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




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




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





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




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




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





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




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




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




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




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




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





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




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




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





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




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




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




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




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




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




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



70
    SECTION("simple 4")
94
    {
95




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




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




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




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




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




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




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




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




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




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




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




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




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




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



70
    SECTION("simple 5")
116
    {
117




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




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






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






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




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






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




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




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






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




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




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

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






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






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




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






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




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




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



70
    SECTION("simple 6")
152
    {
153




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




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




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






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






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






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




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






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




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




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






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




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




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






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




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




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

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






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






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






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




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






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




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




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






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




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




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



70
    SECTION("subDir 2")
205
    {
206





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





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



70
    SECTION("subDir 3")
213
    {
214





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




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





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




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





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




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




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




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




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




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





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




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




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





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




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




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




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




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




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





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




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




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





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




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




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




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




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




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




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



70
    SECTION("subDir 4")
256
    {
257





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




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




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




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




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




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





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




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





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




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




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




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




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




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



70
    SECTION("subDir 5")
280
    {
281





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





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







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







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




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






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




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




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






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




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




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

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






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







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




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






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




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




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



70
    SECTION("subDir 6")
320
    {
321





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





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





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







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







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







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




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






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




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




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






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




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




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






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




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




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

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







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







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







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




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






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




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




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






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




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




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

13
}