GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/map/maplayer/drawfringesimple.cc Lines: 286 286 100.0 %
Date: 2018-07-14 Branches: 849 2214 38.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2016-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 "configmanager.h"
24
#include "configuration.h"
25
#include "dirs.h"
26
#include "graphicsmanager.h"
27
28
#include "being/localplayer.h"
29
30
#include "fs/virtfs/fs.h"
31
32
#include "gui/theme.h"
33
34
#include "unittests/render/mockgraphics.h"
35
36
#include "utils/delete2.h"
37
#include "utils/env.h"
38
39
#include "resources/resourcemanager/resourcemanager.h"
40
41
#include "resources/sdlimagehelper.h"
42
43
#include "resources/image/image.h"
44
45
#include "resources/map/map.h"
46
#include "resources/map/maplayer.h"
47
48
#include "debug.h"
49
50
10
TEST_CASE("MapLayer drawFringe simple", "")
51
{
52
8
    setEnv("SDL_VIDEODRIVER", "dummy");
53
54
24
    VirtFs::mountDirSilent("data", Append_false);
55
24
    VirtFs::mountDirSilent("../data", Append_false);
56
57
16
    imageHelper = new SDLImageHelper;
58
59
8
    Dirs::initRootDir();
60
8
    Dirs::initHomeDir();
61
62
8
    setBrandingDefaults(branding);
63
8
    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
8
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
72
#endif  // USE_SDL2
73
74
8
    theme = new Theme;
75
8
    Theme::selectSkin();
76
77
8
    localPlayer = new LocalPlayer(static_cast<BeingId>(1),
78
8
        BeingTypeId_zero);
79
80
8
    Image *const img1 = new Image(32, 32);
81
8
    Image *const img2 = new Image(32, 32);
82
8
    Image *const img3 = new Image(32, 32);
83
8
    Map *map = nullptr;
84
8
    MapLayer *layer = nullptr;
85
8
    MockGraphics *const mock = new MockGraphics;
86
16
    const Actors actors;
87
88



56
    SECTION("simple 1")
89
    {
90
1
        map = new Map("map",
91
            1, 1,
92

3
            32, 32);
93
1
        layer = new MapLayer("test",
94
            0, 0,
95
            1, 1,
96
            true,
97
            0,
98

3
            0);
99
1
        layer->setTile(0, 0, img1);
100
1
        map->addLayer(layer);
101
2
        layer->setSpecialLayer(map->getSpecialLayer());
102
2
        layer->setTempLayer(map->getTempLayer());
103
1
        layer->updateCache(1, 1);
104
105
        layer->drawFringe(mock,
106
            0, 0,
107
            1, 1,
108
            0, 0,
109
1
            actors);
110



5
        REQUIRE(mock->mDraws.size() == 1);
111



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
112



4
        REQUIRE(mock->mDraws[0].x == 0);
113



4
        REQUIRE(mock->mDraws[0].y == 0);
114



4
        REQUIRE(mock->mDraws[0].image == img1);
115
116
2
        mock->mDraws.clear();
117
        layer->drawFringe(mock,
118
            0, 0,
119
            1, 1,
120
            10, 5,
121
1
            actors);
122



5
        REQUIRE(mock->mDraws.size() == 1);
123



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
124



4
        REQUIRE(mock->mDraws[0].x == -10);
125



4
        REQUIRE(mock->mDraws[0].y == -5);
126



4
        REQUIRE(mock->mDraws[0].image == img1);
127
128
2
        mock->mDraws.clear();
129
        layer->drawFringe(mock,
130
            0, 0,
131
            1, 1,
132
            -10, -5,
133
1
            actors);
134



5
        REQUIRE(mock->mDraws.size() == 1);
135



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
136



4
        REQUIRE(mock->mDraws[0].x == 10);
137



4
        REQUIRE(mock->mDraws[0].y == 5);
138



4
        REQUIRE(mock->mDraws[0].image == img1);
139
    }
140
141



56
    SECTION("simple 2")
142
    {
143
1
        map = new Map("map",
144
            2, 1,
145

3
            32, 32);
146
1
        layer = new MapLayer("test",
147
            0, 0,
148
            2, 1,
149
            true,
150
            0,
151

3
            0);
152
1
        layer->setTile(0, 0, img1);
153
1
        map->addLayer(layer);
154
2
        layer->setSpecialLayer(map->getSpecialLayer());
155
2
        layer->setTempLayer(map->getTempLayer());
156
1
        layer->updateCache(2, 1);
157
158
        layer->drawFringe(mock,
159
            0, 0,
160
            2, 1,
161
            0, 0,
162
1
            actors);
163
164



5
        REQUIRE(mock->mDraws.size() == 1);
165



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
166



4
        REQUIRE(mock->mDraws[0].x == 0);
167



4
        REQUIRE(mock->mDraws[0].y == 0);
168



4
        REQUIRE(mock->mDraws[0].image == img1);
169
170
2
        mock->mDraws.clear();
171
        layer->drawFringe(mock,
172
            0, 0,
173
            2, 1,
174
            10, 5,
175
1
            actors);
176



5
        REQUIRE(mock->mDraws.size() == 1);
177



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
178



4
        REQUIRE(mock->mDraws[0].x == -10);
179



4
        REQUIRE(mock->mDraws[0].y == -5);
180



4
        REQUIRE(mock->mDraws[0].image == img1);
181
182
2
        mock->mDraws.clear();
183
        layer->drawFringe(mock,
184
            0, 0,
185
            2, 1,
186
            -10, -5,
187
1
            actors);
188



5
        REQUIRE(mock->mDraws.size() == 1);
189



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
190



4
        REQUIRE(mock->mDraws[0].x == 10);
191



4
        REQUIRE(mock->mDraws[0].y == 5);
192



4
        REQUIRE(mock->mDraws[0].image == img1);
193
    }
194
195



56
    SECTION("simple 3")
196
    {
197
1
        map = new Map("map",
198
            2, 1,
199

3
            32, 32);
200
1
        layer = new MapLayer("test",
201
            0, 0,
202
            2, 1,
203
            true,
204
            0,
205

3
            0);
206
1
        layer->setTile(0, 0, img1);
207
1
        layer->setTile(1, 0, img2);
208
1
        map->addLayer(layer);
209
2
        layer->setSpecialLayer(map->getSpecialLayer());
210
2
        layer->setTempLayer(map->getTempLayer());
211
1
        layer->updateCache(2, 1);
212
213
        layer->drawFringe(mock,
214
            0, 0,
215
            2, 1,
216
            0, 0,
217
1
            actors);
218



5
        REQUIRE(mock->mDraws.size() == 2);
219



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
220



4
        REQUIRE(mock->mDraws[0].x == 0);
221



4
        REQUIRE(mock->mDraws[0].y == 0);
222



4
        REQUIRE(mock->mDraws[0].image == img1);
223



4
        REQUIRE(mock->mDraws[1].drawType == MockDrawType::DrawImage);
224



4
        REQUIRE(mock->mDraws[1].x == 32);
225



4
        REQUIRE(mock->mDraws[1].y == 0);
226



4
        REQUIRE(mock->mDraws[1].image == img2);
227
228
2
        mock->mDraws.clear();
229
        layer->drawFringe(mock,
230
            0, 0,
231
            2, 1,
232
            -10, -20,
233
1
            actors);
234



5
        REQUIRE(mock->mDraws.size() == 2);
235



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
236



4
        REQUIRE(mock->mDraws[0].x == 10);
237



4
        REQUIRE(mock->mDraws[0].y == 20);
238



4
        REQUIRE(mock->mDraws[0].image == img1);
239



4
        REQUIRE(mock->mDraws[1].drawType == MockDrawType::DrawImage);
240



4
        REQUIRE(mock->mDraws[1].x == 42);
241



4
        REQUIRE(mock->mDraws[1].y == 20);
242



4
        REQUIRE(mock->mDraws[1].image == img2);
243
    }
244
245



56
    SECTION("simple 4")
246
    {
247
1
        map = new Map("map",
248
            2, 1,
249

3
            32, 32);
250
1
        layer = new MapLayer("test",
251
            0, 0,
252
            2, 1,
253
            true,
254
            0,
255

3
            0);
256
1
        layer->setTile(0, 0, img1);
257
1
        layer->setTile(1, 0, img1);
258
1
        map->addLayer(layer);
259
2
        layer->setSpecialLayer(map->getSpecialLayer());
260
2
        layer->setTempLayer(map->getTempLayer());
261
1
        layer->updateCache(2, 1);
262
263
        layer->drawFringe(mock,
264
            0, 0,
265
            2, 1,
266
            0, 0,
267
1
            actors);
268



5
        REQUIRE(mock->mDraws.size() == 1);
269



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawPattern);
270



4
        REQUIRE(mock->mDraws[0].x == 0);
271



4
        REQUIRE(mock->mDraws[0].y == 0);
272



4
        REQUIRE(mock->mDraws[0].width == 64);
273



4
        REQUIRE(mock->mDraws[0].height == 32);
274



4
        REQUIRE(mock->mDraws[0].image == img1);
275
276
2
        mock->mDraws.clear();
277
        layer->drawFringe(mock,
278
            0, 0,
279
            2, 1,
280
            -10, 20,
281
1
            actors);
282



5
        REQUIRE(mock->mDraws.size() == 1);
283



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawPattern);
284



4
        REQUIRE(mock->mDraws[0].x == 10);
285



4
        REQUIRE(mock->mDraws[0].y == -20);
286



4
        REQUIRE(mock->mDraws[0].width == 64);
287



4
        REQUIRE(mock->mDraws[0].height == 32);
288



4
        REQUIRE(mock->mDraws[0].image == img1);
289
    }
290
291



56
    SECTION("simple 4.2")
292
    {
293
1
        map = new Map("map",
294
            3, 1,
295

3
            32, 32);
296
1
        layer = new MapLayer("test",
297
            0, 0,
298
            3, 1,
299
            true,
300
            0,
301

3
            0);
302
1
        layer->setTile(0, 0, img1);
303
1
        layer->setTile(2, 0, img1);
304
1
        map->addLayer(layer);
305
2
        layer->setSpecialLayer(map->getSpecialLayer());
306
2
        layer->setTempLayer(map->getTempLayer());
307
1
        layer->updateCache(3, 1);
308
309
        layer->drawFringe(mock,
310
            0, 0,
311
            3, 1,
312
            0, 0,
313
1
            actors);
314



5
        REQUIRE(mock->mDraws.size() == 2);
315



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
316



4
        REQUIRE(mock->mDraws[0].x == 0);
317



4
        REQUIRE(mock->mDraws[0].y == 0);
318



4
        REQUIRE(mock->mDraws[0].image == img1);
319



4
        REQUIRE(mock->mDraws[1].drawType == MockDrawType::DrawImage);
320



4
        REQUIRE(mock->mDraws[1].x == 64);
321



4
        REQUIRE(mock->mDraws[1].y == 0);
322



4
        REQUIRE(mock->mDraws[1].image == img1);
323
324
2
        mock->mDraws.clear();
325
        layer->drawFringe(mock,
326
            0, 0,
327
            3, 1,
328
            10, -20,
329
1
            actors);
330



5
        REQUIRE(mock->mDraws.size() == 2);
331



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
332



4
        REQUIRE(mock->mDraws[0].x == -10);
333



4
        REQUIRE(mock->mDraws[0].y == 20);
334



4
        REQUIRE(mock->mDraws[0].image == img1);
335



4
        REQUIRE(mock->mDraws[1].drawType == MockDrawType::DrawImage);
336



4
        REQUIRE(mock->mDraws[1].x == 54);
337



4
        REQUIRE(mock->mDraws[1].y == 20);
338



4
        REQUIRE(mock->mDraws[1].image == img1);
339
    }
340
341



56
    SECTION("simple 5")
342
    {
343
1
        map = new Map("map",
344
            3, 1,
345

3
            32, 32);
346
1
        layer = new MapLayer("test",
347
            0, 0,
348
            3, 1,
349
            true,
350
            0,
351

3
            0);
352
1
        layer->setTile(0, 0, img1);
353
1
        layer->setTile(1, 0, img1);
354
1
        map->addLayer(layer);
355
2
        layer->setSpecialLayer(map->getSpecialLayer());
356
2
        layer->setTempLayer(map->getTempLayer());
357
1
        layer->updateCache(3, 1);
358
359
        layer->drawFringe(mock,
360
            0, 0,
361
            3, 1,
362
            0, 0,
363
1
            actors);
364



5
        REQUIRE(mock->mDraws.size() == 1);
365



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawPattern);
366



4
        REQUIRE(mock->mDraws[0].x == 0);
367



4
        REQUIRE(mock->mDraws[0].y == 0);
368



4
        REQUIRE(mock->mDraws[0].width == 64);
369



4
        REQUIRE(mock->mDraws[0].height == 32);
370



4
        REQUIRE(mock->mDraws[0].image == img1);
371
372
2
        mock->mDraws.clear();
373
        layer->drawFringe(mock,
374
            0, 0,
375
            3, 1,
376
            -10, 20,
377
1
            actors);
378



5
        REQUIRE(mock->mDraws.size() == 1);
379



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawPattern);
380



4
        REQUIRE(mock->mDraws[0].x == 10);
381



4
        REQUIRE(mock->mDraws[0].y == -20);
382



4
        REQUIRE(mock->mDraws[0].width == 64);
383



4
        REQUIRE(mock->mDraws[0].height == 32);
384


3
        REQUIRE(mock->mDraws[0].image == img1);
385
    }
386
387



56
    SECTION("simple 6")
388
    {
389
1
        map = new Map("map",
390
            3, 1,
391

3
            32, 32);
392
1
        layer = new MapLayer("test",
393
            0, 0,
394
            3, 1,
395
            true,
396
            0,
397

3
            0);
398
1
        layer->setTile(0, 0, img1);
399
1
        layer->setTile(1, 0, img1);
400
1
        layer->setTile(2, 0, img2);
401
1
        map->addLayer(layer);
402
2
        layer->setSpecialLayer(map->getSpecialLayer());
403
2
        layer->setTempLayer(map->getTempLayer());
404
1
        layer->updateCache(3, 1);
405
406
        layer->drawFringe(mock,
407
            0, 0,
408
            3, 1,
409
            0, 0,
410
1
            actors);
411



5
        REQUIRE(mock->mDraws.size() == 2);
412



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawPattern);
413



4
        REQUIRE(mock->mDraws[0].x == 0);
414



4
        REQUIRE(mock->mDraws[0].y == 0);
415



4
        REQUIRE(mock->mDraws[0].width == 64);
416



4
        REQUIRE(mock->mDraws[0].height == 32);
417



4
        REQUIRE(mock->mDraws[0].image == img1);
418



4
        REQUIRE(mock->mDraws[1].drawType == MockDrawType::DrawImage);
419



4
        REQUIRE(mock->mDraws[1].x == 64);
420



4
        REQUIRE(mock->mDraws[1].y == 0);
421



4
        REQUIRE(mock->mDraws[1].image == img2);
422
423
2
        mock->mDraws.clear();
424
        layer->drawFringe(mock,
425
            0, 0,
426
            3, 1,
427
            -10, 20,
428
1
            actors);
429



5
        REQUIRE(mock->mDraws.size() == 2);
430



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawPattern);
431



4
        REQUIRE(mock->mDraws[0].x == 10);
432



4
        REQUIRE(mock->mDraws[0].y == -20);
433



4
        REQUIRE(mock->mDraws[0].width == 64);
434



4
        REQUIRE(mock->mDraws[0].height == 32);
435



4
        REQUIRE(mock->mDraws[0].image == img1);
436



4
        REQUIRE(mock->mDraws[1].drawType == MockDrawType::DrawImage);
437



4
        REQUIRE(mock->mDraws[1].x == 74);
438



4
        REQUIRE(mock->mDraws[1].y == -20);
439



4
        REQUIRE(mock->mDraws[1].image == img2);
440
    }
441
442



56
    SECTION("simple 7")
443
    {
444
1
        map = new Map("map",
445
            3, 1,
446

3
            32, 32);
447
1
        layer = new MapLayer("test",
448
            0, 0,
449
            3, 1,
450
            true,
451
            0,
452

3
            0);
453
1
        layer->setTile(0, 0, img1);
454
1
        layer->setTile(1, 0, img1);
455
1
        layer->setTile(2, 0, img2);
456
1
        map->addLayer(layer);
457
2
        layer->setSpecialLayer(map->getSpecialLayer());
458
2
        layer->setTempLayer(map->getTempLayer());
459
1
        TileInfo *const tiles = layer->getTiles();
460
1
        tiles[0].isEnabled = false;
461
1
        layer->updateCache(3, 1);
462
463
        layer->drawFringe(mock,
464
            0, 0,
465
            3, 1,
466
            0, 0,
467
1
            actors);
468



5
        REQUIRE(mock->mDraws.size() == 2);
469



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
470



4
        REQUIRE(mock->mDraws[0].x == 32);
471



4
        REQUIRE(mock->mDraws[0].y == 0);
472



4
        REQUIRE(mock->mDraws[0].image == img1);
473



4
        REQUIRE(mock->mDraws[1].drawType == MockDrawType::DrawImage);
474



4
        REQUIRE(mock->mDraws[1].x == 64);
475



4
        REQUIRE(mock->mDraws[1].y == 0);
476



4
        REQUIRE(mock->mDraws[1].image == img2);
477
478
2
        mock->mDraws.clear();
479
        layer->drawFringe(mock,
480
            0, 0,
481
            3, 1,
482
            -10, 20,
483
1
            actors);
484



5
        REQUIRE(mock->mDraws.size() == 2);
485



4
        REQUIRE(mock->mDraws[0].drawType == MockDrawType::DrawImage);
486



4
        REQUIRE(mock->mDraws[0].x == 42);
487



4
        REQUIRE(mock->mDraws[0].y == -20);
488



4
        REQUIRE(mock->mDraws[0].image == img1);
489



4
        REQUIRE(mock->mDraws[1].drawType == MockDrawType::DrawImage);
490



4
        REQUIRE(mock->mDraws[1].x == 74);
491



4
        REQUIRE(mock->mDraws[1].y == -20);
492



4
        REQUIRE(mock->mDraws[1].image == img2);
493
    }
494
495
8
    delete2(localPlayer);
496
8
    delete map;
497
8
    delete img1;
498
8
    delete img2;
499
8
    delete img3;
500
8
    delete mock;
501
8
    delete2(theme);
502
8
    GraphicsManager::deleteRenderers();
503
8
    ResourceManager::cleanOrphans(true);
504
8
    ResourceManager::deleteInstance();
505

24
    VirtFs::unmountDirSilent("data");
506

32
    VirtFs::unmountDirSilent("../data");
507

11
}