Flutter Engine
 
Loading...
Searching...
No Matches
mutators_stack_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
7#include "gtest/gtest.h"
8
9namespace flutter {
10namespace testing {
11
12TEST(MutatorsStack, Initialization) {
13 MutatorsStack stack;
14 ASSERT_TRUE(true);
15}
16
17TEST(MutatorsStack, CopyConstructor) {
18 MutatorsStack stack;
19 auto rrect = DlRoundRect();
20 auto rect = DlRect();
21 stack.PushClipRect(rect);
22 stack.PushClipRRect(rrect);
23 MutatorsStack copy = MutatorsStack(stack);
24 ASSERT_TRUE(copy == stack);
25}
26
27TEST(MutatorsStack, CopyAndUpdateTheCopy) {
28 MutatorsStack stack;
29 auto rrect = DlRoundRect();
30 auto rect = DlRect();
31 stack.PushClipRect(rect);
32 stack.PushClipRRect(rrect);
33 MutatorsStack copy = MutatorsStack(stack);
34 copy.Pop();
35 copy.Pop();
36 ASSERT_TRUE(copy != stack);
37 ASSERT_TRUE(copy.is_empty());
38 ASSERT_TRUE(!stack.is_empty());
39 auto iter = stack.Bottom();
40 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRRect);
41 ASSERT_TRUE(iter->get()->GetRRect() == rrect);
42 ++iter;
43 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRect);
44 ASSERT_TRUE(iter->get()->GetRect() == rect);
45}
46
47TEST(MutatorsStack, PushClipRect) {
48 MutatorsStack stack;
49 auto rect = DlRect();
50 stack.PushClipRect(rect);
51 auto iter = stack.Bottom();
52 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRect);
53 ASSERT_TRUE(iter->get()->GetRect() == rect);
54}
55
56TEST(MutatorsStack, PushClipRRect) {
57 MutatorsStack stack;
58 auto rrect = DlRoundRect();
59 stack.PushClipRRect(rrect);
60 auto iter = stack.Bottom();
61 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRRect);
62 ASSERT_TRUE(iter->get()->GetRRect() == rrect);
63}
64
65TEST(MutatorsStack, PushClipRSE) {
66 MutatorsStack stack;
67 auto rse = DlRoundSuperellipse();
68 stack.PushClipRSE(rse);
69 auto iter = stack.Bottom();
70 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRSE);
71 ASSERT_TRUE(iter->get()->GetRSE() == rse);
72}
73
74TEST(MutatorsStack, PushClipPath) {
75 MutatorsStack stack;
77 stack.PushClipPath(path);
78 auto iter = stack.Bottom();
79 ASSERT_TRUE(iter->get()->GetType() == flutter::MutatorType::kClipPath);
80 ASSERT_TRUE(iter->get()->GetPath() == path);
81}
82
83TEST(MutatorsStack, PushTransform) {
84 MutatorsStack stack;
85 DlMatrix matrix;
86 stack.PushTransform(matrix);
87 auto iter = stack.Bottom();
88 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kTransform);
89 ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
90}
91
92TEST(MutatorsStack, PushOpacity) {
93 MutatorsStack stack;
94 uint8_t alpha = 240;
95 stack.PushOpacity(alpha);
96 auto iter = stack.Bottom();
97 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kOpacity);
98 ASSERT_TRUE(iter->get()->GetAlpha() == 240);
99}
100
101TEST(MutatorsStack, PushBackdropFilter) {
102 MutatorsStack stack;
103 const int num_of_mutators = 10;
104 for (int i = 0; i < num_of_mutators; i++) {
106 stack.PushBackdropFilter(filter, DlRect::MakeXYWH(i, i, i, i));
107 }
108
109 auto iter = stack.Begin();
110 int i = 0;
111 while (iter != stack.End()) {
112 ASSERT_EQ(iter->get()->GetType(), MutatorType::kBackdropFilter);
113 ASSERT_EQ(iter->get()->GetFilterMutation().GetFilter().asBlur()->sigma_x(),
114 i);
115 ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().GetX(), i);
116 ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().GetY(), i);
117 ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().GetWidth(), i);
118 ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().GetHeight(), i);
119 ++iter;
120 ++i;
121 }
122 ASSERT_EQ(i, num_of_mutators);
123}
124
126 MutatorsStack stack;
127 DlMatrix matrix;
128 stack.PushTransform(matrix);
129 stack.Pop();
130 auto iter = stack.Bottom();
131 ASSERT_TRUE(iter == stack.Top());
132}
133
134TEST(MutatorsStack, Traversal) {
135 MutatorsStack stack;
136 DlMatrix matrix;
137 stack.PushTransform(matrix);
138 auto rect = DlRect();
139 stack.PushClipRect(rect);
140 auto rrect = DlRoundRect();
141 stack.PushClipRRect(rrect);
142 auto iter = stack.Bottom();
143 int index = 0;
144 while (iter != stack.Top()) {
145 switch (index) {
146 case 0:
147 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRRect);
148 ASSERT_TRUE(iter->get()->GetRRect() == rrect);
149 break;
150 case 1:
151 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRect);
152 ASSERT_TRUE(iter->get()->GetRect() == rect);
153 break;
154 case 2:
155 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kTransform);
156 ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
157 break;
158 default:
159 break;
160 }
161 ++iter;
162 ++index;
163 }
164}
165
166TEST(MutatorsStack, Equality) {
167 MutatorsStack stack;
168 DlMatrix matrix = DlMatrix::MakeScale({1, 1, 1});
169 stack.PushTransform(matrix);
170 DlRect rect = DlRect();
171 stack.PushClipRect(rect);
172 DlRoundRect rrect = DlRoundRect();
173 stack.PushClipRRect(rrect);
174 DlPath path;
175 stack.PushClipPath(path);
176 uint8_t alpha = 240;
177 stack.PushOpacity(alpha);
178 auto filter = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp);
179 stack.PushBackdropFilter(filter, DlRect());
180
181 MutatorsStack stack_other;
182 DlMatrix matrix_other = DlMatrix::MakeScale({1, 1, 1});
183 stack_other.PushTransform(matrix_other);
184 DlRect rect_other = DlRect();
185 stack_other.PushClipRect(rect_other);
186 DlRoundRect rrect_other = DlRoundRect();
187 stack_other.PushClipRRect(rrect_other);
188 DlPath other_path;
189 stack_other.PushClipPath(other_path);
190 uint8_t other_alpha = 240;
191 stack_other.PushOpacity(other_alpha);
192 auto other_filter = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp);
193 stack_other.PushBackdropFilter(other_filter, DlRect());
194
195 ASSERT_TRUE(stack == stack_other);
196}
197
198TEST(Mutator, Initialization) {
199 DlRect rect = DlRect();
200 Mutator mutator = Mutator(rect);
201 ASSERT_TRUE(mutator.GetType() == MutatorType::kClipRect);
202 ASSERT_TRUE(mutator.GetRect() == rect);
203
204 DlRoundRect rrect = DlRoundRect();
205 Mutator mutator2 = Mutator(rrect);
206 ASSERT_TRUE(mutator2.GetType() == MutatorType::kClipRRect);
207 ASSERT_TRUE(mutator2.GetRRect() == rrect);
208
210 Mutator mutator2se = Mutator(rse);
211 ASSERT_TRUE(mutator2se.GetType() == MutatorType::kClipRSE);
212 ASSERT_TRUE(mutator2se.GetRSE() == rse);
213
214 DlPath path;
215 Mutator mutator3 = Mutator(path);
216 ASSERT_TRUE(mutator3.GetType() == MutatorType::kClipPath);
217 ASSERT_TRUE(mutator3.GetPath() == path);
218
219 DlMatrix matrix;
220 Mutator mutator4 = Mutator(matrix);
221 ASSERT_TRUE(mutator4.GetType() == MutatorType::kTransform);
222 ASSERT_TRUE(mutator4.GetMatrix() == matrix);
223
224 uint8_t alpha = 240;
225 Mutator mutator5 = Mutator(alpha);
226 ASSERT_TRUE(mutator5.GetType() == MutatorType::kOpacity);
227
228 auto filter = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp);
229 Mutator mutator6 = Mutator(filter, DlRect());
230 ASSERT_TRUE(mutator6.GetType() == MutatorType::kBackdropFilter);
231 ASSERT_TRUE(mutator6.GetFilterMutation().GetFilter() == *filter);
232}
233
234TEST(Mutator, CopyConstructor) {
235 DlRect rect = DlRect();
236 Mutator mutator = Mutator(rect);
237 Mutator copy = Mutator(mutator);
238 ASSERT_TRUE(mutator == copy);
239
240 DlRoundRect rrect = DlRoundRect();
241 Mutator mutator2 = Mutator(rrect);
242 Mutator copy2 = Mutator(mutator2);
243 ASSERT_TRUE(mutator2 == copy2);
244
246 Mutator mutator2se = Mutator(rse);
247 Mutator copy2se = Mutator(mutator2se);
248 ASSERT_TRUE(mutator2se == copy2se);
249
250 DlPath path;
251 Mutator mutator3 = Mutator(path);
252 Mutator copy3 = Mutator(mutator3);
253 ASSERT_TRUE(mutator3 == copy3);
254
255 DlMatrix matrix;
256 Mutator mutator4 = Mutator(matrix);
257 Mutator copy4 = Mutator(mutator4);
258 ASSERT_TRUE(mutator4 == copy4);
259
260 uint8_t alpha = 240;
261 Mutator mutator5 = Mutator(alpha);
262 Mutator copy5 = Mutator(mutator5);
263 ASSERT_TRUE(mutator5 == copy5);
264
265 auto filter = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp);
266 Mutator mutator6 = Mutator(filter, DlRect());
267 Mutator copy6 = Mutator(mutator6);
268 ASSERT_TRUE(mutator6 == copy6);
269}
270
271TEST(Mutator, Equality) {
272 DlMatrix matrix;
273 Mutator mutator = Mutator(matrix);
274 Mutator other_mutator = Mutator(matrix);
275 ASSERT_TRUE(mutator == other_mutator);
276
277 DlRect rect = DlRect();
278 Mutator mutator2 = Mutator(rect);
279 Mutator other_mutator2 = Mutator(rect);
280 ASSERT_TRUE(mutator2 == other_mutator2);
281
282 DlRoundRect rrect = DlRoundRect();
283 Mutator mutator3 = Mutator(rrect);
284 Mutator other_mutator3 = Mutator(rrect);
285 ASSERT_TRUE(mutator3 == other_mutator3);
286
288 Mutator mutator3se = Mutator(rse);
289 Mutator other_mutator3se = Mutator(rse);
290 ASSERT_TRUE(mutator3se == other_mutator3se);
291
292 DlPath path;
294 flutter::Mutator other_mutator4 = flutter::Mutator(path);
295 ASSERT_TRUE(mutator4 == other_mutator4);
296 ASSERT_FALSE(mutator2 == mutator);
297
298 uint8_t alpha = 240;
299 Mutator mutator5 = Mutator(alpha);
300 Mutator other_mutator5 = Mutator(alpha);
301 ASSERT_TRUE(mutator5 == other_mutator5);
302
303 auto filter1 = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp);
304 auto filter2 = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp);
305 Mutator mutator6 = Mutator(filter1, DlRect());
306 Mutator other_mutator6 = Mutator(filter2, DlRect());
307 ASSERT_TRUE(mutator6 == other_mutator6);
308}
309
310TEST(Mutator, UnEquality) {
311 DlRect rect = DlRect();
312 Mutator mutator = Mutator(rect);
313 DlMatrix matrix;
314 Mutator not_equal_mutator = Mutator(matrix);
315 ASSERT_TRUE(not_equal_mutator != mutator);
316
317 uint8_t alpha = 240;
318 uint8_t alpha2 = 241;
319 Mutator mutator2 = Mutator(alpha);
320 Mutator other_mutator2 = Mutator(alpha2);
321 ASSERT_TRUE(mutator2 != other_mutator2);
322
323 auto filter = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp);
324 auto filter2 = DlImageFilter::MakeBlur(10, 10, DlTileMode::kClamp);
325 Mutator mutator3 = Mutator(filter, DlRect());
326 Mutator other_mutator3 = Mutator(filter2, DlRect());
327 ASSERT_TRUE(mutator3 != other_mutator3);
328}
329
330} // namespace testing
331} // namespace flutter
static std::shared_ptr< DlImageFilter > MakeBlur(DlScalar sigma_x, DlScalar sigma_y, DlTileMode tile_mode)
const DlImageFilter & GetFilter() const
const DlMatrix & GetMatrix() const
const ImageFilterMutation & GetFilterMutation() const
MutatorType GetType() const
const DlPath & GetPath() const
const DlRoundSuperellipse & GetRSE() const
const DlRect & GetRect() const
const DlRoundRect & GetRRect() const
void PushTransform(const DlMatrix &matrix)
void PushBackdropFilter(const std::shared_ptr< DlImageFilter > &filter, const DlRect &filter_rect)
void PushClipRect(const DlRect &rect)
void PushClipPath(const DlPath &path)
const std::vector< std::shared_ptr< Mutator > >::const_reverse_iterator Top() const
const std::vector< std::shared_ptr< Mutator > >::const_reverse_iterator Bottom() const
const std::vector< std::shared_ptr< Mutator > >::const_iterator End() const
void PushClipRRect(const DlRoundRect &rrect)
void PushOpacity(const uint8_t &alpha)
void PushClipRSE(const DlRoundSuperellipse &rrect)
const std::vector< std::shared_ptr< Mutator > >::const_iterator Begin() const
TEST(NativeAssetsManagerTest, NoAvailableAssets)
impeller::RoundRect DlRoundRect
impeller::Rect DlRect
impeller::RoundSuperellipse DlRoundSuperellipse
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switch_defs.h:52
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static constexpr Matrix MakeScale(const Vector3 &s)
Definition matrix.h:104
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition rect.h:136