OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/geometry/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
10 #include "ui/gfx/geometry/rect_conversions.h" | 10 #include "ui/gfx/geometry/rect_conversions.h" |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 std::numeric_limits<float>::quiet_NaN() }, | 448 std::numeric_limits<float>::quiet_NaN() }, |
449 { 3, 3, 3, 3, | 449 { 3, 3, 3, 3, |
450 std::numeric_limits<float>::max(), | 450 std::numeric_limits<float>::max(), |
451 std::numeric_limits<float>::max(), | 451 std::numeric_limits<float>::max(), |
452 std::numeric_limits<float>::max(), | 452 std::numeric_limits<float>::max(), |
453 std::numeric_limits<float>::max(), | 453 std::numeric_limits<float>::max(), |
454 std::numeric_limits<float>::max() } | 454 std::numeric_limits<float>::max() } |
455 }; | 455 }; |
456 | 456 |
457 for (size_t i = 0; i < arraysize(tests); ++i) { | 457 for (size_t i = 0; i < arraysize(tests); ++i) { |
458 Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); | 458 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
459 RectF r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); | 459 RectF r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
460 | 460 |
461 RectF scaled = ScaleRect(r1, tests[i].scale); | 461 RectF scaled = ScaleRect(r1, tests[i].scale); |
462 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), scaled.x()); | 462 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), scaled.x()); |
463 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), scaled.y()); | 463 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), scaled.y()); |
464 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), scaled.width()); | 464 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), scaled.width()); |
465 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), scaled.height()); | 465 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), scaled.height()); |
466 } | 466 } |
467 } | 467 } |
468 | 468 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 #if defined(OS_WIN) | 698 #if defined(OS_WIN) |
699 TEST(RectTest, ConstructAndAssign) { | 699 TEST(RectTest, ConstructAndAssign) { |
700 const RECT rect_1 = { 0, 0, 10, 10 }; | 700 const RECT rect_1 = { 0, 0, 10, 10 }; |
701 const RECT rect_2 = { 0, 0, -10, -10 }; | 701 const RECT rect_2 = { 0, 0, -10, -10 }; |
702 Rect test1(rect_1); | 702 Rect test1(rect_1); |
703 Rect test2(rect_2); | 703 Rect test2(rect_2); |
704 } | 704 } |
705 #endif | 705 #endif |
706 | 706 |
707 TEST(RectTest, ToRectF) { | 707 TEST(RectTest, ToRectF) { |
708 // Check that implicit conversion from integer to float compiles. | 708 // Check that explicit conversion from integer to float compiles. |
709 Rect a(10, 20, 30, 40); | 709 Rect a(10, 20, 30, 40); |
710 RectF b(10, 20, 30, 40); | 710 RectF b(10, 20, 30, 40); |
711 | 711 |
712 RectF intersect = IntersectRects(a, b); | 712 RectF c = RectF(a); |
713 EXPECT_EQ(b, intersect); | 713 EXPECT_EQ(b, c); |
714 | |
715 EXPECT_EQ(a, b); | |
716 EXPECT_EQ(b, a); | |
717 } | 714 } |
718 | 715 |
719 TEST(RectTest, BoundingRect) { | 716 TEST(RectTest, BoundingRect) { |
720 struct { | 717 struct { |
721 Point a; | 718 Point a; |
722 Point b; | 719 Point b; |
723 Rect expected; | 720 Rect expected; |
724 } int_tests[] = { | 721 } int_tests[] = { |
725 // If point B dominates A, then A should be the origin. | 722 // If point B dominates A, then A should be the origin. |
726 { Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0) }, | 723 { Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0) }, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); | 906 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); |
910 EXPECT_FLOAT_EQ( | 907 EXPECT_FLOAT_EQ( |
911 0.1f + kEpsilon, | 908 0.1f + kEpsilon, |
912 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); | 909 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); |
913 EXPECT_FLOAT_EQ( | 910 EXPECT_FLOAT_EQ( |
914 kEpsilon, | 911 kEpsilon, |
915 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); | 912 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); |
916 } | 913 } |
917 | 914 |
918 } // namespace gfx | 915 } // namespace gfx |
OLD | NEW |