GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/throw.cc Lines: 97 103 94.2 %
Date: 2021-03-17 Branches: 524 1224 42.8 %

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 "configmanager.h"
25
#include "configuration.h"
26
#include "dirs.h"
27
28
#include "fs/virtfs/fs.h"
29
#include "fs/virtfs/zipreader.h"
30
31
#include "utils/checkutils.h"
32
33
#ifndef UNITTESTS_CATCH
34
#include <algorithm>
35
#endif  // UNITTESTS_CATCH
36
37
#include "debug.h"
38
39
3
TEST_CASE("throw VirtFs1 exists1", "")
40
{
41
3
    VirtFs::init(".");
42
3
    const bool dir1 = VirtFs::mountDirSilent("data/",
43
1
        Append_false);
44
3
    VirtFs::mountDirSilent("..\\data",
45
1
        Append_false);
46
47
1
    if (dir1 == true)
48
    {
49
        VirtFs::mountDir("data//test",
50
            Append_false);
51
    }
52
    else
53
    {
54
3
        VirtFs::mountDirSilent("..//data\\test",
55
1
            Append_false);
56
    }
57
58
1
    if (dir1 == true)
59
        VirtFs::unmountDirSilent("data/test");
60
    else
61
3
        VirtFs::unmountDirSilent("../data/test");
62
63






7
    REQUIRE_THROWS(VirtFs::exists("test/../units.xml"));
64
65
1
    VirtFs::deinit();
66
1
}
67
68
3
TEST_CASE("throw VirtFs1 exists2", "")
69
{
70
3
    VirtFs::init(".");
71
6
    const bool dir1 = VirtFs::mountDirSilent2("data/",
72
        "test",
73
1
        Append_false);
74
6
    VirtFs::mountDirSilent2("..\\data",
75
        "test",
76
1
        Append_false);
77
78
1
    if (dir1 == true)
79
    {
80
        VirtFs::mountDir2("data//test",
81
            "dir2",
82
            Append_false);
83
    }
84
    else
85
    {
86
6
        VirtFs::mountDirSilent2("..//data\\test",
87
            "dir2",
88
1
            Append_false);
89
    }
90
91
1
    if (dir1 == true)
92
        VirtFs::unmountDirSilent2("data/test", "dir2");
93
    else
94

6
        VirtFs::unmountDirSilent2("../data/test", "dir2");
95
96






7
    REQUIRE_THROWS(VirtFs::exists("test/../units.xml"));
97
98
1
    VirtFs::deinit();
99
1
}
100
101
3
TEST_CASE("throw Zip readCompressedFile", "")
102
{
103



7
    SECTION("empty")
104
    {
105






5
        REQUIRE_THROWS(VirtFs::ZipReader::readCompressedFile(nullptr));
106
    }
107
1
}
108
109
3
TEST_CASE("throw Zip readFile", "")
110
{
111



7
    SECTION("empty")
112
    {
113






5
        REQUIRE_THROWS(VirtFs::ZipReader::readFile(nullptr));
114
    }
115
1
}
116
117
10
TEST_CASE("throw VirtFs1 unmount", "")
118
{
119
24
    VirtFs::init(".");
120
32
    const std::string sep = dirSeparator;
121
122



56
    SECTION("simple 1")
123
    {
124






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir1"));
125






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir1/"));
126
    }
127
128



56
    SECTION("simple 2")
129
    {
130




6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
131
            Append_true));
132






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir2"));
133




6
        REQUIRE(VirtFs::unmountDir("dir1"));
134
    }
135
136



56
    SECTION("simple 3")
137
    {
138




6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
139
            Append_true));
140




6
        REQUIRE(VirtFs::mountDirSilentTest("dir2//dir3",
141
            Append_true));
142




6
        REQUIRE(VirtFs::mountDirSilentTest("dir3",
143
            Append_false));
144






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir2"));
145




6
        REQUIRE(VirtFs::unmountDir("dir1"));
146






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir1"));
147




6
        REQUIRE(VirtFs::unmountDir("dir2/dir3"));
148






6
        REQUIRE_THROWS(VirtFs::unmountDir("dir2/dir3" + sep));
149
    }
150
151



56
    SECTION("simple 4")
152
    {
153




6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
154
            Append_true));
155






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir2"));
156




6
        REQUIRE(VirtFs::unmountDir("dir1"));
157




6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
158
            Append_true));
159
    }
160
161



56
    SECTION("subDir 1")
162
    {
163







9
        REQUIRE_THROWS(VirtFs::unmountDir2("dir1", "dir1"));
164







9
        REQUIRE_THROWS(VirtFs::unmountDir2("dir1/", "dir1/"));
165
    }
166
167



56
    SECTION("subDir 2")
168
    {
169





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
170
            "dir2",
171
            Append_true));
172






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir1"));
173






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir2"));
174





9
        REQUIRE(VirtFs::unmountDir2("dir1", "dir2"));
175
    }
176
177



56
    SECTION("subDir 3")
178
    {
179





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
180
            "dir2",
181
            Append_true));
182




6
        REQUIRE(VirtFs::mountDirSilentTest("dir2//dir3",
183
            Append_true));
184





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir3",
185
            "dir4",
186
            Append_false));
187






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir2"));
188







9
        REQUIRE_THROWS(VirtFs::unmountDir2("dir1", "dir1"));
189





9
        REQUIRE(VirtFs::unmountDir2("dir1", "dir2"));
190






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir1"));
191




6
        REQUIRE(VirtFs::unmountDir("dir2/dir3"));
192






6
        REQUIRE_THROWS(VirtFs::unmountDir("dir2/dir3" + sep));
193
    }
194
195



56
    SECTION("subDir 4")
196
    {
197





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
198
            "dir2",
199
            Append_true));
200






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir2"));
201






7
        REQUIRE_THROWS(VirtFs::unmountDir("dir1"));
202





9
        REQUIRE(VirtFs::unmountDir2("dir1", "dir2"));
203





9
        REQUIRE(VirtFs::mountDirSilentTest2("dir1",
204
            "dir3",
205
            Append_true));
206
    }
207
208
8
    VirtFs::deinit();
209
8
}
210
211
3
TEST_CASE("throw configuration tests", "configuration")
212
{
213
1
    Dirs::initRootDir();
214
1
    Dirs::initHomeDir();
215
216
1
    ConfigManager::initConfiguration();
217
218



7
    SECTION("configuration undefined")
219
    {
220
1
        const char *const key = "nonsetvalue";
221






7
        REQUIRE_THROWS(config.getIntValue(key));
222






7
        REQUIRE_THROWS(config.getFloatValue(key));
223






7
        REQUIRE_THROWS(config.getStringValue(key));
224






7
        REQUIRE_THROWS(config.getBoolValue(key));
225
    }
226

4
}