GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/fs/virtfs/virtfs1_exists.cc Lines: 85 85 100.0 %
Date: 2017-11-29 Branches: 400 1028 38.9 %

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/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
6
TEST_CASE("VirtFs1 exists1", "")
34
{
35

8
    VirtFs::init(".");
36
8
    const bool dir1 = VirtFs::mountDirSilent("data/",
37
2
        Append_false);
38

8
    VirtFs::mountDirSilent("..\\data",
39
        Append_false);
40
41




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




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




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




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




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




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




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




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




14
    REQUIRE(VirtFs::exists("units.xml") == false);
50
51
2
    if (dir1 == true)
52
    {
53

4
        VirtFs::mountDir("data//test",
54
            Append_false);
55
    }
56
    else
57
    {
58

4
        VirtFs::mountDirSilent("..//data\\test",
59
            Append_false);
60
    }
61
62




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




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




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




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




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




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




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




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




14
    REQUIRE(VirtFs::exists("units.xml/") == false);
71
72
2
    if (dir1 == true)
73

4
        VirtFs::unmountDirSilent("data/test");
74
    else
75

4
        VirtFs::unmountDirSilent("../data/test");
76
77




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




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




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




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




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




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




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




14
    REQUIRE(VirtFs::exists("units.xml/") == false);
85
86
2
    VirtFs::deinit();
87
2
}
88
89
6
TEST_CASE("VirtFs1 exists2", "")
90
{
91

8
    VirtFs::init(".");
92

14
    const bool dir1 = VirtFs::mountDirSilent2("data/",
93
        "test",
94
2
        Append_false);
95

14
    VirtFs::mountDirSilent2("..\\data",
96
        "test",
97
        Append_false);
98
99




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




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




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




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




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




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




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




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




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




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




14
    REQUIRE(VirtFs::exists("file2.txt") == false);
110
111
2
    if (dir1 == true)
112
    {
113

7
        VirtFs::mountDir2("data//test",
114
            "dir2",
115
            Append_false);
116
    }
117
    else
118
    {
119

7
        VirtFs::mountDirSilent2("..//data\\test",
120
            "dir2",
121
            Append_false);
122
    }
123
124




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




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




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




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




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




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




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




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




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




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




12
    REQUIRE(VirtFs::exists("file2.txt"));
135
136
2
    if (dir1 == true)
137

7
        VirtFs::unmountDirSilent2("data/test", "dir2");
138
    else
139

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




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




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




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




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




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




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




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




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




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




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




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

8
}