GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/mstack.cc Lines: 108 108 100.0 %
Date: 2021-03-17 Branches: 270 748 36.1 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2015-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 "gui/cliprect.h"
25
26
#include "resources/mstack.h"
27
28
#include "debug.h"
29
30
3
TEST_CASE("mstack push 1", "")
31
{
32
2
    MStack<ClipRect> stack(10);
33



4
    REQUIRE(-1 == (stack.mPointer - stack.mStack));
34



4
    REQUIRE(0 == stack.mStack[0].xOffset);
35
36
2
    ClipRect &val1 = stack.push();
37
1
    val1.xOffset = 10;
38
1
    ClipRect &val2 = stack.top();
39



4
    REQUIRE(0 == stack.mPointer - stack.mStack);
40



4
    REQUIRE(10 == val2.xOffset);
41



4
    REQUIRE(10 == stack.mStack[0].xOffset);
42



4
    REQUIRE(0 == stack.mStack[1].xOffset);
43
44
1
    val2.yOffset = 2;
45



4
    REQUIRE(2 == val1.yOffset);
46
1
}
47
48
3
TEST_CASE("mstack push 2", "")
49
{
50
2
    MStack<ClipRect> stack(10);
51
2
    ClipRect &val1 = stack.push();
52
1
    val1.xOffset = 10;
53
1
    const ClipRect &val2 = stack.top();
54



4
    REQUIRE(10 == val2.xOffset);
55



4
    REQUIRE(10 == stack.mStack[0].xOffset);
56
57
1
    val1.yOffset = 2;
58



4
    REQUIRE(2 == val2.yOffset);
59



4
    REQUIRE(2 == stack.mStack[0].yOffset);
60
1
}
61
62
3
TEST_CASE("mstack push 3", "")
63
{
64
2
    MStack<ClipRect> stack(10);
65
2
    ClipRect &val1 = stack.push();
66
1
    val1.xOffset = 10;
67
1
    ClipRect &val2 = stack.top();
68



4
    REQUIRE(10 == val2.xOffset);
69



4
    REQUIRE(10 == stack.mStack[0].xOffset);
70
1
}
71
72
3
TEST_CASE("mstack push 4", "")
73
{
74
2
    MStack<ClipRect> stack(10);
75
2
    ClipRect &val1 = stack.push();
76
1
    val1.xOffset = 10;
77



4
    REQUIRE(10 == val1.xOffset);
78



4
    REQUIRE(10 == stack.mStack[0].xOffset);
79



4
    REQUIRE(0 == stack.mStack[1].xOffset);
80



4
    REQUIRE(0 == stack.mStack[2].xOffset);
81
82
2
    ClipRect &val2 = stack.push();
83
1
    val2.xOffset = 20;
84



4
    REQUIRE(20 == val2.xOffset);
85



4
    REQUIRE(10 == stack.mStack[0].xOffset);
86



4
    REQUIRE(20 == stack.mStack[1].xOffset);
87



4
    REQUIRE(0 == stack.mStack[2].xOffset);
88
89
2
    ClipRect &val3 = stack.push();
90
1
    val3.xOffset = 30;
91



4
    REQUIRE(30 == val3.xOffset);
92



4
    REQUIRE(10 == stack.mStack[0].xOffset);
93



4
    REQUIRE(20 == stack.mStack[1].xOffset);
94



4
    REQUIRE(30 == stack.mStack[2].xOffset);
95
1
}
96
97
3
TEST_CASE("mstack pop 1", "")
98
{
99
2
    MStack<ClipRect> stack(10);
100
2
    ClipRect &val1 = stack.push();
101
1
    val1.xOffset = 10;
102



4
    REQUIRE(10 == stack.mStack[0].xOffset);
103
104
1
    stack.pop();
105



4
    REQUIRE(-1 == stack.mPointer - stack.mStack);
106
1
}
107
108
3
TEST_CASE("mstack pop 2", "")
109
{
110
2
    MStack<ClipRect> stack(10);
111
2
    ClipRect &val1 = stack.push();
112



4
    REQUIRE(0 == stack.mPointer - stack.mStack);
113
114
1
    val1.xOffset = 10;
115



4
    REQUIRE(10 == stack.mStack[0].xOffset);
116
117
2
    ClipRect &val2 = stack.push();
118



4
    REQUIRE(1 == stack.mPointer - stack.mStack);
119
120
1
    val2.xOffset = 20;
121



4
    REQUIRE(10 == stack.mStack[0].xOffset);
122



4
    REQUIRE(20 == stack.mStack[1].xOffset);
123
124
1
    stack.pop();
125



4
    REQUIRE(0 == stack.mPointer - stack.mStack);
126



4
    REQUIRE(10 == stack.mStack[0].xOffset);
127



4
    REQUIRE(20 == stack.mStack[1].xOffset);
128
129
1
    ClipRect &val3 = stack.top();
130



4
    REQUIRE(0 == stack.mPointer - stack.mStack);
131



4
    REQUIRE(10 == val1.xOffset);
132



4
    REQUIRE(20 == val2.xOffset);
133



4
    REQUIRE(10 == val3.xOffset);
134



4
    REQUIRE(10 == stack.mStack[0].xOffset);
135



4
    REQUIRE(20 == stack.mStack[1].xOffset);
136



4
    REQUIRE(0 == stack.mStack[2].xOffset);
137
1
}
138
139
3
TEST_CASE("mstack clear 1", "")
140
{
141
2
    MStack<ClipRect> stack(10);
142



4
    REQUIRE(-1 == stack.mPointer - stack.mStack);
143



4
    REQUIRE(0 == stack.mStack[0].xOffset);
144
145
2
    ClipRect &val1 = stack.push();
146
1
    val1.xOffset = 10;
147
148
1
    stack.clear();
149



4
    REQUIRE(-1 == stack.mPointer - stack.mStack);
150



4
    REQUIRE(10 == stack.mStack[0].xOffset);
151



4
    REQUIRE(0 == stack.mStack[1].xOffset);
152
1
}
153
154
3
TEST_CASE("mstack getpop 1", "")
155
{
156
2
    MStack<ClipRect> stack(10);
157
2
    ClipRect &val1 = stack.push();
158
1
    val1.xOffset = 10;
159



4
    REQUIRE(10 == stack.mStack[0].xOffset);
160



4
    REQUIRE(10 == val1.xOffset);
161
162
2
    ClipRect &val2 = stack.getPop();
163



4
    REQUIRE(-1 == stack.mPointer - stack.mStack);
164



4
    REQUIRE(10 == stack.mStack[0].xOffset);
165



4
    REQUIRE(10 == val2.xOffset);
166

4
}