GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_mountzip2.cc Lines: 82 82 100.0 %
Date: 2017-11-29 Branches: 636 1530 41.6 %

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
16
TEST_CASE("VirtFs1 mountZip2", "")
37
{
38

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

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



84
    SECTION("subDir 1")
46
    {
47





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







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






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




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






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




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




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



84
    SECTION("subDir 2")
64
    {
65





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





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







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







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




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






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




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




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






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




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




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



84
    SECTION("subDir 3")
89
    {
90





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





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







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







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




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






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




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




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






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




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




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



84
    SECTION("subDir 4")
114
    {
115





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





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





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







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







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







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




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






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




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




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






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




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




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






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




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




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



84
    SECTION("subDir 5")
149
    {
150





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





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





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







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







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







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




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






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




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




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






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




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




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






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




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




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



84
    SECTION("subDir 6")
184
    {
185





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






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






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




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






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




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




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

18
}