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