GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/dye/dyepalette.cc Lines: 246 246 100.0 %
Date: 2017-11-29 Branches: 1080 2784 38.8 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-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 "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
52
TEST_CASE("DyePalette tests", "")
57
{
58
48
    setEnv("SDL_VIDEODRIVER", "dummy");
59
60
48
    client = new Client;
61
48
    XML::initXML();
62
48
    SDL_Init(SDL_INIT_VIDEO);
63

192
    VirtFs::mountDirSilent("data", Append_false);
64

192
    VirtFs::mountDirSilent("../data", Append_false);
65

192
    VirtFs::mountDirSilent("data/test", Append_false);
66

192
    VirtFs::mountDirSilent("../data/test", Append_false);
67
68
48
    mainGraphics = new SDLGraphics;
69
96
    imageHelper = new SDLImageHelper();
70
71
48
    Dirs::initRootDir();
72
48
    Dirs::initHomeDir();
73
74
48
    ConfigManager::initConfiguration();
75
48
    setConfigDefaults2(config);
76
48
    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
48
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
85
#endif  // USE_SDL2
86
87
48
    theme = new Theme;
88
48
    Theme::selectSkin();
89
90
48
    ActorSprite::load();
91
48
    gui = new Gui();
92
48
    gui->postInit(mainGraphics);
93
48
    setPathsDefaults(paths);
94
48
    PaletteDB::load();
95
96



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



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



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



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



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



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



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

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



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



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



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



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



8
        REQUIRE(palette.mColors[0].value[3] == 0x77);
394
    }
395
48
    delete2(client);
396

192
    VirtFs::unmountDirSilent("data");
397

192
    VirtFs::unmountDirSilent("../data");
398

192
    VirtFs::unmountDirSilent("data/test");
399

192
    VirtFs::unmountDirSilent("../data/test");
400

54
}