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

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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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

8
}