GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/map/maplayer/gettiledrawwidth.cc Lines: 175 175 100.0 %
Date: 2017-11-29 Branches: 591 1498 39.5 %

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



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

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




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



8
        REQUIRE(width == 32);
61



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



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

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




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



8
        REQUIRE(width == 32);
79



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



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

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




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



8
        REQUIRE(width == 32);
98



8
        REQUIRE(nextTile == 0);
99
100




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



8
        REQUIRE(width == 32);
105



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



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

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




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



8
        REQUIRE(width == 64);
124



8
        REQUIRE(nextTile == 1);
125
126




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



8
        REQUIRE(width == 32);
131



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



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

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




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



8
        REQUIRE(width == 32);
150



8
        REQUIRE(nextTile == 1);
151
152




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



8
        REQUIRE(width == 32);
157



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



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

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




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



8
        REQUIRE(width == 64);
176



8
        REQUIRE(nextTile == 2);
177
178




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



8
        REQUIRE(width == 32);
183



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



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

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




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



8
        REQUIRE(width == 64);
203



8
        REQUIRE(nextTile == 1);
204
205




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



8
        REQUIRE(width == 32);
210



8
        REQUIRE(nextTile == 0);
211
212




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



8
        REQUIRE(width == 32);
217



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



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

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




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



8
        REQUIRE(width == 32);
238



8
        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




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



8
        REQUIRE(width == 32);
252



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



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

2
            0);
263
2
        layer->setTile(0, 0, img1);
264
2
        layer->setTile(1, 0, img1);
265
2
        layer->setTile(2, 0, img2);
266
2
        TileInfo *const tiles = layer->getTiles();
267
2
        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




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



8
        REQUIRE(width == 32);
280



8
        REQUIRE(nextTile == 0);
281
282




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



8
        REQUIRE(width == 32);
287



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



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

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




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



8
        REQUIRE(width == 96);
322



8
        REQUIRE(nextTile == 2);
323
324




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



8
        REQUIRE(width == 64);
329



8
        REQUIRE(nextTile == 1);
330
331




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



8
        REQUIRE(width == 32);
336



8
        REQUIRE(nextTile == 0);
337
338




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



8
        REQUIRE(width == 32);
343



8
        REQUIRE(nextTile == 1);
344
345




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



8
        REQUIRE(width == 32);
350



8
        REQUIRE(nextTile == 2);
351
352




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



8
        REQUIRE(width == 64);
357



8
        REQUIRE(nextTile == 1);
358
359




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



8
        REQUIRE(width == 32);
364



8
        REQUIRE(nextTile == 0);
365
366




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



8
        REQUIRE(width == 32);
371



8
        REQUIRE(nextTile == 3);
372
373




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



8
        REQUIRE(width == 96);
378



8
        REQUIRE(nextTile == 84);
379
380




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



6
        REQUIRE(width == 64);
385



8
        REQUIRE(nextTile == 83);
386
387




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



8
        REQUIRE(width == 32);
392



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

26
}