GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/map/maplayer/gettiledrawwidth.cc Lines: 175 175 100.0 %
Date: 2021-03-17 Branches: 558 1432 39.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2016-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 "configmanager.h"
25
#include "dirs.h"
26
27
#include "resources/image/image.h"
28
29
#include "resources/map/maplayer.h"
30
31
#include "debug.h"
32
33
12
TEST_CASE("MapLayer getTileDrawWidth", "")
34
{
35
10
    Dirs::initRootDir();
36
10
    Dirs::initHomeDir();
37
38
10
    ConfigManager::initConfiguration();
39
40
10
    Image *const img1 = new Image(32, 32);
41
10
    Image *const img2 = new Image(32, 32);
42
10
    Image *const img3 = new Image(32, 32);
43
10
    MapLayer *layer = nullptr;
44
    int width;
45
    int nextTile;
46
47



70
    SECTION("simple 1")
48
    {
49
1
        layer = new MapLayer("test",
50
            0, 0,
51
            1, 1,
52
            false,
53
            0,
54

3
            0);
55
2
        layer->setTile(0, 0, img1);
56
1
        TileInfo *const tiles = layer->getTiles();
57




4
        REQUIRE(layer->getTileDrawWidth(tiles,
58
            1,
59
            width,
60
            nextTile) == 0);
61



4
        REQUIRE(width == 32);
62



4
        REQUIRE(nextTile == 0);
63
    }
64
65



70
    SECTION("simple 2")
66
    {
67
1
        layer = new MapLayer("test",
68
            0, 0,
69
            2, 1,
70
            false,
71
            0,
72

3
            0);
73
2
        layer->setTile(0, 0, img1);
74
1
        TileInfo *const tiles = layer->getTiles();
75




4
        REQUIRE(layer->getTileDrawWidth(tiles,
76
            2,
77
            width,
78
            nextTile) == 0);
79



4
        REQUIRE(width == 32);
80



4
        REQUIRE(nextTile == 1);
81
    }
82
83



70
    SECTION("simple 3")
84
    {
85
1
        layer = new MapLayer("test",
86
            0, 0,
87
            2, 1,
88
            false,
89
            0,
90

3
            0);
91
2
        layer->setTile(0, 0, img1);
92
2
        layer->setTile(1, 0, img2);
93
1
        TileInfo *const tiles = layer->getTiles();
94




4
        REQUIRE(layer->getTileDrawWidth(tiles,
95
            1,
96
            width,
97
            nextTile) == 0);
98



4
        REQUIRE(width == 32);
99



4
        REQUIRE(nextTile == 0);
100
101




4
        REQUIRE(layer->getTileDrawWidth(tiles + 1,
102
            1,
103
            width,
104
            nextTile) == 0);
105



4
        REQUIRE(width == 32);
106



4
        REQUIRE(nextTile == 0);
107
    }
108
109



70
    SECTION("simple 4")
110
    {
111
1
        layer = new MapLayer("test",
112
            0, 0,
113
            2, 1,
114
            false,
115
            0,
116

3
            0);
117
2
        layer->setTile(0, 0, img1);
118
2
        layer->setTile(1, 0, img1);
119
1
        TileInfo *const tiles = layer->getTiles();
120




4
        REQUIRE(layer->getTileDrawWidth(tiles,
121
            2,
122
            width,
123
            nextTile) == 1);
124



4
        REQUIRE(width == 64);
125



4
        REQUIRE(nextTile == 1);
126
127




4
        REQUIRE(layer->getTileDrawWidth(tiles + 1,
128
            1,
129
            width,
130
            nextTile) == 0);
131



4
        REQUIRE(width == 32);
132



4
        REQUIRE(nextTile == 0);
133
    }
134
135



70
    SECTION("simple 4.2")
136
    {
137
1
        layer = new MapLayer("test",
138
            0, 0,
139
            3, 1,
140
            false,
141
            0,
142

3
            0);
143
2
        layer->setTile(0, 0, img1);
144
2
        layer->setTile(2, 0, img1);
145
1
        TileInfo *const tiles = layer->getTiles();
146




4
        REQUIRE(layer->getTileDrawWidth(tiles,
147
            3,
148
            width,
149
            nextTile) == 0);
150



4
        REQUIRE(width == 32);
151



4
        REQUIRE(nextTile == 1);
152
153




4
        REQUIRE(layer->getTileDrawWidth(tiles + 2,
154
            1,
155
            width,
156
            nextTile) == 0);
157



4
        REQUIRE(width == 32);
158



4
        REQUIRE(nextTile == 0);
159
    }
160
161



70
    SECTION("simple 5")
162
    {
163
1
        layer = new MapLayer("test",
164
            0, 0,
165
            3, 1,
166
            false,
167
            0,
168

3
            0);
169
2
        layer->setTile(0, 0, img1);
170
2
        layer->setTile(1, 0, img1);
171
1
        TileInfo *const tiles = layer->getTiles();
172




4
        REQUIRE(layer->getTileDrawWidth(tiles,
173
            3,
174
            width,
175
            nextTile) == 1);
176



4
        REQUIRE(width == 64);
177



4
        REQUIRE(nextTile == 2);
178
179




4
        REQUIRE(layer->getTileDrawWidth(tiles + 1,
180
            2,
181
            width,
182
            nextTile) == 0);
183



4
        REQUIRE(width == 32);
184



4
        REQUIRE(nextTile == 1);
185
    }
186
187



70
    SECTION("simple 6")
188
    {
189
1
        layer = new MapLayer("test",
190
            0, 0,
191
            3, 1,
192
            false,
193
            0,
194

3
            0);
195
2
        layer->setTile(0, 0, img1);
196
2
        layer->setTile(1, 0, img1);
197
2
        layer->setTile(2, 0, img2);
198
1
        TileInfo *const tiles = layer->getTiles();
199




4
        REQUIRE(layer->getTileDrawWidth(tiles,
200
            3,
201
            width,
202
            nextTile) == 1);
203



4
        REQUIRE(width == 64);
204



4
        REQUIRE(nextTile == 1);
205
206




4
        REQUIRE(layer->getTileDrawWidth(tiles + 1,
207
            2,
208
            width,
209
            nextTile) == 0);
210



4
        REQUIRE(width == 32);
211



4
        REQUIRE(nextTile == 0);
212
213




4
        REQUIRE(layer->getTileDrawWidth(tiles + 2,
214
            1,
215
            width,
216
            nextTile) == 0);
217



4
        REQUIRE(width == 32);
218



4
        REQUIRE(nextTile == 0);
219
    }
220
221



70
    SECTION("simple 7")
222
    {
223
1
        layer = new MapLayer("test",
224
            0, 0,
225
            3, 1,
226
            false,
227
            0,
228

3
            0);
229
2
        layer->setTile(0, 0, img1);
230
2
        layer->setTile(1, 0, img1);
231
2
        layer->setTile(2, 0, img2);
232
1
        TileInfo *const tiles = layer->getTiles();
233
1
        tiles[1].isEnabled = false;
234




4
        REQUIRE(layer->getTileDrawWidth(tiles,
235
            3,
236
            width,
237
            nextTile) == 0);
238



4
        REQUIRE(width == 32);
239



4
        REQUIRE(nextTile == 1);
240
241
//        REQUIRE(layer->getTileDrawWidth(tiles + 1,
242
//            2,
243
//            width,
244
//            nextTile) == 0);
245
//        REQUIRE(width == 32);
246
//        REQUIRE(nextTile == 0);
247
248




4
        REQUIRE(layer->getTileDrawWidth(tiles + 2,
249
            1,
250
            width,
251
            nextTile) == 0);
252



4
        REQUIRE(width == 32);
253



4
        REQUIRE(nextTile == 0);
254
    }
255
256



70
    SECTION("simple 8")
257
    {
258
1
        layer = new MapLayer("test",
259
            0, 0,
260
            3, 1,
261
            false,
262
            0,
263

3
            0);
264
2
        layer->setTile(0, 0, img1);
265
2
        layer->setTile(1, 0, img1);
266
2
        layer->setTile(2, 0, img2);
267
1
        TileInfo *const tiles = layer->getTiles();
268
1
        tiles[0].isEnabled = false;
269
//        REQUIRE(layer->getTileDrawWidth(tiles,
270
//            3,
271
//            width,
272
//            nextTile) == 1);
273
//        REQUIRE(width == 0);
274
//        REQUIRE(nextTile == 1);
275
276




4
        REQUIRE(layer->getTileDrawWidth(tiles + 1,
277
            2,
278
            width,
279
            nextTile) == 0);
280



4
        REQUIRE(width == 32);
281



4
        REQUIRE(nextTile == 0);
282
283




4
        REQUIRE(layer->getTileDrawWidth(tiles + 2,
284
            1,
285
            width,
286
            nextTile) == 0);
287



4
        REQUIRE(width == 32);
288



4
        REQUIRE(nextTile == 0);
289
    }
290
291



70
    SECTION("normal 1")
292
    {
293
1
        layer = new MapLayer("test",
294
            0, 0,
295
            100, 100,
296
            false,
297
            0,
298

3
            0);
299
2
        layer->setTile(1, 10, img1);
300
2
        layer->setTile(2, 10, img1);
301
2
        layer->setTile(3, 10, img1);
302
2
        layer->setTile(4, 10, img2);
303
2
        layer->setTile(5, 10, nullptr);
304
2
        layer->setTile(6, 10, img2);
305
2
        layer->setTile(7, 10, nullptr);
306
2
        layer->setTile(8, 10, nullptr);
307
2
        layer->setTile(9, 10, img2);
308
2
        layer->setTile(10, 10, img2);
309
2
        layer->setTile(11, 10, img3);
310
2
        layer->setTile(12, 10, nullptr);
311
2
        layer->setTile(13, 10, nullptr);
312
2
        layer->setTile(14, 10, nullptr);
313
2
        layer->setTile(15, 10, img1);
314
2
        layer->setTile(16, 10, img1);
315
2
        layer->setTile(17, 10, img1);
316
1
        TileInfo *const tiles = layer->getTiles();
317
318




4
        REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 1,
319
            100 - 1,
320
            width,
321
            nextTile) == 2);
322



4
        REQUIRE(width == 96);
323



4
        REQUIRE(nextTile == 2);
324
325




4
        REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 2,
326
            100 - 2,
327
            width,
328
            nextTile) == 1);
329



4
        REQUIRE(width == 64);
330



4
        REQUIRE(nextTile == 1);
331
332




4
        REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 3,
333
            100 - 3,
334
            width,
335
            nextTile) == 0);
336



4
        REQUIRE(width == 32);
337



4
        REQUIRE(nextTile == 0);
338
339




4
        REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 4,
340
            100 - 4,
341
            width,
342
            nextTile) == 0);
343



4
        REQUIRE(width == 32);
344



4
        REQUIRE(nextTile == 1);
345
346




4
        REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 6,
347
            100 - 6,
348
            width,
349
            nextTile) == 0);
350



4
        REQUIRE(width == 32);
351



4
        REQUIRE(nextTile == 2);
352
353




4
        REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 9,
354
            100 - 9,
355
            width,
356
            nextTile) == 1);
357



4
        REQUIRE(width == 64);
358



4
        REQUIRE(nextTile == 1);
359
360




4
        REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 10,
361
            100 - 10,
362
            width,
363
            nextTile) == 0);
364



4
        REQUIRE(width == 32);
365



4
        REQUIRE(nextTile == 0);
366
367




4
        REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 11,
368
            100 - 11,
369
            width,
370
            nextTile) == 0);
371



4
        REQUIRE(width == 32);
372



4
        REQUIRE(nextTile == 3);
373
374




4
        REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 15,
375
            100 - 15,
376
            width,
377
            nextTile) == 2);
378



4
        REQUIRE(width == 96);
379



4
        REQUIRE(nextTile == 84);
380
381




4
        REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 16,
382
            100 - 16,
383
            width,
384
            nextTile) == 1);
385



4
        REQUIRE(width == 64);
386



4
        REQUIRE(nextTile == 83);
387
388




4
        REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 17,
389
            100 - 17,
390
            width,
391
            nextTile) == 0);
392



4
        REQUIRE(width == 32);
393



4
        REQUIRE(nextTile == 82);
394
    }
395
396
10
    delete layer;
397
10
    delete img1;
398
10
    delete img2;
399
10
    delete img3;
400

13
}