GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_mountdir1.cc Lines: 98 98 100.0 %
Date: 2021-03-17 Branches: 634 1604 39.5 %

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/virtfs/direntry.h"
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
✓✗
8
TEST_CASE("VirtFs1 mountDir1", "")
36
{
37
✓✗
18
    VirtFs::init(".");
38
24
    const std::string sep = dirSeparator;
39
✓✗✓✗
✓✗✓✗
✓✗✓✓
42
    SECTION("simple 1")
40
    {
41
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
42
            Append_false));
43
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
44
            nullptr);
45
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
8
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") ==
46
            nullptr);
47
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
48
            nullptr);
49
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
5
        REQUIRE(VirtFs::getEntries().size() == 1);
50
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
51
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
52
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
53
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
54
            VirtFs::getEntries()[0])->userDir == "dir1");
55
    }
56
57
✓✗✓✗
✓✗✓✗
✓✗✓✓
42
    SECTION("simple 2")
58
    {
59
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
6
        REQUIRE(VirtFs::mountDirSilentTest("dir1/",
60
            Append_true));
61
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
62
            nullptr);
63
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
8
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") ==
64
            nullptr);
65
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
66
            nullptr);
67
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
5
        REQUIRE(VirtFs::getEntries().size() == 1);
68
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
69
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
70
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
71
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(static_cast<VirtFs::DirEntry*>(
72
            VirtFs::getEntries()[0])->userDir == "dir1" + sep);
73
    }
74
75
✓✗✓✗
✓✗✓✗
✓✗✓✓
42
    SECTION("simple 3")
76
    {
77
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
78
            Append_false));
79
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
6
        REQUIRE(VirtFs::mountDirSilentTest("dir2",
80
            Append_false));
81
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
82
            nullptr);
83
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
8
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") ==
84
            nullptr);
85
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) !=
86
            nullptr);
87
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
88
            nullptr);
89
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
5
        REQUIRE(VirtFs::getEntries().size() == 2);
90
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir2" + sep);
91
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
92
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
93
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
94
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
95
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
96
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
97
            VirtFs::getEntries()[0])->userDir == "dir2");
98
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
99
            VirtFs::getEntries()[1])->userDir == "dir1");
100
    }
101
102
✓✗✓✗
✓✗✓✗
✓✗✓✓
42
    SECTION("simple 4")
103
    {
104
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
6
        REQUIRE(VirtFs::mountDirSilentTest("dir1\\",
105
            Append_true));
106
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
6
        REQUIRE(VirtFs::mountDirSilentTest("dir2",
107
            Append_true));
108
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
109
            nullptr);
110
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) !=
111
            nullptr);
112
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
113
            nullptr);
114
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
5
        REQUIRE(VirtFs::getEntries().size() == 2);
115
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
116
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep);
117
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
118
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
119
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
120
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
121
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(static_cast<VirtFs::DirEntry*>(
122
            VirtFs::getEntries()[0])->userDir == "dir1" + sep);
123
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
124
            VirtFs::getEntries()[1])->userDir == "dir2");
125
    }
126
127
✓✗✓✗
✓✗✓✗
✓✗✓✓
42
    SECTION("simple 5")
128
    {
129
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
130
            Append_true));
131
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(VirtFs::mountDirSilentTest("dir2",
132
            Append_true));
133
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
6
        REQUIRE(VirtFs::mountDirSilentTest("dir3/test",
134
            Append_true));
135
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
136
            nullptr);
137
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) !=
138
            nullptr);
139
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
9
        REQUIRE(VirtFs::searchByRootInternal(
140
            "dir3" + sep + "test" + sep, std::string()) != nullptr);
141
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
142
            nullptr);
143
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
5
        REQUIRE(VirtFs::getEntries().size() == 3);
144
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
145
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep);
146
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::getEntries()[2]->root == "dir3" + sep + "test" + sep);
147
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
148
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
149
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Dir);
150
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
151
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
152
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[2]->subDir.empty());
153
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
154
            VirtFs::getEntries()[0])->userDir == "dir1");
155
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
156
            VirtFs::getEntries()[1])->userDir == "dir2");
157
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
6
        REQUIRE(static_cast<VirtFs::DirEntry*>(
158
            VirtFs::getEntries()[2])->userDir == "dir3" + sep + "test");
159
    }
160
161
✓✗✓✗
✓✗✓✗
✓✗✓✓
42
    SECTION("simple 6")
162
    {
163
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
6
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
164
            Append_true));
165
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
6
        REQUIRE(VirtFs::mountDirSilentTest("dir2",
166
            Append_true));
167
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
6
        REQUIRE(VirtFs::mountDirSilentTest("dir3\\test",
168
            Append_false));
169
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
8
        REQUIRE(VirtFs::searchByRootInternal(
170
            "dir1" + sep + "", std::string()) != nullptr);
171
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
8
        REQUIRE(VirtFs::searchByRootInternal(
172
            "dir2" + sep + "", std::string()) != nullptr);
173
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
9
        REQUIRE(VirtFs::searchByRootInternal(
174
            "dir3" + sep + "test" + sep, std::string()) != nullptr);
175
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
8
        REQUIRE(VirtFs::searchByRootInternal(
176
            "test" + sep + "", std::string()) == nullptr);
177
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
5
        REQUIRE(VirtFs::getEntries().size() == 3);
178
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
7
        REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep + "test" + sep);
179
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
180
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✗✗
✗✗
5
        REQUIRE(VirtFs::getEntries()[2]->root == "dir2" + sep);
181
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
182
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
183
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Dir);
184
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
185
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
186
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(VirtFs::getEntries()[2]->subDir.empty());
187
✓✗✓✗
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
6
        REQUIRE(static_cast<VirtFs::DirEntry*>(
188
            VirtFs::getEntries()[0])->userDir == "dir3" + sep + "test");
189
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
190
            VirtFs::getEntries()[1])->userDir == "dir1");
191
✓✗✓✗
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
        REQUIRE(static_cast<VirtFs::DirEntry*>(
192
            VirtFs::getEntries()[2])->userDir == "dir2");
193
    }
194
195
✓✗
6
    VirtFs::deinit();
196
✓✗✓✗
9
}