GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_unmount.cc Lines: 198 198 100.0 %
Date: 2017-11-29 Branches: 1417 3516 40.3 %

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/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
24
TEST_CASE("VirtFs1 unmount", "")
37
{
38

80
    VirtFs::init(".");
39
80
    std::string name("data/test/test.zip");
40
40
    std::string prefix;
41
80
    const std::string sep = dirSeparator;
42

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



140
    SECTION("simple 2")
46
    {
47




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




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



140
    SECTION("simple 3")
53
    {
54




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




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




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




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




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




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




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




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




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




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





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




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




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





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




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




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




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




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




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





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




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




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





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




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




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




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




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




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




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



140
    SECTION("simple 4")
94
    {
95




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




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




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




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




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




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




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




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




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




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




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




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




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




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



140
    SECTION("simple 5")
116
    {
117




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




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






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






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




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






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




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




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






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




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




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

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






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






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




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






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




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




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



140
    SECTION("simple 6")
152
    {
153




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




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




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






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






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






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




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






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




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




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






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




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




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






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




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




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

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






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






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






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




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






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




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




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






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




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




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



140
    SECTION("subDir 2")
205
    {
206





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





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



140
    SECTION("subDir 3")
213
    {
214





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




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





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




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





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




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




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




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




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




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





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




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




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





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




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




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




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




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




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





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




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




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





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




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




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




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




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




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




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



140
    SECTION("subDir 4")
256
    {
257





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




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




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




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




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




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





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




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





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




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




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




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




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




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



140
    SECTION("subDir 5")
280
    {
281





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





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







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







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




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






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




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




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






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




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




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

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






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







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




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






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




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




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



140
    SECTION("subDir 6")
320
    {
321





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





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





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







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







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







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




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






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




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




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






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




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




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






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




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




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

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







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







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







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




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






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




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




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






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




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




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

26
}