Flutter Engine
 
Loading...
Searching...
No Matches
dl_accumulation_rect_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
6#include "gtest/gtest.h"
7
8namespace flutter {
9namespace testing {
10
11TEST(DisplayListAccumulationRect, Constructor) {
12 AccumulationRect accumulator;
13
14 EXPECT_TRUE(accumulator.is_empty());
15 EXPECT_TRUE(accumulator.GetBounds().IsEmpty());
16 EXPECT_FALSE(accumulator.overlap_detected());
17}
18
19TEST(DisplayListAccumulationRect, OnePoint) {
20 AccumulationRect accumulator;
21 accumulator.accumulate(10.0f, 10.0f);
22
23 EXPECT_TRUE(accumulator.is_empty());
24 EXPECT_TRUE(accumulator.GetBounds().IsEmpty());
25 EXPECT_FALSE(accumulator.overlap_detected());
26}
27
28TEST(DisplayListAccumulationRect, TwoPoints) {
29 auto test = [](DlScalar x1, DlScalar y1, //
30 DlScalar x2, DlScalar y2, //
31 DlRect bounds, //
32 bool should_be_empty, bool should_overlap,
33 const std::string& label) {
34 {
35 AccumulationRect accumulator;
36 accumulator.accumulate(x1, y1);
37 accumulator.accumulate(x2, y2);
38
39 EXPECT_EQ(accumulator.is_empty(), should_be_empty) << label;
40 EXPECT_EQ(accumulator.GetBounds().IsEmpty(), should_be_empty) << label;
41 EXPECT_EQ(accumulator.GetBounds(), bounds) << label;
42 EXPECT_EQ(accumulator.overlap_detected(), should_overlap) << label;
43 }
44
45 {
46 AccumulationRect accumulator;
47 accumulator.accumulate(DlPoint(x1, y1));
48 accumulator.accumulate(DlPoint(x2, y2));
49
50 EXPECT_EQ(accumulator.is_empty(), should_be_empty) << label;
51 EXPECT_EQ(accumulator.GetBounds().IsEmpty(), should_be_empty) << label;
52 EXPECT_EQ(accumulator.GetBounds(), bounds) << label;
53 EXPECT_EQ(accumulator.overlap_detected(), should_overlap) << label;
54 }
55 };
56
57 test(10.0f, 10.0f, 10.0f, 10.0f, DlRect::MakeLTRB(10.0f, 10.0f, 10.0f, 10.0f),
58 true, false, "Same");
59 test(10.0f, 10.0f, 20.0f, 10.0f, DlRect::MakeLTRB(10.0f, 10.0f, 20.0f, 10.0f),
60 true, false, "Horizontal");
61 test(10.0f, 10.0f, 10.0f, 20.0f, DlRect::MakeLTRB(10.0f, 10.0f, 10.0f, 20.0f),
62 true, false, "Vertical");
63 test(10.0f, 10.0f, 20.0f, 20.0f, DlRect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f),
64 false, false, "Diagonal");
65}
66
67TEST(DisplayListAccumulationRect, ThreePoints) {
68 auto test = [](DlScalar x1, DlScalar y1, //
69 DlScalar x2, DlScalar y2, //
70 DlScalar x3, DlScalar y3, //
71 DlRect bounds, //
72 bool should_be_empty, bool should_overlap,
73 const std::string& label) {
74 {
75 AccumulationRect accumulator;
76 accumulator.accumulate(x1, y1);
77 accumulator.accumulate(x2, y2);
78 accumulator.accumulate(x3, y3);
79
80 EXPECT_EQ(accumulator.is_empty(), should_be_empty) << label;
81 EXPECT_EQ(accumulator.GetBounds().IsEmpty(), should_be_empty) << label;
82 EXPECT_EQ(accumulator.GetBounds(), bounds) << label;
83 EXPECT_EQ(accumulator.overlap_detected(), should_overlap) << label;
84 }
85
86 {
87 AccumulationRect accumulator;
88 accumulator.accumulate(DlPoint(x1, y1));
89 accumulator.accumulate(DlPoint(x2, y2));
90 accumulator.accumulate(DlPoint(x3, y3));
91
92 EXPECT_EQ(accumulator.is_empty(), should_be_empty) << label;
93 EXPECT_EQ(accumulator.GetBounds().IsEmpty(), should_be_empty) << label;
94 EXPECT_EQ(accumulator.GetBounds(), bounds) << label;
95 EXPECT_EQ(accumulator.overlap_detected(), should_overlap) << label;
96 }
97 };
98
99 test(10.0f, 10.0f, 10.0f, 10.0f, 10.0f, 10.0f,
100 DlRect::MakeLTRB(10.0f, 10.0f, 10.0f, 10.0f), true, false, "Same");
101 test(10.0f, 10.0f, 20.0f, 10.0f, 15.0f, 10.0f,
102 DlRect::MakeLTRB(10.0f, 10.0f, 20.0f, 10.0f), true, false, "Horizontal");
103 test(10.0f, 10.0f, 10.0f, 20.0f, 10.0f, 15.0f,
104 DlRect::MakeLTRB(10.0f, 10.0f, 10.0f, 20.0f), true, false, "Vertical");
105 test(10.0f, 10.0f, 20.0f, 20.0f, 25.0f, 15.0f,
106 DlRect::MakeLTRB(10.0f, 10.0f, 25.0f, 20.0f), false, false, "Disjoint");
107 test(10.0f, 10.0f, 20.0f, 20.0f, 15.0f, 15.0f,
108 DlRect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f), false, true, "Inside");
109}
110
111TEST(DisplayListAccumulationRect, EmptyRect) {
112 auto test = [](DlScalar l, DlScalar t, DlScalar r, DlScalar b, //
113 DlRect bounds, //
114 bool should_be_empty, bool should_overlap,
115 const std::string& label) {
116 {
117 AccumulationRect accumulator;
118 accumulator.accumulate(DlRect::MakeLTRB(l, t, r, b));
119
120 EXPECT_EQ(accumulator.is_empty(), should_be_empty) << label;
121 EXPECT_EQ(accumulator.GetBounds().IsEmpty(), should_be_empty) << label;
122 EXPECT_EQ(accumulator.GetBounds(), bounds) << label;
123 EXPECT_EQ(accumulator.overlap_detected(), should_overlap) << label;
124 }
125
126 {
127 AccumulationRect accumulator;
128 accumulator.accumulate(DlRect::MakeLTRB(l, t, r, b));
129
130 EXPECT_EQ(accumulator.is_empty(), should_be_empty) << label;
131 EXPECT_EQ(accumulator.GetBounds().IsEmpty(), should_be_empty) << label;
132 EXPECT_EQ(accumulator.GetBounds(), bounds) << label;
133 EXPECT_EQ(accumulator.overlap_detected(), should_overlap) << label;
134 }
135
136 {
138 content.accumulate(l, t);
139 content.accumulate(r, b);
140 EXPECT_EQ(content.is_empty(), should_be_empty) << label;
141 EXPECT_EQ(content.GetBounds().IsEmpty(), should_be_empty) << label;
142 // bounds for an accumulation by points may be different than the
143 // bounds for an accumulation by the rect they produce because
144 // construction by points has no "empty rejection" case.
145 if (!should_be_empty) {
146 EXPECT_EQ(content.GetBounds(), bounds) << label;
147 }
148 EXPECT_EQ(content.overlap_detected(), should_overlap) << label;
149
150 AccumulationRect accumulator;
151 accumulator.accumulate(content);
152
153 EXPECT_EQ(accumulator.is_empty(), should_be_empty) << label;
154 EXPECT_EQ(accumulator.GetBounds().IsEmpty(), should_be_empty) << label;
155 EXPECT_EQ(accumulator.GetBounds(), bounds) << label;
156 EXPECT_EQ(accumulator.overlap_detected(), should_overlap) << label;
157 }
158 };
159
160 test(10.0f, 10.0f, 10.0f, 10.0f, DlRect::MakeLTRB(0.0f, 0.0f, 0.0f, 0.0f),
161 true, false, "Singular");
162 test(10.0f, 10.0f, 20.0f, 10.0f, DlRect::MakeLTRB(0.0f, 0.0f, 0.0f, 0.0f),
163 true, false, "Horizontal Empty");
164 test(10.0f, 10.0f, 10.0f, 20.0f, DlRect::MakeLTRB(0.0f, 0.0f, 0.0f, 0.0f),
165 true, false, "Vertical Empty");
166 test(10.0f, 10.0f, 20.0f, 20.0f, DlRect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f),
167 false, false, "Non-Empty");
168}
169
170TEST(DisplayListAccumulationRect, TwoRects) {
171 auto test = [](DlScalar l1, DlScalar t1, DlScalar r1, DlScalar b1, //
172 DlScalar l2, DlScalar t2, DlScalar r2, DlScalar b2, //
173 DlRect bounds, //
174 bool should_be_empty, bool should_overlap,
175 const std::string& label) {
176 {
177 AccumulationRect accumulator;
178 accumulator.accumulate(DlRect::MakeLTRB(l1, t1, r1, b1));
179 accumulator.accumulate(DlRect::MakeLTRB(l2, t2, r2, b2));
180
181 EXPECT_EQ(accumulator.is_empty(), should_be_empty) << label;
182 EXPECT_EQ(accumulator.GetBounds().IsEmpty(), should_be_empty) << label;
183 EXPECT_EQ(accumulator.GetBounds(), bounds) << label;
184 EXPECT_EQ(accumulator.overlap_detected(), should_overlap) << label;
185 }
186
187 {
188 AccumulationRect content1;
189 content1.accumulate(l1, t1);
190 content1.accumulate(r1, b1);
191
192 AccumulationRect content2;
193 content2.accumulate(l2, t2);
194 content2.accumulate(r2, b2);
195
196 AccumulationRect accumulator;
197 accumulator.accumulate(content1);
198 accumulator.accumulate(content2);
199
200 EXPECT_EQ(accumulator.is_empty(), should_be_empty) << label;
201 EXPECT_EQ(accumulator.GetBounds().IsEmpty(), should_be_empty) << label;
202 EXPECT_EQ(accumulator.GetBounds(), bounds) << label;
203 EXPECT_EQ(accumulator.overlap_detected(), should_overlap) << label;
204 }
205 };
206
207 test(10.0f, 10.0f, 10.0f, 10.0f, //
208 20.0f, 20.0f, 20.0f, 20.0f, //
209 DlRect::MakeLTRB(0.0f, 0.0f, 0.0f, 0.0f), //
210 true, false, "Empty + Empty");
211 test(10.0f, 10.0f, 20.0f, 10.0f, //
212 10.0f, 10.0f, 10.0f, 20.0f, //
213 DlRect::MakeLTRB(0.0f, 0.0f, 0.0f, 0.0f), //
214 true, false, "Horizontal + Vertical");
215 test(10.0f, 10.0f, 10.0f, 10.0f, //
216 15.0f, 15.0f, 20.0f, 20.0f, //
217 DlRect::MakeLTRB(15.0f, 15.0f, 20.0f, 20.0f), //
218 false, false, "Empty + Non-Empty");
219 test(10.0f, 10.0f, 15.0f, 15.0f, //
220 20.0f, 20.0f, 20.0f, 20.0f, //
221 DlRect::MakeLTRB(10.0f, 10.0f, 15.0f, 15.0f), //
222 false, false, "Non-Empty + Empty");
223 test(10.0f, 10.0f, 15.0f, 15.0f, //
224 15.0f, 15.0f, 20.0f, 20.0f, //
225 DlRect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f), //
226 false, false, "Abutting");
227 test(10.0f, 10.0f, 15.0f, 15.0f, //
228 16.0f, 16.0f, 20.0f, 20.0f, //
229 DlRect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f), //
230 false, false, "Disjoint");
231 test(10.0f, 10.0f, 16.0f, 16.0f, //
232 15.0f, 15.0f, 20.0f, 20.0f, //
233 DlRect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f), //
234 false, true, "Overlapping");
235}
236
237} // namespace testing
238} // namespace flutter
void accumulate(DlScalar x, DlScalar y)
union flutter::testing::@2824::KeyboardChange::@78 content
TEST(NativeAssetsManagerTest, NoAvailableAssets)
impeller::Scalar DlScalar
impeller::Point DlPoint
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition rect.h:297
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129