GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/xmlutils.cc Lines: 96 96 100.0 %
Date: 2017-11-29 Branches: 160 376 42.6 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2014-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 "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
6
TEST_CASE("xmlutils readXmlIntVector 1", "")
49
{
50
2
    setEnv("SDL_VIDEODRIVER", "dummy");
51
52
2
    client = new Client;
53
2
    XML::initXML();
54

8
    VirtFs::mountDirSilent("data", Append_false);
55

8
    VirtFs::mountDirSilent("../data", Append_false);
56
57
2
    mainGraphics = new SDLGraphics;
58
4
    imageHelper = new SDLImageHelper();
59
60
2
    Dirs::initHomeDir();
61
62
2
    setBrandingDefaults(branding);
63
2
    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
2
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
72
#endif  // USE_SDL2
73
74
2
    userPalette = new UserPalette;
75
76
2
    Dirs::initRootDir();
77
2
    theme = new Theme;
78
2
    Theme::selectSkin();
79
80
2
    ActorSprite::load();
81
82
4
    STD_VECTOR<int> arr;
83
84



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



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



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



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



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



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



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

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

8
    VirtFs::unmountDirSilent("../data");
105
2
}
106
107
6
TEST_CASE("xmlutils readXmlStringMap 1", "")
108
{
109
2
    setEnv("SDL_VIDEODRIVER", "dummy");
110
111
2
    client = new Client;
112
2
    XML::initXML();
113

8
    VirtFs::mountDirSilent("data", Append_false);
114

8
    VirtFs::mountDirSilent("../data", Append_false);
115
116
2
    mainGraphics = new SDLGraphics;
117
4
    imageHelper = new SDLImageHelper();
118
119
2
    Dirs::initRootDir();
120
2
    Dirs::initHomeDir();
121
122
2
    setBrandingDefaults(branding);
123
2
    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
2
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
132
#endif  // USE_SDL2
133
134
2
    userPalette = new UserPalette;
135
136
2
    theme = new Theme;
137
2
    Theme::selectSkin();
138
139
2
    ActorSprite::load();
140
141
4
    std::map<std::string, std::string> arr;
142
143



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



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




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




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




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

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

8
    VirtFs::unmountDirSilent("../data");
163
2
}
164
165
6
TEST_CASE("xmlutils readXmlIntMap 1", "")
166
{
167
2
    setEnv("SDL_VIDEODRIVER", "dummy");
168
169
2
    client = new Client;
170
2
    XML::initXML();
171

8
    VirtFs::mountDirSilent("data", Append_false);
172

8
    VirtFs::mountDirSilent("../data", Append_false);
173

8
    VirtFs::mountDirSilent("data/test", Append_false);
174

8
    VirtFs::mountDirSilent("../data/test", Append_false);
175
176
2
    mainGraphics = new SDLGraphics;
177
4
    imageHelper = new SDLImageHelper();
178
179
2
    Dirs::initRootDir();
180
2
    Dirs::initHomeDir();
181
182
2
    setBrandingDefaults(branding);
183
2
    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
2
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
192
#endif  // USE_SDL2
193
194
2
    userPalette = new UserPalette;
195
196
2
    theme = new Theme;
197
2
    Theme::selectSkin();
198
199
2
    ActorSprite::load();
200
201
4
    std::map<int32_t, int32_t> arr;
202
203



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



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




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




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




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

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

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

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

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

8
}