GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_mountzip1.cc Lines: 74 74 100.0 %
Date: 2017-11-29 Branches: 537 1306 41.1 %

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

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

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



70
    SECTION("simple 1")
46
    {
47




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






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






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




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






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




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




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



70
    SECTION("simple 2")
63
    {
64




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




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






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






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




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






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




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




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






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




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




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



70
    SECTION("simple 3")
86
    {
87




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




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






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






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




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






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




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




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






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




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




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



70
    SECTION("simple 4")
109
    {
110




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




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




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






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






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






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




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






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




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




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






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




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




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






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




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




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



70
    SECTION("simple 5")
141
    {
142




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




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




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






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






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






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




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






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




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




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






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




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




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






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




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




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

16
}