GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_mountdir1.cc Lines: 98 98 100.0 %
Date: 2017-11-29 Branches: 635 1606 39.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/virtfs/direntry.h"
24
#include "fs/virtfs/fs.h"
25
26
#include "utils/checkutils.h"
27
28
#ifndef UNITTESTS_CATCH
29
#include <algorithm>
30
#endif  // UNITTESTS_CATCH
31
32
#include "debug.h"
33
34
16
TEST_CASE("VirtFs1 mountDir1", "")
35
{
36

48
    VirtFs::init(".");
37
48
    const std::string sep = dirSeparator;
38



84
    SECTION("simple 1")
39
    {
40




12
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
41
            Append_false));
42




14
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
43
            nullptr);
44





16
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") ==
45
            nullptr);
46




14
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
47
            nullptr);
48




10
        REQUIRE(VirtFs::getEntries().size() == 1);
49




10
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
50




8
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
51




8
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
52




8
        REQUIRE(static_cast<VirtFs::DirEntry*>(
53
            VirtFs::getEntries()[0])->userDir == "dir1");
54
    }
55
56



84
    SECTION("simple 2")
57
    {
58




12
        REQUIRE(VirtFs::mountDirSilentTest("dir1/",
59
            Append_true));
60




14
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
61
            nullptr);
62





16
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") ==
63
            nullptr);
64




14
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
65
            nullptr);
66




10
        REQUIRE(VirtFs::getEntries().size() == 1);
67




10
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
68




8
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
69




8
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
70




10
        REQUIRE(static_cast<VirtFs::DirEntry*>(
71
            VirtFs::getEntries()[0])->userDir == "dir1" + sep);
72
    }
73
74



84
    SECTION("simple 3")
75
    {
76




12
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
77
            Append_false));
78




12
        REQUIRE(VirtFs::mountDirSilentTest("dir2",
79
            Append_false));
80




14
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
81
            nullptr);
82





16
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") ==
83
            nullptr);
84




14
        REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) !=
85
            nullptr);
86




14
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
87
            nullptr);
88




10
        REQUIRE(VirtFs::getEntries().size() == 2);
89




10
        REQUIRE(VirtFs::getEntries()[0]->root == "dir2" + sep);
90




10
        REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
91




8
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
92




8
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
93




8
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
94




8
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
95




8
        REQUIRE(static_cast<VirtFs::DirEntry*>(
96
            VirtFs::getEntries()[0])->userDir == "dir2");
97




8
        REQUIRE(static_cast<VirtFs::DirEntry*>(
98
            VirtFs::getEntries()[1])->userDir == "dir1");
99
    }
100
101



84
    SECTION("simple 4")
102
    {
103




12
        REQUIRE(VirtFs::mountDirSilentTest("dir1\\",
104
            Append_true));
105




12
        REQUIRE(VirtFs::mountDirSilentTest("dir2",
106
            Append_true));
107




14
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
108
            nullptr);
109




14
        REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) !=
110
            nullptr);
111




14
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
112
            nullptr);
113




10
        REQUIRE(VirtFs::getEntries().size() == 2);
114




10
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
115




10
        REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep);
116




8
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
117




8
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
118




8
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
119




8
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
120




10
        REQUIRE(static_cast<VirtFs::DirEntry*>(
121
            VirtFs::getEntries()[0])->userDir == "dir1" + sep);
122




8
        REQUIRE(static_cast<VirtFs::DirEntry*>(
123
            VirtFs::getEntries()[1])->userDir == "dir2");
124
    }
125
126



84
    SECTION("simple 5")
127
    {
128




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




12
        REQUIRE(VirtFs::mountDirSilentTest("dir2",
131
            Append_true));
132




12
        REQUIRE(VirtFs::mountDirSilentTest("dir3/test",
133
            Append_true));
134




14
        REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) !=
135
            nullptr);
136




14
        REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) !=
137
            nullptr);
138





18
        REQUIRE(VirtFs::searchByRootInternal(
139
            "dir3" + sep + "test" + sep, std::string()) != nullptr);
140




14
        REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) ==
141
            nullptr);
142




10
        REQUIRE(VirtFs::getEntries().size() == 3);
143




10
        REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
144




10
        REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep);
145





14
        REQUIRE(VirtFs::getEntries()[2]->root == "dir3" + sep + "test" + sep);
146




8
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
147




8
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
148




8
        REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Dir);
149




8
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
150




8
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
151




8
        REQUIRE(VirtFs::getEntries()[2]->subDir.empty());
152




8
        REQUIRE(static_cast<VirtFs::DirEntry*>(
153
            VirtFs::getEntries()[0])->userDir == "dir1");
154




8
        REQUIRE(static_cast<VirtFs::DirEntry*>(
155
            VirtFs::getEntries()[1])->userDir == "dir2");
156





12
        REQUIRE(static_cast<VirtFs::DirEntry*>(
157
            VirtFs::getEntries()[2])->userDir == "dir3" + sep + "test");
158
    }
159
160



84
    SECTION("simple 6")
161
    {
162




12
        REQUIRE(VirtFs::mountDirSilentTest("dir1",
163
            Append_true));
164




12
        REQUIRE(VirtFs::mountDirSilentTest("dir2",
165
            Append_true));
166




12
        REQUIRE(VirtFs::mountDirSilentTest("dir3\\test",
167
            Append_false));
168





16
        REQUIRE(VirtFs::searchByRootInternal(
169
            "dir1" + sep + "", std::string()) != nullptr);
170





16
        REQUIRE(VirtFs::searchByRootInternal(
171
            "dir2" + sep + "", std::string()) != nullptr);
172





18
        REQUIRE(VirtFs::searchByRootInternal(
173
            "dir3" + sep + "test" + sep, std::string()) != nullptr);
174





16
        REQUIRE(VirtFs::searchByRootInternal(
175
            "test" + sep + "", std::string()) == nullptr);
176




10
        REQUIRE(VirtFs::getEntries().size() == 3);
177





14
        REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep + "test" + sep);
178




10
        REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
179




10
        REQUIRE(VirtFs::getEntries()[2]->root == "dir2" + sep);
180




8
        REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
181




8
        REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
182




8
        REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Dir);
183




8
        REQUIRE(VirtFs::getEntries()[0]->subDir.empty());
184




8
        REQUIRE(VirtFs::getEntries()[1]->subDir.empty());
185




8
        REQUIRE(VirtFs::getEntries()[2]->subDir.empty());
186





12
        REQUIRE(static_cast<VirtFs::DirEntry*>(
187
            VirtFs::getEntries()[0])->userDir == "dir3" + sep + "test");
188




8
        REQUIRE(static_cast<VirtFs::DirEntry*>(
189
            VirtFs::getEntries()[1])->userDir == "dir1");
190




8
        REQUIRE(static_cast<VirtFs::DirEntry*>(
191
            VirtFs::getEntries()[2])->userDir == "dir2");
192
    }
193
194
12
    VirtFs::deinit();
195

18
}