Flutter Engine
The Flutter Engine
Functions
insets_unittest.cc File Reference
#include "insets.h"
#include "gtest/gtest.h"
#include "insets_f.h"
#include "rect.h"
#include "size.h"
#include "vector2d.h"

Go to the source code of this file.

Functions

 TEST (InsetsTest, InsetsDefault)
 
 TEST (InsetsTest, Insets)
 
 TEST (InsetsTest, SetTop)
 
 TEST (InsetsTest, SetBottom)
 
 TEST (InsetsTest, SetLeft)
 
 TEST (InsetsTest, SetRight)
 
 TEST (InsetsTest, Set)
 
 TEST (InsetsTest, Operators)
 
 TEST (InsetsFTest, Operators)
 
 TEST (InsetsTest, Equality)
 
 TEST (InsetsTest, ToString)
 
 TEST (InsetsTest, Offset)
 
 TEST (InsetsTest, Scale)
 
 TEST (InsetsTest, IntegerOverflow)
 
 TEST (InsetsTest, IntegerUnderflow)
 
 TEST (InsetsTest, IntegerOverflowSetVariants)
 
 TEST (InsetsTest, IntegerUnderflowSetVariants)
 
 TEST (InsetsTest, IntegerOverflowSet)
 
 TEST (InsetsTest, IntegerOverflowOffset)
 
 TEST (InsetsTest, IntegerUnderflowOffset)
 
 TEST (InsetsTest, Size)
 

Function Documentation

◆ TEST() [1/21]

TEST ( InsetsFTest  ,
Operators   
)

Definition at line 96 of file insets_unittest.cc.

96 {
97 gfx::InsetsF insets;
98 insets.Set(1.f, 2.5f, 3.3f, 4.1f);
99 insets += gfx::InsetsF(5.8f, 6.7f, 7.6f, 8.5f);
100 EXPECT_FLOAT_EQ(6.8f, insets.top());
101 EXPECT_FLOAT_EQ(9.2f, insets.left());
102 EXPECT_FLOAT_EQ(10.9f, insets.bottom());
103 EXPECT_FLOAT_EQ(12.6f, insets.right());
104
105 insets -= gfx::InsetsF(-1.f, 0, 1.1f, 2.2f);
106 EXPECT_FLOAT_EQ(7.8f, insets.top());
107 EXPECT_FLOAT_EQ(9.2f, insets.left());
108 EXPECT_FLOAT_EQ(9.8f, insets.bottom());
109 EXPECT_FLOAT_EQ(10.4f, insets.right());
110
111 insets = gfx::InsetsF(10, 10.1f, 10.01f, 10.001f) +
112 gfx::InsetsF(5.5f, 5.f, 0, -20.2f);
113 EXPECT_FLOAT_EQ(15.5f, insets.top());
114 EXPECT_FLOAT_EQ(15.1f, insets.left());
115 EXPECT_FLOAT_EQ(10.01f, insets.bottom());
116 EXPECT_FLOAT_EQ(-10.199f, insets.right());
117
118 insets = gfx::InsetsF(10, 10.1f, 10.01f, 10.001f) -
119 gfx::InsetsF(5.5f, 5.f, 0, -20.2f);
120 EXPECT_FLOAT_EQ(4.5f, insets.top());
121 EXPECT_FLOAT_EQ(5.1f, insets.left());
122 EXPECT_FLOAT_EQ(10.01f, insets.bottom());
123 EXPECT_FLOAT_EQ(30.201f, insets.right());
124}
constexpr float left() const
Definition: insets_f.h:29
constexpr float bottom() const
Definition: insets_f.h:30
constexpr float top() const
Definition: insets_f.h:28
void Set(float top, float left, float bottom, float right)
Definition: insets_f.h:44
constexpr float right() const
Definition: insets_f.h:31

◆ TEST() [2/21]

TEST ( InsetsTest  ,
Equality   
)

Definition at line 126 of file insets_unittest.cc.

126 {
127 gfx::Insets insets1;
128 insets1.Set(1, 2, 3, 4);
129 gfx::Insets insets2;
130 // Test operator== and operator!=.
131 EXPECT_FALSE(insets1 == insets2);
132 EXPECT_TRUE(insets1 != insets2);
133
134 insets2.Set(1, 2, 3, 4);
135 EXPECT_TRUE(insets1 == insets2);
136 EXPECT_FALSE(insets1 != insets2);
137}
void Set(int top, int left, int bottom, int right)
Definition: insets.h:76
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678

◆ TEST() [3/21]

TEST ( InsetsTest  ,
Insets   
)

Definition at line 24 of file insets_unittest.cc.

24 {
25 gfx::Insets insets(1, 2, 3, 4);
26 EXPECT_EQ(1, insets.top());
27 EXPECT_EQ(2, insets.left());
28 EXPECT_EQ(3, insets.bottom());
29 EXPECT_EQ(4, insets.right());
30 EXPECT_EQ(6, insets.width()); // Left + right.
31 EXPECT_EQ(4, insets.height()); // Top + bottom.
32 EXPECT_FALSE(insets.IsEmpty());
33}

◆ TEST() [4/21]

TEST ( InsetsTest  ,
InsetsDefault   
)

Definition at line 13 of file insets_unittest.cc.

13 {
14 gfx::Insets insets;
15 EXPECT_EQ(0, insets.top());
16 EXPECT_EQ(0, insets.left());
17 EXPECT_EQ(0, insets.bottom());
18 EXPECT_EQ(0, insets.right());
19 EXPECT_EQ(0, insets.width());
20 EXPECT_EQ(0, insets.height());
21 EXPECT_TRUE(insets.IsEmpty());
22}
constexpr int width() const
Definition: insets.h:52
constexpr int right() const
Definition: insets.h:48
constexpr int bottom() const
Definition: insets.h:47
constexpr int top() const
Definition: insets.h:45
constexpr int height() const
Definition: insets.h:56
constexpr int left() const
Definition: insets.h:46
bool IsEmpty() const
Definition: insets.h:63

◆ TEST() [5/21]

TEST ( InsetsTest  ,
IntegerOverflow   
)

Definition at line 176 of file insets_unittest.cc.

176 {
177 constexpr int int_min = std::numeric_limits<int>::min();
178 constexpr int int_max = std::numeric_limits<int>::max();
179
180 gfx::Insets width_height_test(int_max);
181 EXPECT_EQ(int_max, width_height_test.width());
182 EXPECT_EQ(int_max, width_height_test.height());
183
184 gfx::Insets plus_test(int_max);
185 plus_test += gfx::Insets(int_max);
186 EXPECT_EQ(gfx::Insets(int_max), plus_test);
187
188 gfx::Insets negation_test = -gfx::Insets(int_min);
189 EXPECT_EQ(gfx::Insets(int_max), negation_test);
190
191 gfx::Insets scale_test(int_max);
192 scale_test = scale_test.Scale(2.f, 2.f);
193 EXPECT_EQ(gfx::Insets(int_max), scale_test);
194}
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

◆ TEST() [6/21]

TEST ( InsetsTest  ,
IntegerOverflowOffset   
)

Definition at line 265 of file insets_unittest.cc.

265 {
266 constexpr int int_max = std::numeric_limits<int>::max();
267
268 const gfx::Vector2d max_vector(int_max, int_max);
269 gfx::Insets insets(1, 2, 3, 4);
270 gfx::Insets offset_test = insets.Offset(max_vector);
271 EXPECT_EQ(gfx::Insets(int_max, int_max, 3 - int_max, 4 - int_max),
272 offset_test);
273}
Insets Offset(const gfx::Vector2d &vector) const
Definition: insets.cc:17

◆ TEST() [7/21]

TEST ( InsetsTest  ,
IntegerOverflowSet   
)

Definition at line 257 of file insets_unittest.cc.

257 {
258 constexpr int int_max = std::numeric_limits<int>::max();
259
260 gfx::Insets set_all_test;
261 set_all_test.Set(10, 20, int_max, int_max);
262 EXPECT_EQ(gfx::Insets(10, 20, int_max - 10, int_max - 20), set_all_test);
263}

◆ TEST() [8/21]

TEST ( InsetsTest  ,
IntegerOverflowSetVariants   
)

Definition at line 213 of file insets_unittest.cc.

213 {
214 constexpr int int_max = std::numeric_limits<int>::max();
215
216 gfx::Insets set_test(20);
217 set_test.set_top(int_max);
218 EXPECT_EQ(int_max, set_test.top());
219 EXPECT_EQ(0, set_test.bottom());
220
221 set_test.set_left(int_max);
222 EXPECT_EQ(int_max, set_test.left());
223 EXPECT_EQ(0, set_test.right());
224
225 set_test = gfx::Insets(30);
226 set_test.set_bottom(int_max);
227 EXPECT_EQ(int_max - 30, set_test.bottom());
228 EXPECT_EQ(30, set_test.top());
229
230 set_test.set_right(int_max);
231 EXPECT_EQ(int_max - 30, set_test.right());
232 EXPECT_EQ(30, set_test.left());
233}

◆ TEST() [9/21]

TEST ( InsetsTest  ,
IntegerUnderflow   
)

Definition at line 196 of file insets_unittest.cc.

196 {
197 constexpr int int_min = std::numeric_limits<int>::min();
198 constexpr int int_max = std::numeric_limits<int>::max();
199
200 gfx::Insets width_height_test = gfx::Insets(int_min);
201 EXPECT_EQ(int_min, width_height_test.width());
202 EXPECT_EQ(int_min, width_height_test.height());
203
204 gfx::Insets minus_test(int_min);
205 minus_test -= gfx::Insets(int_max);
206 EXPECT_EQ(gfx::Insets(int_min), minus_test);
207
208 gfx::Insets scale_test = gfx::Insets(int_min);
209 scale_test = scale_test.Scale(2.f, 2.f);
210 EXPECT_EQ(gfx::Insets(int_min), scale_test);
211}
Insets Scale(float scale) const
Definition: insets.h:110

◆ TEST() [10/21]

TEST ( InsetsTest  ,
IntegerUnderflowOffset   
)

Definition at line 275 of file insets_unittest.cc.

275 {
276 constexpr int int_min = std::numeric_limits<int>::min();
277
278 const gfx::Vector2d min_vector(int_min, int_min);
279 gfx::Insets insets(-10);
280 gfx::Insets offset_test = insets.Offset(min_vector);
281 EXPECT_EQ(gfx::Insets(int_min, int_min, -10 - int_min, -10 - int_min),
282 offset_test);
283}

◆ TEST() [11/21]

TEST ( InsetsTest  ,
IntegerUnderflowSetVariants   
)

Definition at line 235 of file insets_unittest.cc.

235 {
236 constexpr int int_min = std::numeric_limits<int>::min();
237
238 gfx::Insets set_test(-20);
239 set_test.set_top(int_min);
240 EXPECT_EQ(int_min, set_test.top());
241 EXPECT_EQ(0, set_test.bottom());
242
243 set_test.set_left(int_min);
244 EXPECT_EQ(int_min, set_test.left());
245 EXPECT_EQ(0, set_test.right());
246
247 set_test = gfx::Insets(-30);
248 set_test.set_bottom(int_min);
249 EXPECT_EQ(int_min + 30, set_test.bottom());
250 EXPECT_EQ(-30, set_test.top());
251
252 set_test.set_right(int_min);
253 EXPECT_EQ(int_min + 30, set_test.right());
254 EXPECT_EQ(-30, set_test.left());
255}

◆ TEST() [12/21]

TEST ( InsetsTest  ,
Offset   
)

Definition at line 144 of file insets_unittest.cc.

144 {
145 const gfx::Insets insets(1, 2, 3, 4);
146 const gfx::Rect rect(5, 6, 7, 8);
147 const gfx::Vector2d vector(9, 10);
148
149 // Whether you inset then offset the rect, offset then inset the rect, or
150 // offset the insets then apply to the rect, the outcome should be the same.
151 gfx::Rect inset_first = rect;
152 inset_first.Inset(insets);
153 inset_first.Offset(vector);
154
155 gfx::Rect offset_first = rect;
156 offset_first.Offset(vector);
157 offset_first.Inset(insets);
158
159 gfx::Rect inset_by_offset = rect;
160 inset_by_offset.Inset(insets.Offset(vector));
161
162 EXPECT_EQ(inset_first, offset_first);
163 EXPECT_EQ(inset_by_offset, inset_first);
164}
Definition: rect.h:36
void Offset(int horizontal, int vertical)
Definition: rect.cc:121
void Inset(int horizontal, int vertical)
Definition: rect.h:123
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350

◆ TEST() [13/21]

TEST ( InsetsTest  ,
Operators   
)

Definition at line 68 of file insets_unittest.cc.

68 {
69 gfx::Insets insets;
70 insets.Set(1, 2, 3, 4);
71 insets += gfx::Insets(5, 6, 7, 8);
72 EXPECT_EQ(6, insets.top());
73 EXPECT_EQ(8, insets.left());
74 EXPECT_EQ(10, insets.bottom());
75 EXPECT_EQ(12, insets.right());
76
77 insets -= gfx::Insets(-1, 0, 1, 2);
78 EXPECT_EQ(7, insets.top());
79 EXPECT_EQ(8, insets.left());
80 EXPECT_EQ(9, insets.bottom());
81 EXPECT_EQ(10, insets.right());
82
83 insets = gfx::Insets(10, 10, 10, 10) + gfx::Insets(5, 5, 0, -20);
84 EXPECT_EQ(15, insets.top());
85 EXPECT_EQ(15, insets.left());
86 EXPECT_EQ(10, insets.bottom());
87 EXPECT_EQ(-10, insets.right());
88
89 insets = gfx::Insets(10, 10, 10, 10) - gfx::Insets(5, 5, 0, -20);
90 EXPECT_EQ(5, insets.top());
91 EXPECT_EQ(5, insets.left());
92 EXPECT_EQ(10, insets.bottom());
93 EXPECT_EQ(30, insets.right());
94}

◆ TEST() [14/21]

TEST ( InsetsTest  ,
Scale   
)

Definition at line 166 of file insets_unittest.cc.

166 {
167 gfx::Insets test(10, 5);
168 test = test.Scale(2.f, 3.f);
169 EXPECT_EQ(gfx::Insets(30, 10), test);
170
171 test = gfx::Insets(7, 3);
172 test = test.Scale(-2.f, -3.f);
173 EXPECT_EQ(gfx::Insets(-21, -6), test);
174}
#define test(name)

◆ TEST() [15/21]

TEST ( InsetsTest  ,
Set   
)

Definition at line 59 of file insets_unittest.cc.

59 {
60 gfx::Insets insets;
61 insets.Set(1, 2, 3, 4);
62 EXPECT_EQ(1, insets.top());
63 EXPECT_EQ(2, insets.left());
64 EXPECT_EQ(3, insets.bottom());
65 EXPECT_EQ(4, insets.right());
66}

◆ TEST() [16/21]

TEST ( InsetsTest  ,
SetBottom   
)

Definition at line 41 of file insets_unittest.cc.

41 {
42 gfx::Insets insets(1);
43 insets.set_bottom(2);
44 EXPECT_EQ(gfx::Insets(1, 1, 2, 1), insets);
45}

◆ TEST() [17/21]

TEST ( InsetsTest  ,
SetLeft   
)

Definition at line 47 of file insets_unittest.cc.

47 {
48 gfx::Insets insets(1);
49 insets.set_left(2);
50 EXPECT_EQ(gfx::Insets(1, 2, 1, 1), insets);
51}

◆ TEST() [18/21]

TEST ( InsetsTest  ,
SetRight   
)

Definition at line 53 of file insets_unittest.cc.

53 {
54 gfx::Insets insets(1);
55 insets.set_right(2);
56 EXPECT_EQ(gfx::Insets(1, 1, 1, 2), insets);
57}

◆ TEST() [19/21]

TEST ( InsetsTest  ,
SetTop   
)

Definition at line 35 of file insets_unittest.cc.

35 {
36 gfx::Insets insets(1);
37 insets.set_top(2);
38 EXPECT_EQ(gfx::Insets(2, 1, 1, 1), insets);
39}

◆ TEST() [20/21]

TEST ( InsetsTest  ,
Size   
)

Definition at line 285 of file insets_unittest.cc.

285 {
286 gfx::Insets insets(1, 2, 3, 4);
287 EXPECT_EQ(gfx::Size(6, 4), insets.size());
288}
Definition: size.h:26

◆ TEST() [21/21]

TEST ( InsetsTest  ,
ToString   
)

Definition at line 139 of file insets_unittest.cc.

139 {
140 gfx::Insets insets(1, 2, 3, 4);
141 EXPECT_EQ("1,2,3,4", insets.ToString());
142}