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

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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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

4
}