OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "ui/gfx/rect.h" | 7 #include "ui/gfx/rect.h" |
8 #include "ui/gfx/rect_conversions.h" | 8 #include "ui/gfx/rect_conversions.h" |
9 #include "ui/gfx/skia_util.h" | 9 #include "ui/gfx/skia_util.h" |
10 | 10 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 3, 1, 4, 2, | 100 3, 1, 4, 2, |
101 3, 1, 1, 2 }, | 101 3, 1, 1, 2 }, |
102 { 3, 0, 2, 2, // gap | 102 { 3, 0, 2, 2, // gap |
103 0, 0, 2, 2, | 103 0, 0, 2, 2, |
104 0, 0, 0, 0 } | 104 0, 0, 0, 0 } |
105 }; | 105 }; |
106 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 106 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
107 gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); | 107 gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
108 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); | 108 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
109 gfx::Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3); | 109 gfx::Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3); |
110 gfx::Rect ir = r1; | 110 gfx::Rect ir = gfx::IntersectRects(r1, r2); |
111 ir.Intersect(r2); | |
112 EXPECT_EQ(r3.x(), ir.x()); | 111 EXPECT_EQ(r3.x(), ir.x()); |
113 EXPECT_EQ(r3.y(), ir.y()); | 112 EXPECT_EQ(r3.y(), ir.y()); |
114 EXPECT_EQ(r3.width(), ir.width()); | 113 EXPECT_EQ(r3.width(), ir.width()); |
115 EXPECT_EQ(r3.height(), ir.height()); | 114 EXPECT_EQ(r3.height(), ir.height()); |
116 } | 115 } |
117 } | 116 } |
118 | 117 |
119 TEST(RectTest, Union) { | 118 TEST(RectTest, Union) { |
120 static const struct Test { | 119 static const struct Test { |
121 int x1; // rect 1 | 120 int x1; // rect 1 |
(...skipping 28 matching lines...) Expand all Loading... |
150 0, 0, 2, 2, | 149 0, 0, 2, 2, |
151 0, 0, 5, 5 }, | 150 0, 0, 5, 5 }, |
152 { 0, 0, 0, 0, // union with empty rect | 151 { 0, 0, 0, 0, // union with empty rect |
153 2, 2, 2, 2, | 152 2, 2, 2, 2, |
154 2, 2, 2, 2 } | 153 2, 2, 2, 2 } |
155 }; | 154 }; |
156 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 155 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
157 gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); | 156 gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
158 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); | 157 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
159 gfx::Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3); | 158 gfx::Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3); |
160 gfx::Rect u = r1; | 159 gfx::Rect u = gfx::UnionRects(r1, r2); |
161 u.Union(r2); | |
162 EXPECT_EQ(r3.x(), u.x()); | 160 EXPECT_EQ(r3.x(), u.x()); |
163 EXPECT_EQ(r3.y(), u.y()); | 161 EXPECT_EQ(r3.y(), u.y()); |
164 EXPECT_EQ(r3.width(), u.width()); | 162 EXPECT_EQ(r3.width(), u.width()); |
165 EXPECT_EQ(r3.height(), u.height()); | 163 EXPECT_EQ(r3.height(), u.height()); |
166 } | 164 } |
167 } | 165 } |
168 | 166 |
169 TEST(RectTest, Equals) { | 167 TEST(RectTest, Equals) { |
170 ASSERT_TRUE(gfx::Rect(0, 0, 0, 0) == gfx::Rect(0, 0, 0, 0)); | 168 ASSERT_TRUE(gfx::Rect(0, 0, 0, 0) == gfx::Rect(0, 0, 0, 0)); |
171 ASSERT_TRUE(gfx::Rect(1, 2, 3, 4) == gfx::Rect(1, 2, 3, 4)); | 169 ASSERT_TRUE(gfx::Rect(1, 2, 3, 4) == gfx::Rect(1, 2, 3, 4)); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 std::numeric_limits<float>::max() }, | 437 std::numeric_limits<float>::max() }, |
440 { 3, 3, 3, 3, | 438 { 3, 3, 3, 3, |
441 -1.0f, | 439 -1.0f, |
442 -3.0f, -3.0f, 0.0f, 0.0f } | 440 -3.0f, -3.0f, 0.0f, 0.0f } |
443 }; | 441 }; |
444 | 442 |
445 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 443 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
446 gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); | 444 gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
447 gfx::RectF r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); | 445 gfx::RectF r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
448 | 446 |
449 gfx::RectF scaled = r1; | 447 gfx::RectF scaled = gfx::ScaleRect(r1, tests[i].scale); |
450 scaled.Scale(tests[i].scale); | |
451 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), scaled.x()); | 448 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), scaled.x()); |
452 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), scaled.y()); | 449 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), scaled.y()); |
453 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), scaled.width()); | 450 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), scaled.width()); |
454 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), scaled.height()); | 451 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), scaled.height()); |
455 } | 452 } |
456 } | 453 } |
457 | 454 |
458 TEST(RectTest, ToEnclosedRect) { | 455 TEST(RectTest, ToEnclosedRect) { |
459 static const struct Test { | 456 static const struct Test { |
460 float x1; // source | 457 float x1; // source |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 gfx::Rect test1(rect_1); | 592 gfx::Rect test1(rect_1); |
596 gfx::Rect test2(rect_2); | 593 gfx::Rect test2(rect_2); |
597 } | 594 } |
598 #endif | 595 #endif |
599 | 596 |
600 TEST(RectTest, ToRectF) { | 597 TEST(RectTest, ToRectF) { |
601 // Check that implicit conversion from integer to float compiles. | 598 // Check that implicit conversion from integer to float compiles. |
602 gfx::Rect a(10, 20, 30, 40); | 599 gfx::Rect a(10, 20, 30, 40); |
603 gfx::RectF b(10, 20, 30, 40); | 600 gfx::RectF b(10, 20, 30, 40); |
604 | 601 |
605 gfx::RectF intersect = b; | 602 gfx::RectF intersect = gfx::IntersectRects(a, b); |
606 intersect.Intersect(a); | |
607 EXPECT_EQ(b.ToString(), intersect.ToString()); | 603 EXPECT_EQ(b.ToString(), intersect.ToString()); |
608 | 604 |
609 EXPECT_EQ(a, b); | 605 EXPECT_EQ(a, b); |
610 EXPECT_EQ(b, a); | 606 EXPECT_EQ(b, a); |
611 } | 607 } |
612 | 608 |
613 } // namespace ui | 609 } // namespace ui |
OLD | NEW |