GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_mountzip2.cc Lines: 82 82 100.0 %
Date: 2018-09-20 Branches: 634 1528 41.5 %

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
8
TEST_CASE("VirtFs1 mountZip2", "")
37
{
38
24
    VirtFs::init(".");
39
24
    std::string name("data/test/test.zip");
40
12
    std::string prefix;
41
24
    const std::string sep = dirSeparator;
42

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



42
    SECTION("subDir 1")
46
    {
47





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip",
48
            "dir1",
49
            Append_false));
50







10
        REQUIRE(VirtFs::searchByRootInternal(
51
            prefix + "data" + sep + "test" + sep + "test.zip", "dir1" + sep) !=
52
            nullptr);
53






11
        REQUIRE(VirtFs::searchByRootInternal(
54
            prefix + "data" + sep + "test" + sep + "test2.zip",
55
            std::string()) == nullptr);
56




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






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




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




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
61
    }
62
63



42
    SECTION("subDir 2")
64
    {
65





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip",
66
            "dir1",
67
            Append_false));
68





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip",
69
            "dir2",
70
            Append_false));
71







10
        REQUIRE(VirtFs::searchByRootInternal(
72
            prefix + "data" + sep + "test" + sep + "test.zip", "dir1" + sep) !=
73
            nullptr);
74







10
        REQUIRE(VirtFs::searchByRootInternal(
75
            prefix + "data" + sep + "test" + sep + "test2.zip",
76
            "dir2" + sep) != nullptr);
77




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






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




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




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






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




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




5
        REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1" + sep);
86
    }
87
88



42
    SECTION("subDir 3")
89
    {
90





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip",
91
            "dir1",
92
            Append_true));
93





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip",
94
            "dir2",
95
            Append_true));
96







10
        REQUIRE(VirtFs::searchByRootInternal(
97
            prefix + "data" + sep + "test" + sep + "test.zip",
98
            "dir1" + sep) != nullptr);
99







10
        REQUIRE(VirtFs::searchByRootInternal(
100
            prefix + "data" + sep + "test" + sep + "test2.zip",
101
            "dir2" + sep) != nullptr);
102




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






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




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




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






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




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




5
        REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep);
111
    }
112
113



42
    SECTION("subDir 4")
114
    {
115





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip",
116
            "dir1",
117
            Append_false));
118





7
        REQUIRE(VirtFs::mountDir2(prefix + "data/test",
119
            "dir2",
120
            Append_false));
121





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip",
122
            "dir3",
123
            Append_false));
124







10
        REQUIRE(VirtFs::searchByRootInternal(
125
            prefix + "data" + sep + "test" + sep + "test.zip",
126
            "dir1" + sep) != nullptr);
127







10
        REQUIRE(VirtFs::searchByRootInternal(
128
            prefix + "data" + sep + "test" + sep + "test2.zip",
129
            "dir3" + sep) != nullptr);
130







10
        REQUIRE(VirtFs::searchByRootInternal(
131
            prefix + "data" + sep + "test" + sep + "",
132
            "dir2" + sep) != nullptr);
133




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






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




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




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






9
        REQUIRE(VirtFs::getEntries()[1]->root ==
139
            prefix + "data" + sep + "test" + sep + "");
140




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




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






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




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




5
        REQUIRE(VirtFs::getEntries()[2]->subDir == "dir1" + sep);
146
    }
147
148



42
    SECTION("subDir 5")
149
    {
150





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip",
151
            "dir1",
152
            Append_false));
153





7
        REQUIRE(VirtFs::mountDir2(prefix + "data/test",
154
            "dir2",
155
            Append_false));
156





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip",
157
            "dir3",
158
            Append_true));
159







10
        REQUIRE(VirtFs::searchByRootInternal(
160
            prefix + "data" + sep + "test" + sep + "test.zip",
161
            "dir1" + sep) != nullptr);
162







10
        REQUIRE(VirtFs::searchByRootInternal(
163
            prefix + "data" + sep + "test" + sep + "test2.zip",
164
            "dir3" + sep) != nullptr);
165







10
        REQUIRE(VirtFs::searchByRootInternal(
166
            prefix + "data" + sep + "test" + sep + "",
167
            "dir2" + sep) != nullptr);
168




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






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




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




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






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




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




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






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




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




5
        REQUIRE(VirtFs::getEntries()[2]->subDir == "dir3" + sep);
181
    }
182
183



42
    SECTION("subDir 6")
184
    {
185





7
        REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip",
186
            dirSeparator,
187
            Append_false));
188






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






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




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






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




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




4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
199
    }
200
201
6
    VirtFs::deinit();
202

9
}