GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/map/maplayer/gettiledrawwidth.cc Lines: 175 175 100.0 %
Date: 2018-09-20 Branches: 594 1500 39.6 %

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



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

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




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



4
        REQUIRE(width == 32);
61



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



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

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




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



4
        REQUIRE(width == 32);
79



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



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

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




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



4
        REQUIRE(width == 32);
98



4
        REQUIRE(nextTile == 0);
99
100




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



4
        REQUIRE(width == 32);
105



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



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

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




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



4
        REQUIRE(width == 64);
124



4
        REQUIRE(nextTile == 1);
125
126




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



4
        REQUIRE(width == 32);
131



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



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

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




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



4
        REQUIRE(width == 32);
150



4
        REQUIRE(nextTile == 1);
151
152




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



4
        REQUIRE(width == 32);
157



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



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

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




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



4
        REQUIRE(width == 64);
176



4
        REQUIRE(nextTile == 2);
177
178




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



4
        REQUIRE(width == 32);
183



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



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

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




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



4
        REQUIRE(width == 64);
203



4
        REQUIRE(nextTile == 1);
204
205




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



4
        REQUIRE(width == 32);
210



4
        REQUIRE(nextTile == 0);
211
212




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



4
        REQUIRE(width == 32);
217



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



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

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




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



4
        REQUIRE(width == 32);
238



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




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



4
        REQUIRE(width == 32);
252



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



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

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




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



4
        REQUIRE(width == 32);
280



4
        REQUIRE(nextTile == 0);
281
282




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



4
        REQUIRE(width == 32);
287



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



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

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




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



4
        REQUIRE(width == 96);
322



4
        REQUIRE(nextTile == 2);
323
324




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



4
        REQUIRE(width == 64);
329



4
        REQUIRE(nextTile == 1);
330
331




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



4
        REQUIRE(width == 32);
336



4
        REQUIRE(nextTile == 0);
337
338




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



4
        REQUIRE(width == 32);
343



4
        REQUIRE(nextTile == 1);
344
345




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



4
        REQUIRE(width == 32);
350



4
        REQUIRE(nextTile == 2);
351
352




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



4
        REQUIRE(width == 64);
357



4
        REQUIRE(nextTile == 1);
358
359




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



4
        REQUIRE(width == 32);
364



4
        REQUIRE(nextTile == 0);
365
366




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



4
        REQUIRE(width == 32);
371



4
        REQUIRE(nextTile == 3);
372
373




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



4
        REQUIRE(width == 96);
378



4
        REQUIRE(nextTile == 84);
379
380




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


3
        REQUIRE(width == 64);
385



4
        REQUIRE(nextTile == 83);
386
387




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



4
        REQUIRE(width == 32);
392



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

13
}