GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/xmlutils.cc Lines: 99 99 100.0 %
Date: 2021-03-17 Branches: 152 360 42.2 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2014-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 "client.h"
25
#include "configmanager.h"
26
#include "configuration.h"
27
#include "dirs.h"
28
#include "graphicsmanager.h"
29
30
#include "being/actorsprite.h"
31
32
#include "fs/virtfs/fs.h"
33
34
#include "gui/userpalette.h"
35
#include "gui/theme.h"
36
37
#include "utils/delete2.h"
38
#include "utils/env.h"
39
#include "utils/xmlutils.h"
40
41
#include "render/sdlgraphics.h"
42
43
#include "resources/resourcemanager/resourcemanager.h"
44
45
#include "resources/sdlimagehelper.h"
46
47
#include "debug.h"
48
49
3
TEST_CASE("xmlutils readXmlIntVector 1", "")
50
{
51
1
    setEnv("SDL_VIDEODRIVER", "dummy");
52
53
1
    client = new Client;
54
1
    XML::initXML();
55
3
    VirtFs::mountDirSilent("data", Append_false);
56
3
    VirtFs::mountDirSilent("../data", Append_false);
57
58
1
    mainGraphics = new SDLGraphics;
59
2
    imageHelper = new SDLImageHelper();
60
61
1
    Dirs::initHomeDir();
62
63
1
    setBrandingDefaults(branding);
64
1
    ConfigManager::initConfiguration();
65
66
#ifdef USE_SDL2
67
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
68
        GraphicsManager::createWindow(640, 480, 0,
69
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
70
#else  // USE_SDL2
71
72
1
    GraphicsManager::createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
73
#endif  // USE_SDL2
74
75
1
    userPalette = new UserPalette;
76
77
1
    Dirs::initRootDir();
78
1
    theme = new Theme;
79
1
    Theme::selectSkin();
80
81
1
    ActorSprite::load();
82
83
2
    STD_VECTOR<int> arr;
84
85


15
    readXmlIntVector("graphics/gui/browserbox.xml",
86
        "skinset",
87
        "widget",
88
        "option",
89
        "value",
90
        arr,
91
1
        SkipError_false);
92
93



5
    REQUIRE(5 == arr.size());
94



4
    REQUIRE(1 == arr[0]);
95



5
    REQUIRE(15 == arr[1]);
96



5
    REQUIRE(0 == arr[2]);
97



5
    REQUIRE(1 == arr[3]);
98



5
    REQUIRE(1 == arr[4]);
99
100
1
    delete2(userPalette)
101
1
    delete2(theme)
102
1
    delete2(client)
103
1
    ResourceManager::deleteInstance();
104

3
    VirtFs::unmountDirSilent("data");
105

4
    VirtFs::unmountDirSilent("../data");
106
1
}
107
108
3
TEST_CASE("xmlutils readXmlStringMap 1", "")
109
{
110
1
    setEnv("SDL_VIDEODRIVER", "dummy");
111
112
1
    client = new Client;
113
1
    XML::initXML();
114
3
    VirtFs::mountDirSilent("data", Append_false);
115
3
    VirtFs::mountDirSilent("../data", Append_false);
116
117
1
    mainGraphics = new SDLGraphics;
118
2
    imageHelper = new SDLImageHelper();
119
120
1
    Dirs::initRootDir();
121
1
    Dirs::initHomeDir();
122
123
1
    setBrandingDefaults(branding);
124
1
    ConfigManager::initConfiguration();
125
126
#ifdef USE_SDL2
127
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
128
        GraphicsManager::createWindow(640, 480, 0,
129
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
130
#else  // USE_SDL2
131
132
1
    GraphicsManager::createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
133
#endif  // USE_SDL2
134
135
1
    userPalette = new UserPalette;
136
137
1
    theme = new Theme;
138
1
    Theme::selectSkin();
139
140
1
    ActorSprite::load();
141
142
2
    std::map<std::string, std::string> arr;
143
144



18
    readXmlStringMap("graphics/sprites/manaplus_emotes.xml",
145
        "emotes",
146
        "emote",
147
        "sprite",
148
        "name",
149
        "variant",
150
        arr,
151
1
        SkipError_false);
152
153



5
    REQUIRE(arr.size() == 27);
154




7
    REQUIRE(arr["Kitty"] == "0");
155




7
    REQUIRE(arr["xD"] == "1");
156




7
    REQUIRE(arr["Metal"] == "26");
157
158
1
    delete2(userPalette)
159
1
    delete2(theme)
160
1
    delete2(client)
161
1
    ResourceManager::deleteInstance();
162

3
    VirtFs::unmountDirSilent("data");
163

4
    VirtFs::unmountDirSilent("../data");
164
1
}
165
166
3
TEST_CASE("xmlutils readXmlIntMap 1", "")
167
{
168
1
    setEnv("SDL_VIDEODRIVER", "dummy");
169
170
1
    client = new Client;
171
1
    XML::initXML();
172
3
    VirtFs::mountDirSilent("data", Append_false);
173
3
    VirtFs::mountDirSilent("../data", Append_false);
174
3
    VirtFs::mountDirSilent("data/test", Append_false);
175
3
    VirtFs::mountDirSilent("../data/test", Append_false);
176
177
1
    mainGraphics = new SDLGraphics;
178
2
    imageHelper = new SDLImageHelper();
179
180
1
    Dirs::initRootDir();
181
1
    Dirs::initHomeDir();
182
183
1
    setBrandingDefaults(branding);
184
1
    ConfigManager::initConfiguration();
185
186
#ifdef USE_SDL2
187
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
188
        GraphicsManager::createWindow(640, 480, 0,
189
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
190
#else  // USE_SDL2
191
192
1
    GraphicsManager::createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
193
#endif  // USE_SDL2
194
195
1
    userPalette = new UserPalette;
196
197
1
    theme = new Theme;
198
1
    Theme::selectSkin();
199
200
1
    ActorSprite::load();
201
202
2
    std::map<int32_t, int32_t> arr;
203
204



18
    readXmlIntMap("testintmap.xml",
205
        "tests",
206
        "sub",
207
        "item",
208
        "id",
209
        "val",
210
        arr,
211
1
        SkipError_false);
212
213



5
    REQUIRE(arr.size() == 3);
214




4
    REQUIRE(arr[1] == 2);
215




4
    REQUIRE(arr[10] == 20);
216




4
    REQUIRE(arr[3] == 0);
217
218
1
    delete2(userPalette)
219
1
    delete2(theme)
220
1
    delete2(client)
221
1
    ResourceManager::deleteInstance();
222

3
    VirtFs::unmountDirSilent("data/test");
223

3
    VirtFs::unmountDirSilent("../data/test");
224

3
    VirtFs::unmountDirSilent("data");
225

4
    VirtFs::unmountDirSilent("../data");
226

4
}