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

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


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



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



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



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



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



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



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

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

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



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



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




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




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




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

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

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



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



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




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




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




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

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

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

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

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

4
}