GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/throw.cc Lines: 97 103 94.2 %
Date: 2018-11-12 Branches: 520 1216 42.8 %

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






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

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






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



7
    SECTION("empty")
103
    {
104






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



7
    SECTION("empty")
111
    {
112






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



56
    SECTION("simple 1")
122
    {
123






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






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



56
    SECTION("simple 2")
128
    {
129




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




5
        REQUIRE_THROWS(VirtFs::unmountDir("dir2"));
132




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



56
    SECTION("simple 3")
136
    {
137




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




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




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






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




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






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




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






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



56
    SECTION("simple 4")
151
    {
152




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






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




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




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



56
    SECTION("subDir 1")
161
    {
162







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







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



56
    SECTION("subDir 2")
167
    {
168





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






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






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





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



56
    SECTION("subDir 3")
177
    {
178





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




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





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






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







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





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






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




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






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



56
    SECTION("subDir 4")
195
    {
196





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






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






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





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





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



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






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






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






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






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

4
}