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

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

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



35
    SECTION("simple 1")
46
    {
47




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






11
        REQUIRE(VirtFs::searchByRootInternal(
50
            prefix + "data" + sep + "test" + sep + "test.zip", std::string()) !=
51
            nullptr);
52






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




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






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




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




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



35
    SECTION("simple 2")
63
    {
64




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




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






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






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




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






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




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




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






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




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




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



35
    SECTION("simple 3")
86
    {
87




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




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






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






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




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






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




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




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






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




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




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



35
    SECTION("simple 4")
109
    {
110




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




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




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






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






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






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




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






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




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




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






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




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




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






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




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




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



35
    SECTION("simple 5")
141
    {
142




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




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




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






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






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






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




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






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




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




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






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




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




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






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




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




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

8
}