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