GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/map/maplayer/drawfringesimple.cc Lines: 286 286 100.0 %
Date: 2017-11-29 Branches: 849 2218 38.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2016-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 "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
20
TEST_CASE("MapLayer drawFringe simple", "")
51
{
52
16
    setEnv("SDL_VIDEODRIVER", "dummy");
53
54

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

64
    VirtFs::mountDirSilent("../data", Append_false);
56
57
32
    imageHelper = new SDLImageHelper;
58
59
16
    Dirs::initRootDir();
60
16
    Dirs::initHomeDir();
61
62
16
    setBrandingDefaults(branding);
63
16
    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
16
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
72
#endif  // USE_SDL2
73
74
16
    theme = new Theme;
75
16
    Theme::selectSkin();
76
77
16
    localPlayer = new LocalPlayer(static_cast<BeingId>(1),
78
16
        BeingTypeId_zero);
79
80
16
    Image *const img1 = new Image(32, 32);
81
16
    Image *const img2 = new Image(32, 32);
82
16
    Image *const img3 = new Image(32, 32);
83
16
    Map *map = nullptr;
84
16
    MapLayer *layer = nullptr;
85
16
    MockGraphics *const mock = new MockGraphics;
86
32
    const Actors actors;
87
88



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

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

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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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

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

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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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

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

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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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

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

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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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

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

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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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

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

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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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

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

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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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

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

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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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

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

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

22
}