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 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 RectF(-4.2f, -4.2f, 11.0f, 11.0f) } | 664 RectF(-4.2f, -4.2f, 11.0f, 11.0f) } |
665 }; | 665 }; |
666 | 666 |
667 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_tests); ++i) { | 667 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_tests); ++i) { |
668 RectF actual = BoundingRect(float_tests[i].a, float_tests[i].b); | 668 RectF actual = BoundingRect(float_tests[i].a, float_tests[i].b); |
669 EXPECT_EQ(float_tests[i].expected.ToString(), actual.ToString()); | 669 EXPECT_EQ(float_tests[i].expected.ToString(), actual.ToString()); |
670 } | 670 } |
671 } | 671 } |
672 | 672 |
673 TEST(RectTest, IsExpressibleAsRect) { | 673 TEST(RectTest, IsExpressibleAsRect) { |
674 EXPECT_TRUE(gfx::RectF().IsExpressibleAsRect()); | 674 EXPECT_TRUE(gfx::RectF().IsExpressibleAsRect()); |
tfarina
2012/11/09 14:29:52
nit: I though I had removed the gfx:: prefix when
danakj
2012/11/09 16:15:11
Done.
| |
675 | 675 |
676 float min = std::numeric_limits<int>::min(); | 676 float min = std::numeric_limits<int>::min(); |
677 float max = std::numeric_limits<int>::max(); | 677 float max = std::numeric_limits<int>::max(); |
678 float infinity = std::numeric_limits<float>::infinity(); | 678 float infinity = std::numeric_limits<float>::infinity(); |
679 | 679 |
680 EXPECT_TRUE(gfx::RectF( | 680 EXPECT_TRUE(gfx::RectF( |
681 min + 200, min + 200, max - 200, max - 200).IsExpressibleAsRect()); | 681 min + 200, min + 200, max - 200, max - 200).IsExpressibleAsRect()); |
682 EXPECT_FALSE(gfx::RectF( | 682 EXPECT_FALSE(gfx::RectF( |
683 min - 200, min + 200, max + 200, max + 200).IsExpressibleAsRect()); | 683 min - 200, min + 200, max + 200, max + 200).IsExpressibleAsRect()); |
684 EXPECT_FALSE(gfx::RectF( | 684 EXPECT_FALSE(gfx::RectF( |
685 min + 200 , min - 200, max + 200, max + 200).IsExpressibleAsRect()); | 685 min + 200 , min - 200, max + 200, max + 200).IsExpressibleAsRect()); |
686 EXPECT_FALSE(gfx::RectF( | 686 EXPECT_FALSE(gfx::RectF( |
687 min + 200, min + 200, max + 200, max - 200).IsExpressibleAsRect()); | 687 min + 200, min + 200, max + 200, max - 200).IsExpressibleAsRect()); |
688 EXPECT_FALSE(gfx::RectF( | 688 EXPECT_FALSE(gfx::RectF( |
689 min + 200, min + 200, max - 200, max + 200).IsExpressibleAsRect()); | 689 min + 200, min + 200, max - 200, max + 200).IsExpressibleAsRect()); |
690 | 690 |
691 EXPECT_TRUE(gfx::RectF(0, 0, max - 200, max - 200).IsExpressibleAsRect()); | 691 EXPECT_TRUE(gfx::RectF(0, 0, max - 200, max - 200).IsExpressibleAsRect()); |
692 EXPECT_FALSE(gfx::RectF(200, 0, max + 200, max - 200).IsExpressibleAsRect()); | 692 EXPECT_FALSE(gfx::RectF(200, 0, max + 200, max - 200).IsExpressibleAsRect()); |
693 EXPECT_FALSE(gfx::RectF(0, 200, max - 200, max + 200).IsExpressibleAsRect()); | 693 EXPECT_FALSE(gfx::RectF(0, 200, max - 200, max + 200).IsExpressibleAsRect()); |
694 EXPECT_FALSE(gfx::RectF(0, 0, max + 200, max - 200).IsExpressibleAsRect()); | 694 EXPECT_FALSE(gfx::RectF(0, 0, max + 200, max - 200).IsExpressibleAsRect()); |
695 EXPECT_FALSE(gfx::RectF(0, 0, max - 200, max + 200).IsExpressibleAsRect()); | 695 EXPECT_FALSE(gfx::RectF(0, 0, max - 200, max + 200).IsExpressibleAsRect()); |
696 | 696 |
697 EXPECT_FALSE(gfx::RectF(infinity, 0, 1, 1).IsExpressibleAsRect()); | 697 EXPECT_FALSE(gfx::RectF(infinity, 0, 1, 1).IsExpressibleAsRect()); |
698 EXPECT_FALSE(gfx::RectF(0, infinity, 1, 1).IsExpressibleAsRect()); | 698 EXPECT_FALSE(gfx::RectF(0, infinity, 1, 1).IsExpressibleAsRect()); |
699 EXPECT_FALSE(gfx::RectF(0, 0, infinity, 1).IsExpressibleAsRect()); | 699 EXPECT_FALSE(gfx::RectF(0, 0, infinity, 1).IsExpressibleAsRect()); |
700 EXPECT_FALSE(gfx::RectF(0, 0, 1, infinity).IsExpressibleAsRect()); | 700 EXPECT_FALSE(gfx::RectF(0, 0, 1, infinity).IsExpressibleAsRect()); |
701 } | 701 } |
702 | 702 |
703 TEST(RectTest, Offset) { | |
704 Rect i(1, 2, 3, 4); | |
705 | |
706 EXPECT_EQ(Rect(2, 1, 3, 4).ToString(), (i + Vector2d(1, -1)).ToString()); | |
707 i += Vector2d(1, -1); | |
708 EXPECT_EQ(Rect(2, 1, 3, 4).ToString(), i.ToString()); | |
709 EXPECT_EQ(Rect(1, 2, 3, 4).ToString(), (i - Vector2d(1, -1)).ToString()); | |
710 i -= Vector2d(1, -1); | |
711 EXPECT_EQ(Rect(1, 2, 3, 4).ToString(), i.ToString()); | |
712 | |
713 RectF f(1.1f, 2.2f, 3.3f, 4.4f); | |
714 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f).ToString(), | |
715 (f + Vector2dF(1.1f, -1.1f)).ToString()); | |
716 f += Vector2dF(1.1f, -1.1f); | |
717 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f).ToString(), f.ToString()); | |
718 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f).ToString(), | |
719 (f - Vector2dF(1.1f, -1.1f)).ToString()); | |
720 f -= Vector2dF(1.1f, -1.1f); | |
721 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f).ToString(), f.ToString()); | |
722 } | |
723 | |
703 } // namespace gfx | 724 } // namespace gfx |
OLD | NEW |