GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
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 "fs/files.h" |
||
25 |
|||
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 |
✓✗ | 3 |
TEST_CASE("VirtFs1 getRealDir1", "") |
37 |
{ |
||
38 |
✓✗ | 4 |
VirtFs::init("."); |
39 |
4 |
const std::string sep = dirSeparator; |
|
40 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir(".").empty()); |
41 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("..").empty()); |
42 |
✓✗ | 4 |
const bool dir1 = VirtFs::mountDirSilent("data", |
43 |
✓✗ | 1 |
Append_false); |
44 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ ✗✗ |
6 |
REQUIRE((dir1 || VirtFs::mountDirSilent("../data", |
45 |
Append_false)) == true); |
||
46 |
✗✓ | 1 |
if (dir1 == true) |
47 |
{ |
||
48 |
REQUIRE(VirtFs::getRealDir("test") == "data"); |
||
49 |
REQUIRE(VirtFs::getRealDir("test/test.txt") == |
||
50 |
"data"); |
||
51 |
REQUIRE(VirtFs::getRealDir("test\\test.txt") == |
||
52 |
"data"); |
||
53 |
REQUIRE(VirtFs::getRealDir("test//test.txt") == |
||
54 |
"data"); |
||
55 |
} |
||
56 |
else |
||
57 |
{ |
||
58 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("test") == "../data"); |
59 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("test/test.txt") == |
60 |
"../data"); |
||
61 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("test\\test.txt") == |
62 |
"../data"); |
||
63 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("test//test.txt") == |
64 |
"../data"); |
||
65 |
} |
||
66 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("zzz").empty()); |
67 |
|||
68 |
✓✗ | 4 |
VirtFs::mountDirSilent("data/test", |
69 |
✓✗ | 1 |
Append_false); |
70 |
✓✗ | 4 |
VirtFs::mountDirSilent("../data/test", |
71 |
✓✗ | 1 |
Append_false); |
72 |
✗✓ | 1 |
if (dir1 == true) |
73 |
{ |
||
74 |
REQUIRE(VirtFs::getRealDir("test") == "data"); |
||
75 |
REQUIRE(VirtFs::getRealDir("test/test.txt") == |
||
76 |
"data"); |
||
77 |
REQUIRE(VirtFs::getRealDir("test\\test.txt") == |
||
78 |
"data"); |
||
79 |
REQUIRE(VirtFs::getRealDir("test.txt") == |
||
80 |
"data" + sep + "test"); |
||
81 |
} |
||
82 |
else |
||
83 |
{ |
||
84 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
10 |
REQUIRE(VirtFs::getRealDir("test") == ".." + sep + "data"); |
85 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
10 |
REQUIRE(VirtFs::getRealDir("test/test.txt") == |
86 |
".." + sep + "data"); |
||
87 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
10 |
REQUIRE(VirtFs::getRealDir("test\\test.txt") == |
88 |
".." + sep + "data"); |
||
89 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
12 |
REQUIRE(VirtFs::getRealDir("test.txt") == |
90 |
".." + sep + "data" + sep + "test"); |
||
91 |
} |
||
92 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("zzz").empty()); |
93 |
|||
94 |
✓✗✓✗ |
4 |
VirtFs::unmountDirSilent("data/test"); |
95 |
✓✗✓✗ |
4 |
VirtFs::unmountDirSilent("../data/test"); |
96 |
|||
97 |
✗✓ | 1 |
if (dir1 == true) |
98 |
{ |
||
99 |
REQUIRE(VirtFs::getRealDir("test") == "data"); |
||
100 |
REQUIRE(VirtFs::getRealDir("test/test.txt") == |
||
101 |
"data"); |
||
102 |
} |
||
103 |
else |
||
104 |
{ |
||
105 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
10 |
REQUIRE(VirtFs::getRealDir("test") == ".." + sep + "data"); |
106 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
10 |
REQUIRE(VirtFs::getRealDir("test/test.txt") == |
107 |
".." + sep + "data"); |
||
108 |
} |
||
109 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("zzz").empty()); |
110 |
|||
111 |
✓✗✓✗ |
4 |
VirtFs::unmountDirSilent("data"); |
112 |
✓✗✓✗ |
4 |
VirtFs::unmountDirSilent("../data"); |
113 |
✓✗ | 1 |
VirtFs::deinit(); |
114 |
1 |
} |
|
115 |
|||
116 |
✓✗ | 3 |
TEST_CASE("VirtFs1 getRealDir2", "") |
117 |
{ |
||
118 |
✓✗ | 4 |
VirtFs::init("."); |
119 |
4 |
const std::string sep = dirSeparator; |
|
120 |
✓✗ | 4 |
std::string name("data/test/test.zip"); |
121 |
✓✗✓✗ ✓✗ |
4 |
std::string prefix("data" + sep + "test" + sep); |
122 |
✓✗✓✗ |
1 |
if (Files::existsLocal(name) == false) |
123 |
✓✗✓✗ |
3 |
prefix = ".." + sep + prefix; |
124 |
✓✗ | 2 |
VirtFs::mountZip(prefix + "test2.zip", |
125 |
✓✗ | 1 |
Append_false); |
126 |
|||
127 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir(".").empty()); |
128 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("..").empty()); |
129 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
9 |
REQUIRE(VirtFs::getRealDir("test.txt") == prefix + "test2.zip"); |
130 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
9 |
REQUIRE(VirtFs::getRealDir("dir/1") == prefix + "test2.zip"); |
131 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("dir\\dye.png") == |
132 |
prefix + "test2.zip"); |
||
133 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("zzz").empty()); |
134 |
|||
135 |
✓✗ | 2 |
VirtFs::mountZip(prefix + "test.zip", |
136 |
✓✗ | 1 |
Append_false); |
137 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
9 |
REQUIRE(VirtFs::getRealDir("dir//dye.png") == |
138 |
prefix + "test2.zip"); |
||
139 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("dir///hide.png") == |
140 |
prefix + "test.zip"); |
||
141 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
9 |
REQUIRE(VirtFs::getRealDir("dir\\\\brimmedhat.png") == |
142 |
prefix + "test.zip"); |
||
143 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("zzz").empty()); |
144 |
|||
145 |
✓✗✓✗ |
2 |
VirtFs::unmountZip(prefix + "test.zip"); |
146 |
|||
147 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("dir/brimmedhat.png").empty()); |
148 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
9 |
REQUIRE(VirtFs::getRealDir("test.txt") == prefix + "test2.zip"); |
149 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
9 |
REQUIRE(VirtFs::getRealDir("dir//dye.png") == |
150 |
prefix + "test2.zip"); |
||
151 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("zzz").empty()); |
152 |
|||
153 |
✓✗✓✗ |
2 |
VirtFs::unmountZip(prefix + "test2.zip"); |
154 |
✓✗ | 1 |
VirtFs::deinit(); |
155 |
1 |
} |
|
156 |
|||
157 |
✓✗ | 3 |
TEST_CASE("VirtFs1 getRealDir3", "") |
158 |
{ |
||
159 |
✓✗ | 4 |
VirtFs::init("."); |
160 |
4 |
const std::string sep = dirSeparator; |
|
161 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir(".").empty()); |
162 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("..").empty()); |
163 |
✓✗✓✗ |
7 |
const bool dir1 = VirtFs::mountDirSilent2("data", |
164 |
"test", |
||
165 |
✓✗ | 1 |
Append_false); |
166 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ ✗✗✗✗ |
8 |
REQUIRE((dir1 || VirtFs::mountDirSilent2("../data", |
167 |
"test", |
||
168 |
Append_false)) == true); |
||
169 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("file1.txt").empty()); |
170 |
✗✓ | 1 |
if (dir1 == true) |
171 |
{ |
||
172 |
REQUIRE(VirtFs::getRealDir("dir1") == "data"); |
||
173 |
REQUIRE(VirtFs::getRealDir("simplefile.txt") == "data"); |
||
174 |
} |
||
175 |
else |
||
176 |
{ |
||
177 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
10 |
REQUIRE(VirtFs::getRealDir("dir1") == ".." + sep + "data"); |
178 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
10 |
REQUIRE(VirtFs::getRealDir("simplefile.txt") == ".." + sep + "data"); |
179 |
} |
||
180 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("zzz").empty()); |
181 |
|||
182 |
✓✗✓✗ |
7 |
VirtFs::mountDirSilent2("data/test", |
183 |
"dir2", |
||
184 |
✓✗ | 1 |
Append_false); |
185 |
✓✗✓✗ |
7 |
VirtFs::mountDirSilent2("../data/test", |
186 |
"dir2", |
||
187 |
✓✗ | 1 |
Append_false); |
188 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("dir").empty()); |
189 |
✗✓ | 1 |
if (dir1 == true) |
190 |
{ |
||
191 |
REQUIRE(VirtFs::getRealDir("file1.txt") == "data" + sep + "test"); |
||
192 |
REQUIRE(VirtFs::getRealDir("simplefile.txt") == "data"); |
||
193 |
} |
||
194 |
else |
||
195 |
{ |
||
196 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
12 |
REQUIRE(VirtFs::getRealDir("file1.txt") == |
197 |
".." + sep + "data" + sep + "test"); |
||
198 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
10 |
REQUIRE(VirtFs::getRealDir("simplefile.txt") == ".." + sep + "data"); |
199 |
} |
||
200 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
8 |
REQUIRE(VirtFs::getRealDir("zzz").empty()); |
201 |
|||
202 |
✓✗ | 1 |
VirtFs::deinit(); |
203 |
✓✗✓✗ |
4 |
} |
Generated by: GCOVR (Version 3.3) |