| 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 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); | 548 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
| 549 | 549 |
| 550 gfx::Rect enclosed = ToEnclosingRect(r1); | 550 gfx::Rect enclosed = ToEnclosingRect(r1); |
| 551 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); | 551 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); |
| 552 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); | 552 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); |
| 553 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); | 553 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); |
| 554 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); | 554 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); |
| 555 } | 555 } |
| 556 } | 556 } |
| 557 | 557 |
| 558 TEST(RectTest, ToFlooredRect) { |
| 559 static const struct Test { |
| 560 float x1; // source |
| 561 float y1; |
| 562 float w1; |
| 563 float h1; |
| 564 int x2; // target |
| 565 int y2; |
| 566 int w2; |
| 567 int h2; |
| 568 } tests [] = { |
| 569 { 0.0f, 0.0f, 0.0f, 0.0f, |
| 570 0, 0, 0, 0 }, |
| 571 { -1.5f, -1.5f, 3.0f, 3.0f, |
| 572 -2, -2, 3, 3 }, |
| 573 { -1.5f, -1.5f, 3.5f, 3.5f, |
| 574 -2, -2, 3, 3 }, |
| 575 { 20000.5f, 20000.5f, 0.5f, 0.5f, |
| 576 20000, 20000, 0, 0 }, |
| 577 }; |
| 578 |
| 579 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 580 gfx::RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
| 581 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
| 582 |
| 583 gfx::Rect floored = ToFlooredRectDeprecated(r1); |
| 584 EXPECT_FLOAT_EQ(r2.x(), floored.x()); |
| 585 EXPECT_FLOAT_EQ(r2.y(), floored.y()); |
| 586 EXPECT_FLOAT_EQ(r2.width(), floored.width()); |
| 587 EXPECT_FLOAT_EQ(r2.height(), floored.height()); |
| 588 } |
| 589 } |
| 590 |
| 558 #if defined(OS_WIN) | 591 #if defined(OS_WIN) |
| 559 TEST(RectTest, ConstructAndAssign) { | 592 TEST(RectTest, ConstructAndAssign) { |
| 560 const RECT rect_1 = { 0, 0, 10, 10 }; | 593 const RECT rect_1 = { 0, 0, 10, 10 }; |
| 561 const RECT rect_2 = { 0, 0, -10, -10 }; | 594 const RECT rect_2 = { 0, 0, -10, -10 }; |
| 562 gfx::Rect test1(rect_1); | 595 gfx::Rect test1(rect_1); |
| 563 gfx::Rect test2(rect_2); | 596 gfx::Rect test2(rect_2); |
| 564 } | 597 } |
| 565 #endif | 598 #endif |
| 566 | 599 |
| 567 TEST(RectTest, ToRectF) { | 600 TEST(RectTest, ToRectF) { |
| 568 // Check that implicit conversion from integer to float compiles. | 601 // Check that implicit conversion from integer to float compiles. |
| 569 gfx::Rect a(10, 20, 30, 40); | 602 gfx::Rect a(10, 20, 30, 40); |
| 570 gfx::RectF b(10, 20, 30, 40); | 603 gfx::RectF b(10, 20, 30, 40); |
| 571 | 604 |
| 572 gfx::RectF intersect = b; | 605 gfx::RectF intersect = b; |
| 573 intersect.Intersect(a); | 606 intersect.Intersect(a); |
| 574 EXPECT_EQ(b.ToString(), intersect.ToString()); | 607 EXPECT_EQ(b.ToString(), intersect.ToString()); |
| 575 | 608 |
| 576 EXPECT_EQ(a, b); | 609 EXPECT_EQ(a, b); |
| 577 EXPECT_EQ(b, a); | 610 EXPECT_EQ(b, a); |
| 578 } | 611 } |
| 579 | 612 |
| 580 } // namespace ui | 613 } // namespace ui |
| OLD | NEW |