Revert of Fix cancellation of a pair of URLRequestJob subclasses (patchset #6 id...
[chromium-blink-merge.git] / cc / base / region_unittest.cc
blobc9a218d692a7b95f68f8c6fb693ae9c2563b86bc
1 // Copyright 2012 The Chromium 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.
5 #include "cc/base/region.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace cc {
10 namespace {
12 #define TEST_INSIDE_RECT(r, x, y, w, h) \
13 EXPECT_TRUE(r.Contains(gfx::Point(x, y))); \
14 EXPECT_TRUE(r.Contains(gfx::Point(x + w - 1, y))); \
15 EXPECT_TRUE(r.Contains(gfx::Point(x, y + h - 1))); \
16 EXPECT_TRUE(r.Contains(gfx::Point(x + w - 1, y + h - 1))); \
17 EXPECT_TRUE(r.Contains(gfx::Point(x, y + h / 2))); \
18 EXPECT_TRUE(r.Contains(gfx::Point(x + w - 1, y + h / 2))); \
19 EXPECT_TRUE(r.Contains(gfx::Point(x + w / 2, y))); \
20 EXPECT_TRUE(r.Contains(gfx::Point(x + w / 2, y + h - 1))); \
21 EXPECT_TRUE(r.Contains(gfx::Point(x + w / 2, y + h / 2))); \
23 #define TEST_LEFT_OF_RECT(r, x, y, w, h) \
24 EXPECT_FALSE(r.Contains(gfx::Point(x - 1, y))); \
25 EXPECT_FALSE(r.Contains(gfx::Point(x - 1, y + h - 1))); \
27 #define TEST_RIGHT_OF_RECT(r, x, y, w, h) \
28 EXPECT_FALSE(r.Contains(gfx::Point(x + w, y))); \
29 EXPECT_FALSE(r.Contains(gfx::Point(x + w, y + h - 1))); \
31 #define TEST_TOP_OF_RECT(r, x, y, w, h) \
32 EXPECT_FALSE(r.Contains(gfx::Point(x, y - 1))); \
33 EXPECT_FALSE(r.Contains(gfx::Point(x + w - 1, y - 1))); \
35 #define TEST_BOTTOM_OF_RECT(r, x, y, w, h) \
36 EXPECT_FALSE(r.Contains(gfx::Point(x, y + h))); \
37 EXPECT_FALSE(r.Contains(gfx::Point(x + w - 1, y + h))); \
39 TEST(RegionTest, ContainsPoint) {
40 Region r;
42 EXPECT_FALSE(r.Contains(gfx::Point(0, 0)));
44 r.Union(gfx::Rect(35, 35, 1, 1));
45 TEST_INSIDE_RECT(r, 35, 35, 1, 1);
46 TEST_LEFT_OF_RECT(r, 35, 35, 1, 1);
47 TEST_RIGHT_OF_RECT(r, 35, 35, 1, 1);
48 TEST_TOP_OF_RECT(r, 35, 35, 1, 1);
49 TEST_BOTTOM_OF_RECT(r, 35, 35, 1, 1);
51 r.Union(gfx::Rect(30, 30, 10, 10));
52 TEST_INSIDE_RECT(r, 30, 30, 10, 10);
53 TEST_LEFT_OF_RECT(r, 30, 30, 10, 10);
54 TEST_RIGHT_OF_RECT(r, 30, 30, 10, 10);
55 TEST_TOP_OF_RECT(r, 30, 30, 10, 10);
56 TEST_BOTTOM_OF_RECT(r, 30, 30, 10, 10);
58 r.Union(gfx::Rect(31, 40, 10, 10));
59 EXPECT_FALSE(r.Contains(gfx::Point(30, 40)));
60 EXPECT_TRUE(r.Contains(gfx::Point(31, 40)));
61 EXPECT_FALSE(r.Contains(gfx::Point(40, 39)));
62 EXPECT_TRUE(r.Contains(gfx::Point(40, 40)));
64 TEST_INSIDE_RECT(r, 30, 30, 10, 10);
65 TEST_LEFT_OF_RECT(r, 30, 30, 10, 10);
66 TEST_RIGHT_OF_RECT(r, 30, 30, 10, 10);
67 TEST_TOP_OF_RECT(r, 30, 30, 10, 10);
68 TEST_INSIDE_RECT(r, 31, 40, 10, 10);
69 TEST_LEFT_OF_RECT(r, 31, 40, 10, 10);
70 TEST_RIGHT_OF_RECT(r, 31, 40, 10, 10);
71 TEST_BOTTOM_OF_RECT(r, 31, 40, 10, 10);
73 r.Union(gfx::Rect(42, 40, 10, 10));
75 TEST_INSIDE_RECT(r, 42, 40, 10, 10);
76 TEST_LEFT_OF_RECT(r, 42, 40, 10, 10);
77 TEST_RIGHT_OF_RECT(r, 42, 40, 10, 10);
78 TEST_TOP_OF_RECT(r, 42, 40, 10, 10);
79 TEST_BOTTOM_OF_RECT(r, 42, 40, 10, 10);
81 TEST_INSIDE_RECT(r, 30, 30, 10, 10);
82 TEST_LEFT_OF_RECT(r, 30, 30, 10, 10);
83 TEST_RIGHT_OF_RECT(r, 30, 30, 10, 10);
84 TEST_TOP_OF_RECT(r, 30, 30, 10, 10);
85 TEST_INSIDE_RECT(r, 31, 40, 10, 10);
86 TEST_LEFT_OF_RECT(r, 31, 40, 10, 10);
87 TEST_RIGHT_OF_RECT(r, 31, 40, 10, 10);
88 TEST_BOTTOM_OF_RECT(r, 31, 40, 10, 10);
91 TEST(RegionTest, EmptySpan) {
92 Region r;
93 r.Union(gfx::Rect(5, 0, 10, 10));
94 r.Union(gfx::Rect(0, 5, 10, 10));
95 r.Subtract(gfx::Rect(7, 7, 10, 0));
97 for (Region::Iterator it(r); it.has_rect(); it.next())
98 EXPECT_FALSE(it.rect().IsEmpty());
101 #define TEST_NO_INTERSECT(a, b) { \
102 Region ar = a; \
103 Region br = b; \
104 EXPECT_FALSE(ar.Intersects(br)); \
105 EXPECT_FALSE(br.Intersects(ar)); \
106 EXPECT_FALSE(ar.Intersects(b)); \
107 EXPECT_FALSE(br.Intersects(a)); \
110 #define TEST_INTERSECT(a, b) { \
111 Region ar = a; \
112 Region br = b; \
113 EXPECT_TRUE(ar.Intersects(br)); \
114 EXPECT_TRUE(br.Intersects(ar)); \
115 EXPECT_TRUE(ar.Intersects(b)); \
116 EXPECT_TRUE(br.Intersects(a)); \
119 TEST(RegionTest, IntersectsRegion) {
120 Region r;
122 TEST_NO_INTERSECT(gfx::Rect(), gfx::Rect());
123 TEST_NO_INTERSECT(gfx::Rect(), gfx::Rect(0, 0, 1, 1));
124 TEST_NO_INTERSECT(gfx::Rect(), gfx::Rect(1, 1, 1, 1));
126 TEST_NO_INTERSECT(gfx::Rect(-1, -1, 2, 2), gfx::Rect());
128 r.Union(gfx::Rect(0, 0, 1, 1));
129 TEST_NO_INTERSECT(r, gfx::Rect());
130 TEST_INTERSECT(r, gfx::Rect(0, 0, 1, 1));
131 TEST_INTERSECT(r, gfx::Rect(0, 0, 2, 2));
132 TEST_INTERSECT(r, gfx::Rect(-1, 0, 2, 2));
133 TEST_INTERSECT(r, gfx::Rect(-1, -1, 2, 2));
134 TEST_INTERSECT(r, gfx::Rect(0, -1, 2, 2));
135 TEST_INTERSECT(r, gfx::Rect(-1, -1, 3, 3));
137 r.Union(gfx::Rect(0, 0, 3, 3));
138 r.Union(gfx::Rect(10, 0, 3, 3));
139 r.Union(gfx::Rect(0, 10, 13, 3));
140 TEST_NO_INTERSECT(r, gfx::Rect());
141 TEST_INTERSECT(r, gfx::Rect(1, 1, 1, 1));
142 TEST_INTERSECT(r, gfx::Rect(0, 0, 2, 2));
143 TEST_INTERSECT(r, gfx::Rect(1, 0, 2, 2));
144 TEST_INTERSECT(r, gfx::Rect(1, 1, 2, 2));
145 TEST_INTERSECT(r, gfx::Rect(0, 1, 2, 2));
146 TEST_INTERSECT(r, gfx::Rect(0, 0, 3, 3));
147 TEST_INTERSECT(r, gfx::Rect(-1, -1, 2, 2));
148 TEST_INTERSECT(r, gfx::Rect(2, -1, 2, 2));
149 TEST_INTERSECT(r, gfx::Rect(2, 2, 2, 2));
150 TEST_INTERSECT(r, gfx::Rect(-1, 2, 2, 2));
152 TEST_INTERSECT(r, gfx::Rect(11, 1, 1, 1));
153 TEST_INTERSECT(r, gfx::Rect(10, 0, 2, 2));
154 TEST_INTERSECT(r, gfx::Rect(11, 0, 2, 2));
155 TEST_INTERSECT(r, gfx::Rect(11, 1, 2, 2));
156 TEST_INTERSECT(r, gfx::Rect(10, 1, 2, 2));
157 TEST_INTERSECT(r, gfx::Rect(10, 0, 3, 3));
158 TEST_INTERSECT(r, gfx::Rect(9, -1, 2, 2));
159 TEST_INTERSECT(r, gfx::Rect(12, -1, 2, 2));
160 TEST_INTERSECT(r, gfx::Rect(12, 2, 2, 2));
161 TEST_INTERSECT(r, gfx::Rect(9, 2, 2, 2));
163 TEST_INTERSECT(r, gfx::Rect(0, -1, 13, 5));
164 TEST_INTERSECT(r, gfx::Rect(1, -1, 11, 5));
165 TEST_INTERSECT(r, gfx::Rect(2, -1, 9, 5));
166 TEST_INTERSECT(r, gfx::Rect(2, -1, 8, 5));
167 TEST_INTERSECT(r, gfx::Rect(3, -1, 8, 5));
168 TEST_NO_INTERSECT(r, gfx::Rect(3, -1, 7, 5));
170 TEST_INTERSECT(r, gfx::Rect(0, 1, 13, 1));
171 TEST_INTERSECT(r, gfx::Rect(1, 1, 11, 1));
172 TEST_INTERSECT(r, gfx::Rect(2, 1, 9, 1));
173 TEST_INTERSECT(r, gfx::Rect(2, 1, 8, 1));
174 TEST_INTERSECT(r, gfx::Rect(3, 1, 8, 1));
175 TEST_NO_INTERSECT(r, gfx::Rect(3, 1, 7, 1));
177 TEST_INTERSECT(r, gfx::Rect(0, 0, 13, 13));
178 TEST_INTERSECT(r, gfx::Rect(0, 1, 13, 11));
179 TEST_INTERSECT(r, gfx::Rect(0, 2, 13, 9));
180 TEST_INTERSECT(r, gfx::Rect(0, 2, 13, 8));
181 TEST_INTERSECT(r, gfx::Rect(0, 3, 13, 8));
182 TEST_NO_INTERSECT(r, gfx::Rect(0, 3, 13, 7));
185 TEST(RegionTest, ReadPastFullSpanVectorInIntersectsTest) {
186 Region r;
188 // This region has enough spans to fill its allocated Vector exactly.
189 r.Union(gfx::Rect(400, 300, 1, 800));
190 r.Union(gfx::Rect(785, 585, 1, 1));
191 r.Union(gfx::Rect(787, 585, 1, 1));
192 r.Union(gfx::Rect(0, 587, 16, 162));
193 r.Union(gfx::Rect(26, 590, 300, 150));
194 r.Union(gfx::Rect(196, 750, 1, 1));
195 r.Union(gfx::Rect(0, 766, 1, 1));
196 r.Union(gfx::Rect(0, 782, 1, 1));
197 r.Union(gfx::Rect(745, 798, 1, 1));
198 r.Union(gfx::Rect(795, 882, 10, 585));
199 r.Union(gfx::Rect(100, 1499, 586, 1));
200 r.Union(gfx::Rect(100, 1500, 585, 784));
201 // This query rect goes past the bottom of the Region, causing the
202 // test to reach the last span and try go past it. It should not read
203 // memory off the end of the span Vector.
204 TEST_NO_INTERSECT(r, gfx::Rect(0, 2184, 1, 150));
207 #define TEST_NO_CONTAINS(a, b) \
209 Region ar = a; \
210 Region br = b; \
211 EXPECT_FALSE(ar.Contains(br)); \
212 EXPECT_FALSE(ar.Contains(b)); \
215 #define TEST_CONTAINS(a, b) \
217 Region ar = a; \
218 Region br = b; \
219 EXPECT_TRUE(ar.Contains(br)); \
220 EXPECT_TRUE(ar.Contains(b)); \
223 TEST(RegionTest, ContainsRegion) {
224 TEST_CONTAINS(gfx::Rect(), gfx::Rect());
225 TEST_CONTAINS(gfx::Rect(0, 0, 1, 1), gfx::Rect());
226 TEST_CONTAINS(gfx::Rect(10, 10, 1, 1), gfx::Rect());
228 TEST_NO_CONTAINS(gfx::Rect(), gfx::Rect(0, 0, 1, 1));
229 TEST_NO_CONTAINS(gfx::Rect(), gfx::Rect(1, 1, 1, 1));
231 TEST_NO_CONTAINS(gfx::Rect(10, 10, 1, 1), gfx::Rect(11, 10, 1, 1));
232 TEST_NO_CONTAINS(gfx::Rect(10, 10, 1, 1), gfx::Rect(10, 11, 1, 1));
233 TEST_NO_CONTAINS(gfx::Rect(10, 10, 1, 1), gfx::Rect(9, 10, 1, 1));
234 TEST_NO_CONTAINS(gfx::Rect(10, 10, 1, 1), gfx::Rect(10, 9, 1, 1));
235 TEST_NO_CONTAINS(gfx::Rect(10, 10, 1, 1), gfx::Rect(9, 9, 2, 2));
236 TEST_NO_CONTAINS(gfx::Rect(10, 10, 1, 1), gfx::Rect(10, 9, 2, 2));
237 TEST_NO_CONTAINS(gfx::Rect(10, 10, 1, 1), gfx::Rect(9, 10, 2, 2));
238 TEST_NO_CONTAINS(gfx::Rect(10, 10, 1, 1), gfx::Rect(10, 10, 2, 2));
239 TEST_NO_CONTAINS(gfx::Rect(10, 10, 1, 1), gfx::Rect(9, 9, 3, 3));
241 Region h_lines;
242 for (int i = 10; i < 20; i += 2)
243 h_lines.Union(gfx::Rect(i, 10, 1, 10));
245 TEST_CONTAINS(gfx::Rect(10, 10, 9, 10), h_lines);
246 TEST_NO_CONTAINS(gfx::Rect(10, 10, 9, 9), h_lines);
247 TEST_NO_CONTAINS(gfx::Rect(10, 11, 9, 9), h_lines);
248 TEST_NO_CONTAINS(gfx::Rect(10, 10, 8, 10), h_lines);
249 TEST_NO_CONTAINS(gfx::Rect(11, 10, 8, 10), h_lines);
251 Region v_lines;
252 for (int i = 10; i < 20; i += 2)
253 v_lines.Union(gfx::Rect(10, i, 10, 1));
255 TEST_CONTAINS(gfx::Rect(10, 10, 10, 9), v_lines);
256 TEST_NO_CONTAINS(gfx::Rect(10, 10, 9, 9), v_lines);
257 TEST_NO_CONTAINS(gfx::Rect(11, 10, 9, 9), v_lines);
258 TEST_NO_CONTAINS(gfx::Rect(10, 10, 10, 8), v_lines);
259 TEST_NO_CONTAINS(gfx::Rect(10, 11, 10, 8), v_lines);
261 Region grid;
262 for (int i = 10; i < 20; i += 2)
263 for (int j = 10; j < 20; j += 2)
264 grid.Union(gfx::Rect(i, j, 1, 1));
266 TEST_CONTAINS(gfx::Rect(10, 10, 9, 9), grid);
267 TEST_NO_CONTAINS(gfx::Rect(10, 10, 9, 8), grid);
268 TEST_NO_CONTAINS(gfx::Rect(10, 11, 9, 8), grid);
269 TEST_NO_CONTAINS(gfx::Rect(10, 10, 8, 9), grid);
270 TEST_NO_CONTAINS(gfx::Rect(11, 10, 8, 9), grid);
272 TEST_CONTAINS(h_lines, h_lines);
273 TEST_CONTAINS(v_lines, v_lines);
274 TEST_NO_CONTAINS(v_lines, h_lines);
275 TEST_NO_CONTAINS(h_lines, v_lines);
276 TEST_CONTAINS(grid, grid);
277 TEST_CONTAINS(h_lines, grid);
278 TEST_CONTAINS(v_lines, grid);
279 TEST_NO_CONTAINS(grid, h_lines);
280 TEST_NO_CONTAINS(grid, v_lines);
282 for (int i = 10; i < 20; i += 2)
283 TEST_CONTAINS(h_lines, gfx::Rect(i, 10, 1, 10));
285 for (int i = 10; i < 20; i += 2)
286 TEST_CONTAINS(v_lines, gfx::Rect(10, i, 10, 1));
288 for (int i = 10; i < 20; i += 2)
289 for (int j = 10; j < 20; j += 2)
290 TEST_CONTAINS(grid, gfx::Rect(i, j, 1, 1));
292 Region container;
293 container.Union(gfx::Rect(0, 0, 40, 20));
294 container.Union(gfx::Rect(0, 20, 41, 20));
295 TEST_CONTAINS(container, gfx::Rect(5, 5, 30, 30));
297 container.Clear();
298 container.Union(gfx::Rect(0, 0, 10, 10));
299 container.Union(gfx::Rect(0, 30, 10, 10));
300 container.Union(gfx::Rect(30, 30, 10, 10));
301 container.Union(gfx::Rect(30, 0, 10, 10));
302 TEST_NO_CONTAINS(container, gfx::Rect(5, 5, 30, 30));
304 container.Clear();
305 container.Union(gfx::Rect(0, 0, 10, 10));
306 container.Union(gfx::Rect(0, 30, 10, 10));
307 container.Union(gfx::Rect(30, 0, 10, 40));
308 TEST_NO_CONTAINS(container, gfx::Rect(5, 5, 30, 30));
310 container.Clear();
311 container.Union(gfx::Rect(30, 0, 10, 10));
312 container.Union(gfx::Rect(30, 30, 10, 10));
313 container.Union(gfx::Rect(0, 0, 10, 40));
314 TEST_NO_CONTAINS(container, gfx::Rect(5, 5, 30, 30));
316 container.Clear();
317 container.Union(gfx::Rect(0, 0, 10, 40));
318 container.Union(gfx::Rect(30, 0, 10, 40));
319 TEST_NO_CONTAINS(container, gfx::Rect(5, 5, 30, 30));
321 container.Clear();
322 container.Union(gfx::Rect(0, 0, 40, 40));
323 TEST_NO_CONTAINS(container, gfx::Rect(10, -1, 20, 10));
325 container.Clear();
326 container.Union(gfx::Rect(0, 0, 40, 40));
327 TEST_NO_CONTAINS(container, gfx::Rect(10, 31, 20, 10));
329 container.Clear();
330 container.Union(gfx::Rect(0, 0, 40, 20));
331 container.Union(gfx::Rect(0, 20, 41, 20));
332 TEST_NO_CONTAINS(container, gfx::Rect(-1, 10, 10, 20));
334 container.Clear();
335 container.Union(gfx::Rect(0, 0, 40, 20));
336 container.Union(gfx::Rect(0, 20, 41, 20));
337 TEST_NO_CONTAINS(container, gfx::Rect(31, 10, 10, 20));
339 container.Clear();
340 container.Union(gfx::Rect(0, 0, 40, 40));
341 container.Subtract(gfx::Rect(0, 20, 60, 0));
342 TEST_NO_CONTAINS(container, gfx::Rect(31, 10, 10, 20));
344 container.Clear();
345 container.Union(gfx::Rect(0, 0, 60, 20));
346 container.Union(gfx::Rect(30, 20, 10, 20));
347 TEST_NO_CONTAINS(container, gfx::Rect(0, 0, 10, 39));
348 TEST_NO_CONTAINS(container, gfx::Rect(0, 0, 10, 40));
349 TEST_NO_CONTAINS(container, gfx::Rect(0, 0, 10, 41));
350 TEST_NO_CONTAINS(container, gfx::Rect(29, 0, 10, 39));
351 TEST_CONTAINS(container, gfx::Rect(30, 0, 10, 40));
352 TEST_NO_CONTAINS(container, gfx::Rect(31, 0, 10, 41));
353 TEST_NO_CONTAINS(container, gfx::Rect(49, 0, 10, 39));
354 TEST_NO_CONTAINS(container, gfx::Rect(50, 0, 10, 40));
355 TEST_NO_CONTAINS(container, gfx::Rect(51, 0, 10, 41));
357 container.Clear();
358 container.Union(gfx::Rect(30, 0, 10, 20));
359 container.Union(gfx::Rect(0, 20, 60, 20));
360 TEST_NO_CONTAINS(container, gfx::Rect(0, 0, 10, 39));
361 TEST_NO_CONTAINS(container, gfx::Rect(0, 0, 10, 40));
362 TEST_NO_CONTAINS(container, gfx::Rect(0, 0, 10, 41));
363 TEST_NO_CONTAINS(container, gfx::Rect(29, 0, 10, 39));
364 TEST_CONTAINS(container, gfx::Rect(30, 0, 10, 40));
365 TEST_NO_CONTAINS(container, gfx::Rect(31, 0, 10, 41));
366 TEST_NO_CONTAINS(container, gfx::Rect(49, 0, 10, 39));
367 TEST_NO_CONTAINS(container, gfx::Rect(50, 0, 10, 40));
368 TEST_NO_CONTAINS(container, gfx::Rect(51, 0, 10, 41));
371 TEST(RegionTest, Union) {
372 Region r;
373 Region r2;
375 // A rect uniting a contained rect does not change the region.
376 r2 = r = gfx::Rect(0, 0, 50, 50);
377 r2.Union(gfx::Rect(20, 20, 10, 10));
378 EXPECT_EQ(r, r2);
380 // A rect uniting a containing rect gives back the containing rect.
381 r = gfx::Rect(0, 0, 50, 50);
382 r.Union(gfx::Rect(0, 0, 100, 100));
383 EXPECT_EQ(Region(gfx::Rect(0, 0, 100, 100)), r);
385 // A complex region uniting a contained rect does not change the region.
386 r = gfx::Rect(0, 0, 50, 50);
387 r.Union(gfx::Rect(100, 0, 50, 50));
388 r2 = r;
389 r2.Union(gfx::Rect(20, 20, 10, 10));
390 EXPECT_EQ(r, r2);
392 // A complex region uniting a containing rect gives back the containing rect.
393 r = gfx::Rect(0, 0, 50, 50);
394 r.Union(gfx::Rect(100, 0, 50, 50));
395 r.Union(gfx::Rect(0, 0, 500, 500));
396 EXPECT_EQ(Region(gfx::Rect(0, 0, 500, 500)), r);
399 TEST(RegionTest, IsEmpty) {
400 EXPECT_TRUE(Region().IsEmpty());
401 EXPECT_TRUE(Region(gfx::Rect()).IsEmpty());
402 EXPECT_TRUE(Region(Region()).IsEmpty());
403 EXPECT_TRUE(Region(gfx::Rect(10, 10, 10, 0)).IsEmpty());
404 EXPECT_TRUE(Region(gfx::Rect(10, 10, 0, 10)).IsEmpty());
405 EXPECT_TRUE(Region(gfx::Rect(-10, 10, 10, 0)).IsEmpty());
406 EXPECT_TRUE(Region(gfx::Rect(-10, 10, 0, 10)).IsEmpty());
407 EXPECT_FALSE(Region(gfx::Rect(-1, -1, 1, 1)).IsEmpty());
408 EXPECT_FALSE(Region(gfx::Rect(0, 0, 1, 1)).IsEmpty());
409 EXPECT_FALSE(Region(gfx::Rect(0, 0, 2, 2)).IsEmpty());
411 EXPECT_TRUE(SkIRect::MakeXYWH(10, 10, 10, 0).isEmpty());
412 EXPECT_TRUE(SkIRect::MakeXYWH(10, 10, 0, 10).isEmpty());
413 EXPECT_TRUE(SkIRect::MakeXYWH(-10, 10, 10, 0).isEmpty());
414 EXPECT_TRUE(SkIRect::MakeXYWH(-10, 10, 0, 10).isEmpty());
415 EXPECT_FALSE(SkIRect::MakeXYWH(-1, -1, 1, 1).isEmpty());
416 EXPECT_FALSE(SkIRect::MakeXYWH(0, 0, 1, 1).isEmpty());
417 EXPECT_FALSE(SkIRect::MakeXYWH(0, 0, 2, 2).isEmpty());
420 TEST(RegionTest, Clear) {
421 Region r;
423 r = gfx::Rect(0, 0, 50, 50);
424 EXPECT_FALSE(r.IsEmpty());
425 r.Clear();
426 EXPECT_TRUE(r.IsEmpty());
428 r = gfx::Rect(0, 0, 50, 50);
429 r.Union(gfx::Rect(100, 0, 50, 50));
430 r.Union(gfx::Rect(0, 0, 500, 500));
431 EXPECT_FALSE(r.IsEmpty());
432 r.Clear();
433 EXPECT_TRUE(r.IsEmpty());
436 TEST(RegionSwap, Swap) {
437 Region r1, r2, r3;
439 r1 = gfx::Rect(0, 0, 50, 50);
440 r1.Swap(&r2);
441 EXPECT_TRUE(r1.IsEmpty());
442 EXPECT_EQ(r2.ToString(), Region(gfx::Rect(0, 0, 50, 50)).ToString());
444 r1 = gfx::Rect(0, 0, 50, 50);
445 r1.Union(gfx::Rect(100, 0, 50, 50));
446 r1.Union(gfx::Rect(0, 0, 500, 500));
447 r3 = r1;
448 r1.Swap(&r2);
449 EXPECT_EQ(r1.ToString(), Region(gfx::Rect(0, 0, 50, 50)).ToString());
450 EXPECT_EQ(r2.ToString(), r3.ToString());
453 } // namespace
454 } // namespace cc