GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/dye/dyepalette.cc Lines: 247 247 100.0 %
Date: 2021-03-17 Branches: 1072 2764 38.8 %

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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



168
    SECTION("simple test 4")
133
    {
134

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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


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



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

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



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



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



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



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



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

27
}