GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/dye/dyepalette.cc Lines: 246 246 100.0 %
Date: 2018-11-12 Branches: 1072 2768 38.7 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-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 "configuration.h"
25
#include "configmanager.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/gui.h"
34
#include "gui/theme.h"
35
36
#include "render/sdlgraphics.h"
37
38
#include "resources/sdlimagehelper.h"
39
40
#include "resources/db/palettedb.h"
41
42
#include "resources/dye/dyepalette.h"
43
44
#include "utils/delete2.h"
45
#include "utils/env.h"
46
47
PRAGMA48(GCC diagnostic push)
48
PRAGMA48(GCC diagnostic ignored "-Wshadow")
49
#ifndef USE_SDL2
50
#include <SDL.h>
51
#endif  // USE_SDL2
52
PRAGMA48(GCC diagnostic pop)
53
54
#include "debug.h"
55
56
26
TEST_CASE("DyePalette tests", "")
57
{
58
24
    setEnv("SDL_VIDEODRIVER", "dummy");
59
60
24
    client = new Client;
61
24
    XML::initXML();
62
24
    SDL_Init(SDL_INIT_VIDEO);
63
72
    VirtFs::mountDirSilent("data", Append_false);
64
72
    VirtFs::mountDirSilent("../data", Append_false);
65
72
    VirtFs::mountDirSilent("data/test", Append_false);
66
72
    VirtFs::mountDirSilent("../data/test", Append_false);
67
68
24
    mainGraphics = new SDLGraphics;
69
48
    imageHelper = new SDLImageHelper();
70
71
24
    Dirs::initRootDir();
72
24
    Dirs::initHomeDir();
73
74
24
    ConfigManager::initConfiguration();
75
24
    setConfigDefaults2(config);
76
24
    setBrandingDefaults(branding);
77
78
#ifdef USE_SDL2
79
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
80
        graphicsManager.createWindow(640, 480, 0,
81
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
82
#else  // USE_SDL2
83
84
24
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
85
#endif  // USE_SDL2
86
87
24
    theme = new Theme;
88
24
    Theme::selectSkin();
89
90
24
    ActorSprite::load();
91
24
    gui = new Gui();
92
24
    gui->postInit(mainGraphics);
93
24
    setPathsDefaults(paths);
94
24
    PaletteDB::load();
95
96



168
    SECTION("simple test 1")
97
    {
98

4
        DyePalette palette("#12ff34", 6);
99



5
        REQUIRE(palette.mColors.size() == 1);
100



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
101



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
102



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
103



4
        REQUIRE(palette.mColors[0].value[3] == 0x00);
104
    }
105
106



168
    SECTION("simple test 2")
107
    {
108

4
        DyePalette palette("#12ff3456", 8);
109



5
        REQUIRE(palette.mColors.size() == 1);
110



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
111



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
112



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
113



4
        REQUIRE(palette.mColors[0].value[3] == 0x56);
114
    }
115
116



168
    SECTION("simple test 3")
117
    {
118

4
        DyePalette palette("#12ff34,002211", 6);
119



5
        REQUIRE(palette.mColors.size() == 2);
120



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
121



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
122



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
123



4
        REQUIRE(palette.mColors[0].value[3] == 0x00);
124
125



4
        REQUIRE(palette.mColors[1].value[0] == 0x00);
126



4
        REQUIRE(palette.mColors[1].value[1] == 0x22);
127



4
        REQUIRE(palette.mColors[1].value[2] == 0x11);
128



4
        REQUIRE(palette.mColors[1].value[3] == 0x00);
129
    }
130
131



144
    SECTION("simple test 4")
132
    {
133

4
        DyePalette palette("#12ff3412,00221133", 8);
134



5
        REQUIRE(palette.mColors.size() == 2);
135



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
136



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
137



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
138



4
        REQUIRE(palette.mColors[0].value[3] == 0x12);
139
140



4
        REQUIRE(palette.mColors[1].value[0] == 0x00);
141



4
        REQUIRE(palette.mColors[1].value[1] == 0x22);
142



4
        REQUIRE(palette.mColors[1].value[2] == 0x11);
143



4
        REQUIRE(palette.mColors[1].value[3] == 0x33);
144
    }
145
146



168
    SECTION("simple test 5")
147
    {
148

4
        DyePalette palette("#12ff34,", 6);
149



5
        REQUIRE(palette.mColors.size() == 1);
150



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
151



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
152



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
153



4
        REQUIRE(palette.mColors[0].value[3] == 0x00);
154
    }
155
156



168
    SECTION("simple test 6")
157
    {
158

4
        DyePalette palette("#12ff3456,", 8);
159



5
        REQUIRE(palette.mColors.size() == 1);
160



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
161



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
162



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
163



4
        REQUIRE(palette.mColors[0].value[3] == 0x56);
164
    }
165
166



168
    SECTION("simple test 7")
167
    {
168

4
        DyePalette palette("#,,,12ff3412,,00221133", 8);
169



5
        REQUIRE(palette.mColors.size() == 2);
170



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
171



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
172



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
173



4
        REQUIRE(palette.mColors[0].value[3] == 0x12);
174
175



4
        REQUIRE(palette.mColors[1].value[0] == 0x00);
176



4
        REQUIRE(palette.mColors[1].value[1] == 0x22);
177



4
        REQUIRE(palette.mColors[1].value[2] == 0x11);
178



4
        REQUIRE(palette.mColors[1].value[3] == 0x33);
179
    }
180
181



168
    SECTION("palette test 1")
182
    {
183

4
        DyePalette palette("@Untitled1", 6);
184



5
        REQUIRE(palette.mColors.size() == 1);
185



4
        REQUIRE(palette.mColors[0].value[0] == 47);
186



4
        REQUIRE(palette.mColors[0].value[1] == 56);
187



4
        REQUIRE(palette.mColors[0].value[2] == 46);
188



4
        REQUIRE(palette.mColors[0].value[3] == 255);
189
    }
190
191



168
    SECTION("palette test 2")
192
    {
193

4
        DyePalette palette("@Untitled1,Untitled8", 6);
194



5
        REQUIRE(palette.mColors.size() == 2);
195



4
        REQUIRE(palette.mColors[0].value[0] == 47);
196



4
        REQUIRE(palette.mColors[0].value[1] == 56);
197



4
        REQUIRE(palette.mColors[0].value[2] == 46);
198



4
        REQUIRE(palette.mColors[0].value[3] == 255);
199
200



4
        REQUIRE(palette.mColors[1].value[0] == 0);
201



4
        REQUIRE(palette.mColors[1].value[1] == 0);
202



4
        REQUIRE(palette.mColors[1].value[2] == 255);
203



4
        REQUIRE(palette.mColors[1].value[3] == 255);
204
    }
205
206



168
    SECTION("palette test 3")
207
    {
208

4
        DyePalette palette("@Untitled1,", 6);
209



5
        REQUIRE(palette.mColors.size() == 1);
210



4
        REQUIRE(palette.mColors[0].value[0] == 47);
211



4
        REQUIRE(palette.mColors[0].value[1] == 56);
212



4
        REQUIRE(palette.mColors[0].value[2] == 46);
213



4
        REQUIRE(palette.mColors[0].value[3] == 255);
214
    }
215
216



168
    SECTION("palette test 4")
217
    {
218

4
        DyePalette palette("@,,,Untitled1,,Untitled8", 6);
219



5
        REQUIRE(palette.mColors.size() == 2);
220



4
        REQUIRE(palette.mColors[0].value[0] == 47);
221



4
        REQUIRE(palette.mColors[0].value[1] == 56);
222



4
        REQUIRE(palette.mColors[0].value[2] == 46);
223



4
        REQUIRE(palette.mColors[0].value[3] == 255);
224
225



4
        REQUIRE(palette.mColors[1].value[0] == 0);
226



4
        REQUIRE(palette.mColors[1].value[1] == 0);
227



4
        REQUIRE(palette.mColors[1].value[2] == 255);
228



4
        REQUIRE(palette.mColors[1].value[3] == 255);
229
    }
230
231



168
    SECTION("palette test 5")
232
    {
233

4
        DyePalette palette("@12ff34", 6);
234



5
        REQUIRE(palette.mColors.size() == 1);
235



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
236



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
237



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
238



4
        REQUIRE(palette.mColors[0].value[3] == 0x00);
239
    }
240
241



168
    SECTION("palette test 6")
242
    {
243

4
        DyePalette palette("@12ff3456", 8);
244



5
        REQUIRE(palette.mColors.size() == 1);
245



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
246



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
247



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
248



4
        REQUIRE(palette.mColors[0].value[3] == 0x56);
249
    }
250
251



168
    SECTION("palette test 7")
252
    {
253

4
        DyePalette palette("@12ff34,002211", 6);
254



5
        REQUIRE(palette.mColors.size() == 2);
255



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
256



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
257



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
258



4
        REQUIRE(palette.mColors[0].value[3] == 0x00);
259
260



4
        REQUIRE(palette.mColors[1].value[0] == 0x00);
261



4
        REQUIRE(palette.mColors[1].value[1] == 0x22);
262



4
        REQUIRE(palette.mColors[1].value[2] == 0x11);
263



4
        REQUIRE(palette.mColors[1].value[3] == 0x00);
264
    }
265
266



168
    SECTION("palette test 8")
267
    {
268

4
        DyePalette palette("@12ff3412,00221133", 8);
269



5
        REQUIRE(palette.mColors.size() == 2);
270



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
271



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
272



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
273



4
        REQUIRE(palette.mColors[0].value[3] == 0x12);
274
275



4
        REQUIRE(palette.mColors[1].value[0] == 0x00);
276



4
        REQUIRE(palette.mColors[1].value[1] == 0x22);
277



4
        REQUIRE(palette.mColors[1].value[2] == 0x11);
278



4
        REQUIRE(palette.mColors[1].value[3] == 0x33);
279
    }
280
281



168
    SECTION("palette test 9")
282
    {
283

4
        DyePalette palette("@12ff34,", 6);
284



5
        REQUIRE(palette.mColors.size() == 1);
285



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
286



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
287



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
288



4
        REQUIRE(palette.mColors[0].value[3] == 0x00);
289
    }
290
291



168
    SECTION("palette test 10")
292
    {
293

4
        DyePalette palette("@12ff3456,", 8);
294



5
        REQUIRE(palette.mColors.size() == 1);
295



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
296



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
297



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
298



4
        REQUIRE(palette.mColors[0].value[3] == 0x56);
299
    }
300
301



168
    SECTION("palette test 11")
302
    {
303

4
        DyePalette palette("@,,,12ff3412,,00221133", 8);
304



5
        REQUIRE(palette.mColors.size() == 2);
305



4
        REQUIRE(palette.mColors[0].value[0] == 0x12);
306



4
        REQUIRE(palette.mColors[0].value[1] == 0xff);
307



4
        REQUIRE(palette.mColors[0].value[2] == 0x34);
308



4
        REQUIRE(palette.mColors[0].value[3] == 0x12);
309
310



4
        REQUIRE(palette.mColors[1].value[0] == 0x00);
311



4
        REQUIRE(palette.mColors[1].value[1] == 0x22);
312



4
        REQUIRE(palette.mColors[1].value[2] == 0x11);
313



4
        REQUIRE(palette.mColors[1].value[3] == 0x33);
314
    }
315
316



168
    SECTION("palette test 12")
317
    {
318

4
        DyePalette palette("@Untitled1,334455", 6);
319



5
        REQUIRE(palette.mColors.size() == 2);
320



4
        REQUIRE(palette.mColors[0].value[0] == 47);
321



4
        REQUIRE(palette.mColors[0].value[1] == 56);
322



4
        REQUIRE(palette.mColors[0].value[2] == 46);
323



4
        REQUIRE(palette.mColors[0].value[3] == 255);
324
325



4
        REQUIRE(palette.mColors[1].value[0] == 0x33);
326



4
        REQUIRE(palette.mColors[1].value[1] == 0x44);
327



4
        REQUIRE(palette.mColors[1].value[2] == 0x55);
328



4
        REQUIRE(palette.mColors[1].value[3] == 0x00);
329
    }
330
331



168
    SECTION("palette test 13")
332
    {
333

4
        DyePalette palette("@Untitled1,33445566", 8);
334



5
        REQUIRE(palette.mColors.size() == 2);
335



4
        REQUIRE(palette.mColors[0].value[0] == 47);
336



4
        REQUIRE(palette.mColors[0].value[1] == 56);
337



4
        REQUIRE(palette.mColors[0].value[2] == 46);
338



4
        REQUIRE(palette.mColors[0].value[3] == 255);
339
340



4
        REQUIRE(palette.mColors[1].value[0] == 0x33);
341



4
        REQUIRE(palette.mColors[1].value[1] == 0x44);
342



4
        REQUIRE(palette.mColors[1].value[2] == 0x55);
343



4
        REQUIRE(palette.mColors[1].value[3] == 0x66);
344
    }
345
346



168
    SECTION("palette test 14")
347
    {
348

4
        DyePalette palette("@+77,Untitled1", 8);
349



5
        REQUIRE(palette.mColors.size() == 1);
350



4
        REQUIRE(palette.mColors[0].value[0] == 47);
351



4
        REQUIRE(palette.mColors[0].value[1] == 56);
352



4
        REQUIRE(palette.mColors[0].value[2] == 46);
353



4
        REQUIRE(palette.mColors[0].value[3] == 0x77);
354
    }
355
356



168
    SECTION("palette test 15")
357
    {
358

4
        DyePalette palette("@+87,Untitled1,Untitled8", 8);
359



5
        REQUIRE(palette.mColors.size() == 2);
360



4
        REQUIRE(palette.mColors[0].value[0] == 47);
361



4
        REQUIRE(palette.mColors[0].value[1] == 56);
362



4
        REQUIRE(palette.mColors[0].value[2] == 46);
363



4
        REQUIRE(palette.mColors[0].value[3] == 0x87);
364
365



4
        REQUIRE(palette.mColors[1].value[0] == 0);
366



4
        REQUIRE(palette.mColors[1].value[1] == 0);
367



4
        REQUIRE(palette.mColors[1].value[2] == 255);
368



4
        REQUIRE(palette.mColors[1].value[3] == 0x87);
369
    }
370
371



168
    SECTION("palette test 16")
372
    {
373

4
        DyePalette palette("@+87,Untitled1,+34,Untitled8", 8);
374



5
        REQUIRE(palette.mColors.size() == 2);
375



4
        REQUIRE(palette.mColors[0].value[0] == 47);
376



4
        REQUIRE(palette.mColors[0].value[1] == 56);
377



4
        REQUIRE(palette.mColors[0].value[2] == 46);
378



4
        REQUIRE(palette.mColors[0].value[3] == 0x87);
379
380



4
        REQUIRE(palette.mColors[1].value[0] == 0);
381



4
        REQUIRE(palette.mColors[1].value[1] == 0);
382



4
        REQUIRE(palette.mColors[1].value[2] == 255);
383



4
        REQUIRE(palette.mColors[1].value[3] == 0x34);
384
    }
385
386



168
    SECTION("palette test 17")
387
    {
388

4
        DyePalette palette("@+12,+23,+77,Untitled1", 8);
389



5
        REQUIRE(palette.mColors.size() == 1);
390



4
        REQUIRE(palette.mColors[0].value[0] == 47);
391



4
        REQUIRE(palette.mColors[0].value[1] == 56);
392



4
        REQUIRE(palette.mColors[0].value[2] == 46);
393



4
        REQUIRE(palette.mColors[0].value[3] == 0x77);
394
    }
395
24
    delete2(client);
396
72
    VirtFs::unmountDirSilent("data");
397
72
    VirtFs::unmountDirSilent("../data");
398
72
    VirtFs::unmountDirSilent("data/test");
399
72
    VirtFs::unmountDirSilent("../data/test");
400

27
}