forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutators_stack_unittests.cc
262 lines (230 loc) · 7.21 KB
/
mutators_stack_unittests.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/flow/embedded_views.h"
#include "gtest/gtest.h"
namespace flutter {
namespace testing {
TEST(MutatorsStack, Initialization) {
MutatorsStack stack;
ASSERT_TRUE(true);
}
TEST(MutatorsStack, CopyConstructor) {
MutatorsStack stack;
auto rrect = SkRRect::MakeEmpty();
auto rect = SkRect::MakeEmpty();
stack.PushClipRect(rect);
stack.PushClipRRect(rrect);
MutatorsStack copy = MutatorsStack(stack);
ASSERT_TRUE(copy == stack);
}
TEST(MutatorsStack, CopyAndUpdateTheCopy) {
MutatorsStack stack;
auto rrect = SkRRect::MakeEmpty();
auto rect = SkRect::MakeEmpty();
stack.PushClipRect(rect);
stack.PushClipRRect(rrect);
MutatorsStack copy = MutatorsStack(stack);
copy.Pop();
copy.Pop();
ASSERT_TRUE(copy != stack);
ASSERT_TRUE(copy.is_empty());
ASSERT_TRUE(!stack.is_empty());
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rrect);
ASSERT_TRUE(iter->get()->GetRRect() == rrect);
++iter;
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rect);
ASSERT_TRUE(iter->get()->GetRect() == rect);
}
TEST(MutatorsStack, PushClipRect) {
MutatorsStack stack;
auto rect = SkRect::MakeEmpty();
stack.PushClipRect(rect);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rect);
ASSERT_TRUE(iter->get()->GetRect() == rect);
}
TEST(MutatorsStack, PushClipRRect) {
MutatorsStack stack;
auto rrect = SkRRect::MakeEmpty();
stack.PushClipRRect(rrect);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rrect);
ASSERT_TRUE(iter->get()->GetRRect() == rrect);
}
TEST(MutatorsStack, PushClipPath) {
MutatorsStack stack;
SkPath path;
stack.PushClipPath(path);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == flutter::MutatorType::clip_path);
ASSERT_TRUE(iter->get()->GetPath() == path);
}
TEST(MutatorsStack, PushTransform) {
MutatorsStack stack;
SkMatrix matrix;
matrix.setIdentity();
stack.PushTransform(matrix);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::transform);
ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
}
TEST(MutatorsStack, PushOpacity) {
MutatorsStack stack;
int alpha = 240;
stack.PushOpacity(alpha);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::opacity);
ASSERT_TRUE(iter->get()->GetAlpha() == 240);
}
TEST(MutatorsStack, Pop) {
MutatorsStack stack;
SkMatrix matrix;
matrix.setIdentity();
stack.PushTransform(matrix);
stack.Pop();
auto iter = stack.Bottom();
ASSERT_TRUE(iter == stack.Top());
}
TEST(MutatorsStack, Traversal) {
MutatorsStack stack;
SkMatrix matrix;
matrix.setIdentity();
stack.PushTransform(matrix);
auto rect = SkRect::MakeEmpty();
stack.PushClipRect(rect);
auto rrect = SkRRect::MakeEmpty();
stack.PushClipRRect(rrect);
auto iter = stack.Bottom();
int index = 0;
while (iter != stack.Top()) {
switch (index) {
case 0:
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rrect);
ASSERT_TRUE(iter->get()->GetRRect() == rrect);
break;
case 1:
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rect);
ASSERT_TRUE(iter->get()->GetRect() == rect);
break;
case 2:
ASSERT_TRUE(iter->get()->GetType() == MutatorType::transform);
ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
break;
default:
break;
}
++iter;
++index;
}
}
TEST(MutatorsStack, Equality) {
MutatorsStack stack;
SkMatrix matrix = SkMatrix::Scale(1, 1);
stack.PushTransform(matrix);
SkRect rect = SkRect::MakeEmpty();
stack.PushClipRect(rect);
SkRRect rrect = SkRRect::MakeEmpty();
stack.PushClipRRect(rrect);
SkPath path;
stack.PushClipPath(path);
int alpha = 240;
stack.PushOpacity(alpha);
MutatorsStack stackOther;
SkMatrix matrixOther = SkMatrix::Scale(1, 1);
stackOther.PushTransform(matrixOther);
SkRect rectOther = SkRect::MakeEmpty();
stackOther.PushClipRect(rectOther);
SkRRect rrectOther = SkRRect::MakeEmpty();
stackOther.PushClipRRect(rrectOther);
SkPath otherPath;
stackOther.PushClipPath(otherPath);
int otherAlpha = 240;
stackOther.PushOpacity(otherAlpha);
ASSERT_TRUE(stack == stackOther);
}
TEST(Mutator, Initialization) {
SkRect rect = SkRect::MakeEmpty();
Mutator mutator = Mutator(rect);
ASSERT_TRUE(mutator.GetType() == MutatorType::clip_rect);
ASSERT_TRUE(mutator.GetRect() == rect);
SkRRect rrect = SkRRect::MakeEmpty();
Mutator mutator2 = Mutator(rrect);
ASSERT_TRUE(mutator2.GetType() == MutatorType::clip_rrect);
ASSERT_TRUE(mutator2.GetRRect() == rrect);
SkPath path;
Mutator mutator3 = Mutator(path);
ASSERT_TRUE(mutator3.GetType() == MutatorType::clip_path);
ASSERT_TRUE(mutator3.GetPath() == path);
SkMatrix matrix;
matrix.setIdentity();
Mutator mutator4 = Mutator(matrix);
ASSERT_TRUE(mutator4.GetType() == MutatorType::transform);
ASSERT_TRUE(mutator4.GetMatrix() == matrix);
int alpha = 240;
Mutator mutator5 = Mutator(alpha);
ASSERT_TRUE(mutator5.GetType() == MutatorType::opacity);
}
TEST(Mutator, CopyConstructor) {
SkRect rect = SkRect::MakeEmpty();
Mutator mutator = Mutator(rect);
Mutator copy = Mutator(mutator);
ASSERT_TRUE(mutator == copy);
SkRRect rrect = SkRRect::MakeEmpty();
Mutator mutator2 = Mutator(rrect);
Mutator copy2 = Mutator(mutator2);
ASSERT_TRUE(mutator2 == copy2);
SkPath path;
Mutator mutator3 = Mutator(path);
Mutator copy3 = Mutator(mutator3);
ASSERT_TRUE(mutator3 == copy3);
SkMatrix matrix;
matrix.setIdentity();
Mutator mutator4 = Mutator(matrix);
Mutator copy4 = Mutator(mutator4);
ASSERT_TRUE(mutator4 == copy4);
int alpha = 240;
Mutator mutator5 = Mutator(alpha);
Mutator copy5 = Mutator(mutator5);
ASSERT_TRUE(mutator5 == copy5);
}
TEST(Mutator, Equality) {
SkMatrix matrix;
matrix.setIdentity();
Mutator mutator = Mutator(matrix);
Mutator otherMutator = Mutator(matrix);
ASSERT_TRUE(mutator == otherMutator);
SkRect rect = SkRect::MakeEmpty();
Mutator mutator2 = Mutator(rect);
Mutator otherMutator2 = Mutator(rect);
ASSERT_TRUE(mutator2 == otherMutator2);
SkRRect rrect = SkRRect::MakeEmpty();
Mutator mutator3 = Mutator(rrect);
Mutator otherMutator3 = Mutator(rrect);
ASSERT_TRUE(mutator3 == otherMutator3);
SkPath path;
flutter::Mutator mutator4 = flutter::Mutator(path);
flutter::Mutator otherMutator4 = flutter::Mutator(path);
ASSERT_TRUE(mutator4 == otherMutator4);
ASSERT_FALSE(mutator2 == mutator);
int alpha = 240;
Mutator mutator5 = Mutator(alpha);
Mutator otherMutator5 = Mutator(alpha);
ASSERT_TRUE(mutator5 == otherMutator5);
}
TEST(Mutator, UnEquality) {
SkRect rect = SkRect::MakeEmpty();
Mutator mutator = Mutator(rect);
SkMatrix matrix;
matrix.setIdentity();
Mutator notEqualMutator = Mutator(matrix);
ASSERT_TRUE(notEqualMutator != mutator);
int alpha = 240;
int alpha2 = 241;
Mutator mutator2 = Mutator(alpha);
Mutator otherMutator2 = Mutator(alpha2);
ASSERT_TRUE(mutator2 != otherMutator2);
}
} // namespace testing
} // namespace flutter