GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/throw.cc Lines: 97 97 100.0 %
Date: 2017-11-29 Branches: 545 1242 43.9 %

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 "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
6
TEST_CASE("throw VirtFs1 exists1", "")
39
{
40

8
    VirtFs::init(".");
41
8
    const bool dir1 = VirtFs::mountDirSilent("data/",
42
2
        Append_false);
43

8
    VirtFs::mountDirSilent("..\\data",
44
        Append_false);
45
46
2
    if (dir1 == true)
47
    {
48

4
        VirtFs::mountDir("data//test",
49
            Append_false);
50
    }
51
    else
52
    {
53

4
        VirtFs::mountDirSilent("..//data\\test",
54
            Append_false);
55
    }
56
57
2
    if (dir1 == true)
58

4
        VirtFs::unmountDirSilent("data/test");
59
    else
60

4
        VirtFs::unmountDirSilent("../data/test");
61
62






16
    REQUIRE_THROWS(VirtFs::exists("test/../units.xml"));
63
64
2
    VirtFs::deinit();
65
2
}
66
67
6
TEST_CASE("throw VirtFs1 exists2", "")
68
{
69

8
    VirtFs::init(".");
70

14
    const bool dir1 = VirtFs::mountDirSilent2("data/",
71
        "test",
72
2
        Append_false);
73

14
    VirtFs::mountDirSilent2("..\\data",
74
        "test",
75
        Append_false);
76
77
2
    if (dir1 == true)
78
    {
79

7
        VirtFs::mountDir2("data//test",
80
            "dir2",
81
            Append_false);
82
    }
83
    else
84
    {
85

7
        VirtFs::mountDirSilent2("..//data\\test",
86
            "dir2",
87
            Append_false);
88
    }
89
90
2
    if (dir1 == true)
91

7
        VirtFs::unmountDirSilent2("data/test", "dir2");
92
    else
93

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






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



14
    SECTION("empty")
103
    {
104






12
        REQUIRE_THROWS(VirtFs::ZipReader::readCompressedFile(nullptr));
105
    }
106
2
}
107
108
6
TEST_CASE("throw Zip readFile", "")
109
{
110



14
    SECTION("empty")
111
    {
112






12
        REQUIRE_THROWS(VirtFs::ZipReader::readFile(nullptr));
113
    }
114
2
}
115
116
20
TEST_CASE("throw VirtFs1 unmount", "")
117
{
118

64
    VirtFs::init(".");
119
64
    const std::string sep = dirSeparator;
120
121



112
    SECTION("simple 1")
122
    {
123






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






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



112
    SECTION("simple 2")
128
    {
129




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




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




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



112
    SECTION("simple 3")
136
    {
137




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



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




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






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




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






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




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






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



112
    SECTION("simple 4")
151
    {
152




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






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




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




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



112
    SECTION("subDir 1")
161
    {
162







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







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



112
    SECTION("subDir 2")
167
    {
168





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






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






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





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



112
    SECTION("subDir 3")
177
    {
178





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




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





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






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







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





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






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




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






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



112
    SECTION("subDir 4")
195
    {
196





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






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






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





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





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



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






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






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






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






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

8
}