GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_mountzip1.cc Lines: 74 74 100.0 %
Date: 2021-03-17 Branches: 535 1304 41.0 %

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

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



35
    SECTION("simple 1")
47
    {
48




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






11
        REQUIRE(VirtFs::searchByRootInternal(
51
            prefix + "data" + sep + "test" + sep + "test.zip", std::string()) !=
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




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




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



35
    SECTION("simple 2")
64
    {
65




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




4
        REQUIRE(VirtFs::mountZip(prefix + "data/test/test2.zip",
68
            Append_false));
69






11
        REQUIRE(VirtFs::searchByRootInternal(
70
            prefix + "data" + sep + "test" + sep + "test.zip",
71
            std::string()) != nullptr);
72






11
        REQUIRE(VirtFs::searchByRootInternal(
73
            prefix + "data" + sep + "test" + sep + "test2.zip",
74
            std::string()) != nullptr);
75




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






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




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




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






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




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




4
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
84
    }
85
86



35
    SECTION("simple 3")
87
    {
88




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




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






11
        REQUIRE(VirtFs::searchByRootInternal(
93
            prefix + "data" + sep + "test" + sep + "test.zip",
94
            std::string()) != nullptr);
95






11
        REQUIRE(VirtFs::searchByRootInternal(
96
            prefix + "data" + sep + "test" + sep + "test2.zip",
97
            std::string()) != nullptr);
98




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






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




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




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






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




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




4
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
107
    }
108
109



35
    SECTION("simple 4")
110
    {
111




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




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




4
        REQUIRE(VirtFs::mountZip(prefix + "data/test/test2.zip",
116
            Append_false));
117






11
        REQUIRE(VirtFs::searchByRootInternal(
118
            prefix + "data" + sep + "test" + sep + "test.zip",
119
            std::string()) != nullptr);
120






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






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




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






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




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




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






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




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




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






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




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




4
        REQUIRE(VirtFs::getEntries()[2]->subDir.empty());
139
    }
140
141



35
    SECTION("simple 5")
142
    {
143




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




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




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






11
        REQUIRE(VirtFs::searchByRootInternal(
150
            prefix + "data" + sep + "test" + sep + "test.zip",
151
            std::string()) != nullptr);
152






11
        REQUIRE(VirtFs::searchByRootInternal(
153
            prefix + "data" + sep + "test" + sep + "test2.zip",
154
            std::string()) != nullptr);
155






11
        REQUIRE(VirtFs::searchByRootInternal(
156
            prefix + "data" + sep + "test" + sep + "",
157
            std::string()) != nullptr);
158




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






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




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




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






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




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




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






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




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




4
        REQUIRE(VirtFs::getEntries()[2]->subDir.empty());
171
    }
172
173
5
    VirtFs::deinit();
174

8
}