GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/map/maplayer/getemptytiledrawwidth.cc Lines: 71 71 100.0 %
Date: 2017-11-29 Branches: 179 430 41.6 %

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
12
TEST_CASE("MapLayer getEmptyTileDrawWidth", "")
33
{
34
8
    Dirs::initRootDir();
35
8
    Dirs::initHomeDir();
36
37
8
    ConfigManager::initConfiguration();
38
39
8
    Image *const img1 = new Image(32, 32);
40
8
    Image *const img2 = new Image(32, 32);
41
8
    Image *const img3 = new Image(32, 32);
42
8
    MapLayer *layer = nullptr;
43
    int nextTile;
44
45



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

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




8
        REQUIRE(layer->getEmptyTileDrawWidth(tiles + 1,
56
            1,
57
            nextTile) == 0);
58



8
        REQUIRE(nextTile == 0);
59
    }
60
61



56
    SECTION("simple 4")
62
    {
63
10
        layer = new MapLayer("test",
64
            0, 0,
65
            3, 1,
66
            false,
67
            0,
68

2
            0);
69
2
        layer->setTile(0, 0, img1);
70
2
        layer->setTile(2, 0, img1);
71
2
        TileInfo *const tiles = layer->getTiles();
72




8
        REQUIRE(layer->getEmptyTileDrawWidth(tiles + 1,
73
            2,
74
            nextTile) == 0);
75



8
        REQUIRE(nextTile == 0);
76
    }
77
78



56
    SECTION("simple 5")
79
    {
80
10
        layer = new MapLayer("test",
81
            0, 0,
82
            3, 1,
83
            false,
84
            0,
85

2
            0);
86
2
        layer->setTile(0, 0, img1);
87
2
        layer->setTile(1, 0, img1);
88
2
        TileInfo *const tiles = layer->getTiles();
89




8
        REQUIRE(layer->getEmptyTileDrawWidth(tiles + 2,
90
            1,
91
            nextTile) == 0);
92



8
        REQUIRE(nextTile == 0);
93
    }
94
95



56
    SECTION("normal 1")
96
    {
97
10
        layer = new MapLayer("test",
98
            0, 0,
99
            100, 100,
100
            false,
101
            0,
102

2
            0);
103
2
        layer->setTile(1, 10, img1);
104
2
        layer->setTile(2, 10, img1);
105
2
        layer->setTile(3, 10, img1);
106
2
        layer->setTile(4, 10, img2);
107
2
        layer->setTile(5, 10, nullptr);
108
2
        layer->setTile(6, 10, img2);
109
2
        layer->setTile(7, 10, nullptr);
110
2
        layer->setTile(8, 10, nullptr);
111
2
        layer->setTile(9, 10, img2);
112
2
        layer->setTile(10, 10, img2);
113
2
        layer->setTile(11, 10, img3);
114
2
        layer->setTile(12, 10, nullptr);
115
2
        layer->setTile(13, 10, nullptr);
116
2
        layer->setTile(14, 10, nullptr);
117
2
        layer->setTile(15, 10, img1);
118
2
        layer->setTile(16, 10, img1);
119
2
        layer->setTile(17, 10, img1);
120
2
        TileInfo *const tiles = layer->getTiles();
121
122




8
        REQUIRE(layer->getEmptyTileDrawWidth(tiles + 10 * 100 + 0,
123
            100 - 0,
124
            nextTile) == 0);
125



8
        REQUIRE(nextTile == 0);
126
127




8
        REQUIRE(layer->getEmptyTileDrawWidth(tiles + 10 * 100 + 5,
128
            100 - 5,
129
            nextTile) == 0);
130



8
        REQUIRE(nextTile == 0);
131
132




8
        REQUIRE(layer->getEmptyTileDrawWidth(tiles + 10 * 100 + 7,
133
            100 - 7,
134
            nextTile) == 1);
135



8
        REQUIRE(nextTile == 1);
136
137




8
        REQUIRE(layer->getEmptyTileDrawWidth(tiles + 10 * 100 + 8,
138
            100 - 8,
139
            nextTile) == 0);
140



8
        REQUIRE(nextTile == 0);
141
142




8
        REQUIRE(layer->getEmptyTileDrawWidth(tiles + 10 * 100 + 12,
143
            100 - 12,
144
            nextTile) == 2);
145



8
        REQUIRE(nextTile == 2);
146
147




8
        REQUIRE(layer->getEmptyTileDrawWidth(tiles + 10 * 100 + 13,
148
            100 - 13,
149
            nextTile) == 1);
150



8
        REQUIRE(nextTile == 1);
151
152




8
        REQUIRE(layer->getEmptyTileDrawWidth(tiles + 10 * 100 + 14,
153
            100 - 14,
154
            nextTile) == 0);
155



8
        REQUIRE(nextTile == 0);
156
    }
157
158
8
    delete layer;
159
8
    delete img1;
160
8
    delete img2;
161
8
    delete img3;
162

14
}