GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_exists.cc Lines: 85 91 93.4 %
Date: 2018-11-12 Branches: 376 1000 37.6 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2016-2018  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/fs.h"
24
25
#include "utils/checkutils.h"
26
27
#ifndef UNITTESTS_CATCH
28
#include <algorithm>
29
#endif  // UNITTESTS_CATCH
30
31
#include "debug.h"
32
33
3
TEST_CASE("VirtFs1 exists1", "")
34
{
35
3
    VirtFs::init(".");
36
3
    const bool dir1 = VirtFs::mountDirSilent("data/",
37
1
        Append_false);
38
3
    VirtFs::mountDirSilent("..\\data",
39
1
        Append_false);
40
41




6
    REQUIRE(VirtFs::exists("test"));
42




6
    REQUIRE(VirtFs::exists("test/"));
43




6
    REQUIRE(VirtFs::exists("test/dir1"));
44




6
    REQUIRE(VirtFs::exists("test/dir1/"));
45




7
    REQUIRE(VirtFs::exists("test/dir") == false);
46




7
    REQUIRE(VirtFs::exists("test//units.xml") == true);
47




7
    REQUIRE(VirtFs::exists("test/\\units123.xml") == false);
48




7
    REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
49




7
    REQUIRE(VirtFs::exists("units.xml") == false);
50
51
1
    if (dir1 == true)
52
    {
53
        VirtFs::mountDir("data//test",
54
            Append_false);
55
    }
56
    else
57
    {
58
3
        VirtFs::mountDirSilent("..//data\\test",
59
1
            Append_false);
60
    }
61
62




7
    REQUIRE(VirtFs::exists("test") == true);
63




6
    REQUIRE(VirtFs::exists("test/dir1"));
64




6
    REQUIRE(VirtFs::exists("test/dir1\\"));
65




7
    REQUIRE(VirtFs::exists("test/dir") == false);
66




7
    REQUIRE(VirtFs::exists("test\\units.xml") == true);
67




7
    REQUIRE(VirtFs::exists("test/units123.xml") == false);
68




7
    REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
69




7
    REQUIRE(VirtFs::exists("units.xml") == true);
70




7
    REQUIRE(VirtFs::exists("units.xml/") == false);
71
72
1
    if (dir1 == true)
73
        VirtFs::unmountDirSilent("data/test");
74
    else
75
3
        VirtFs::unmountDirSilent("../data/test");
76
77




7
    REQUIRE(VirtFs::exists("test") == true);
78




6
    REQUIRE(VirtFs::exists("test/dir1"));
79




7
    REQUIRE(VirtFs::exists("test/dir") == false);
80




7
    REQUIRE(VirtFs::exists("test\\units.xml") == true);
81




7
    REQUIRE(VirtFs::exists("test/units123.xml") == false);
82




7
    REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
83




7
    REQUIRE(VirtFs::exists("units.xml") == false);
84




7
    REQUIRE(VirtFs::exists("units.xml/") == false);
85
86
1
    VirtFs::deinit();
87
1
}
88
89
3
TEST_CASE("VirtFs1 exists2", "")
90
{
91
3
    VirtFs::init(".");
92
6
    const bool dir1 = VirtFs::mountDirSilent2("data/",
93
        "test",
94
1
        Append_false);
95
6
    VirtFs::mountDirSilent2("..\\data",
96
        "test",
97
1
        Append_false);
98
99




7
    REQUIRE(VirtFs::exists("test") == false);
100




7
    REQUIRE(VirtFs::exists("test/") == false);
101




6
    REQUIRE(VirtFs::exists("dir1"));
102




6
    REQUIRE(VirtFs::exists("dir1/"));
103




7
    REQUIRE(VirtFs::exists("dir") == false);
104




7
    REQUIRE(VirtFs::exists("units.xml") == true);
105




7
    REQUIRE(VirtFs::exists("units123.xml") == false);
106




7
    REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
107




6
    REQUIRE(VirtFs::exists("units.xml"));
108




7
    REQUIRE(VirtFs::exists("file1.txt") == false);
109




7
    REQUIRE(VirtFs::exists("file2.txt") == false);
110
111
1
    if (dir1 == true)
112
    {
113
        VirtFs::mountDir2("data//test",
114
            "dir2",
115
            Append_false);
116
    }
117
    else
118
    {
119
6
        VirtFs::mountDirSilent2("..//data\\test",
120
            "dir2",
121
1
            Append_false);
122
    }
123
124




7
    REQUIRE(VirtFs::exists("test") == false);
125




7
    REQUIRE(VirtFs::exists("test/") == false);
126




6
    REQUIRE(VirtFs::exists("dir1"));
127




6
    REQUIRE(VirtFs::exists("dir1/"));
128




7
    REQUIRE(VirtFs::exists("dir") == false);
129




7
    REQUIRE(VirtFs::exists("units.xml") == true);
130




7
    REQUIRE(VirtFs::exists("units123.xml") == false);
131




6
    REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
132




6
    REQUIRE(VirtFs::exists("units.xml"));
133




6
    REQUIRE(VirtFs::exists("file1.txt"));
134




6
    REQUIRE(VirtFs::exists("file2.txt"));
135
136
1
    if (dir1 == true)
137
        VirtFs::unmountDirSilent2("data/test", "dir2");
138
    else
139

5
        VirtFs::unmountDirSilent2("../data/test", "dir2");
140
141




7
    REQUIRE(VirtFs::exists("test") == false);
142




7
    REQUIRE(VirtFs::exists("test/") == false);
143




6
    REQUIRE(VirtFs::exists("dir1"));
144




6
    REQUIRE(VirtFs::exists("dir1/"));
145




7
    REQUIRE(VirtFs::exists("dir") == false);
146




7
    REQUIRE(VirtFs::exists("units.xml") == true);
147




7
    REQUIRE(VirtFs::exists("units123.xml") == false);
148




7
    REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
149




6
    REQUIRE(VirtFs::exists("units.xml"));
150




7
    REQUIRE(VirtFs::exists("file1.txt") == false);
151




7
    REQUIRE(VirtFs::exists("file2.txt") == false);
152
153
1
    VirtFs::deinit();
154

4
}