GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_getrealdir.cc Lines: 95 95 100.0 %
Date: 2017-11-29 Branches: 498 1200 41.5 %

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/fs.h"
26
27
#include "utils/checkutils.h"
28
29
#ifndef UNITTESTS_CATCH
30
#include <algorithm>
31
#endif  // UNITTESTS_CATCH
32
33
#include "debug.h"
34
35
6
TEST_CASE("VirtFs1 getRealDir1", "")
36
{
37

8
    VirtFs::init(".");
38
8
    const std::string sep = dirSeparator;
39




16
    REQUIRE(VirtFs::getRealDir(".").empty());
40




16
    REQUIRE(VirtFs::getRealDir("..").empty());
41
8
    const bool dir1 = VirtFs::mountDirSilent("data",
42
2
        Append_false);
43






11
    REQUIRE((dir1 || VirtFs::mountDirSilent("../data",
44
        Append_false)) == true);
45
2
    if (dir1 == true)
46
    {
47




8
        REQUIRE(VirtFs::getRealDir("test") == "data");
48




8
        REQUIRE(VirtFs::getRealDir("test/test.txt") ==
49
            "data");
50




8
        REQUIRE(VirtFs::getRealDir("test\\test.txt") ==
51
            "data");
52




8
        REQUIRE(VirtFs::getRealDir("test//test.txt") ==
53
            "data");
54
    }
55
    else
56
    {
57




8
        REQUIRE(VirtFs::getRealDir("test") == "../data");
58




8
        REQUIRE(VirtFs::getRealDir("test/test.txt") ==
59
            "../data");
60




8
        REQUIRE(VirtFs::getRealDir("test\\test.txt") ==
61
            "../data");
62




8
        REQUIRE(VirtFs::getRealDir("test//test.txt") ==
63
            "../data");
64
    }
65




16
    REQUIRE(VirtFs::getRealDir("zzz").empty());
66
67

8
    VirtFs::mountDirSilent("data/test",
68
        Append_false);
69

8
    VirtFs::mountDirSilent("../data/test",
70
        Append_false);
71
2
    if (dir1 == true)
72
    {
73




8
        REQUIRE(VirtFs::getRealDir("test") == "data");
74




8
        REQUIRE(VirtFs::getRealDir("test/test.txt") ==
75
            "data");
76




8
        REQUIRE(VirtFs::getRealDir("test\\test.txt") ==
77
            "data");
78





10
        REQUIRE(VirtFs::getRealDir("test.txt") ==
79
            "data" + sep + "test");
80
    }
81
    else
82
    {
83





10
        REQUIRE(VirtFs::getRealDir("test") == ".." + sep + "data");
84





10
        REQUIRE(VirtFs::getRealDir("test/test.txt") ==
85
            ".." + sep + "data");
86





10
        REQUIRE(VirtFs::getRealDir("test\\test.txt") ==
87
            ".." + sep + "data");
88






12
        REQUIRE(VirtFs::getRealDir("test.txt") ==
89
            ".." + sep + "data" + sep + "test");
90
    }
91




16
    REQUIRE(VirtFs::getRealDir("zzz").empty());
92
93

8
    VirtFs::unmountDirSilent("data/test");
94

8
    VirtFs::unmountDirSilent("../data/test");
95
96
2
    if (dir1 == true)
97
    {
98




8
        REQUIRE(VirtFs::getRealDir("test") == "data");
99




8
        REQUIRE(VirtFs::getRealDir("test/test.txt") ==
100
            "data");
101
    }
102
    else
103
    {
104





10
        REQUIRE(VirtFs::getRealDir("test") == ".." + sep + "data");
105





10
        REQUIRE(VirtFs::getRealDir("test/test.txt") ==
106
            ".." + sep + "data");
107
    }
108




16
    REQUIRE(VirtFs::getRealDir("zzz").empty());
109
110

8
    VirtFs::unmountDirSilent("data");
111

8
    VirtFs::unmountDirSilent("../data");
112
2
    VirtFs::deinit();
113
2
}
114
115
6
TEST_CASE("VirtFs1 getRealDir2", "")
116
{
117

8
    VirtFs::init(".");
118
8
    const std::string sep = dirSeparator;
119
8
    std::string name("data/test/test.zip");
120

8
    std::string prefix("data" + sep + "test" + sep);
121

2
    if (Files::existsLocal(name) == false)
122

3
        prefix = ".." + sep + prefix;
123

4
    VirtFs::mountZip(prefix + "test2.zip",
124
        Append_false);
125
126




16
    REQUIRE(VirtFs::getRealDir(".").empty());
127




16
    REQUIRE(VirtFs::getRealDir("..").empty());
128





18
    REQUIRE(VirtFs::getRealDir("test.txt") == prefix + "test2.zip");
129





18
    REQUIRE(VirtFs::getRealDir("dir/1") == prefix + "test2.zip");
130





18
    REQUIRE(VirtFs::getRealDir("dir\\dye.png") ==
131
        prefix + "test2.zip");
132




16
    REQUIRE(VirtFs::getRealDir("zzz").empty());
133
134

4
    VirtFs::mountZip(prefix + "test.zip",
135
        Append_false);
136





18
    REQUIRE(VirtFs::getRealDir("dir//dye.png") ==
137
        prefix + "test2.zip");
138





18
    REQUIRE(VirtFs::getRealDir("dir///hide.png") ==
139
        prefix + "test.zip");
140





18
    REQUIRE(VirtFs::getRealDir("dir\\\\brimmedhat.png") ==
141
        prefix + "test.zip");
142




16
    REQUIRE(VirtFs::getRealDir("zzz").empty());
143
144

4
    VirtFs::unmountZip(prefix + "test.zip");
145
146




16
    REQUIRE(VirtFs::getRealDir("dir/brimmedhat.png").empty());
147





18
    REQUIRE(VirtFs::getRealDir("test.txt") == prefix + "test2.zip");
148





18
    REQUIRE(VirtFs::getRealDir("dir//dye.png") ==
149
        prefix + "test2.zip");
150




16
    REQUIRE(VirtFs::getRealDir("zzz").empty());
151
152

4
    VirtFs::unmountZip(prefix + "test2.zip");
153
2
    VirtFs::deinit();
154
2
}
155
156
6
TEST_CASE("VirtFs1 getRealDir3", "")
157
{
158

8
    VirtFs::init(".");
159
8
    const std::string sep = dirSeparator;
160




16
    REQUIRE(VirtFs::getRealDir(".").empty());
161




16
    REQUIRE(VirtFs::getRealDir("..").empty());
162

14
    const bool dir1 = VirtFs::mountDirSilent2("data",
163
        "test",
164
2
        Append_false);
165








14
    REQUIRE((dir1 || VirtFs::mountDirSilent2("../data",
166
        "test",
167
        Append_false)) == true);
168




16
    REQUIRE(VirtFs::getRealDir("file1.txt").empty());
169
2
    if (dir1 == true)
170
    {
171




8
        REQUIRE(VirtFs::getRealDir("dir1") == "data");
172




8
        REQUIRE(VirtFs::getRealDir("simplefile.txt") == "data");
173
    }
174
    else
175
    {
176





10
        REQUIRE(VirtFs::getRealDir("dir1") == ".." + sep + "data");
177





10
        REQUIRE(VirtFs::getRealDir("simplefile.txt") == ".." + sep + "data");
178
    }
179




16
    REQUIRE(VirtFs::getRealDir("zzz").empty());
180
181

14
    VirtFs::mountDirSilent2("data/test",
182
        "dir2",
183
        Append_false);
184

14
    VirtFs::mountDirSilent2("../data/test",
185
        "dir2",
186
        Append_false);
187




16
    REQUIRE(VirtFs::getRealDir("dir").empty());
188
2
    if (dir1 == true)
189
    {
190





10
        REQUIRE(VirtFs::getRealDir("file1.txt") == "data" + sep + "test");
191




8
        REQUIRE(VirtFs::getRealDir("simplefile.txt") == "data");
192
    }
193
    else
194
    {
195






12
        REQUIRE(VirtFs::getRealDir("file1.txt") ==
196
            ".." + sep + "data" + sep + "test");
197





10
        REQUIRE(VirtFs::getRealDir("simplefile.txt") == ".." + sep + "data");
198
    }
199




16
    REQUIRE(VirtFs::getRealDir("zzz").empty());
200
201
2
    VirtFs::deinit();
202

8
}