Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Unified Diff: ui/gfx/rect_unittest.cc

Issue 11293194: ui: Prefer +/- operators to apply offsets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gfx:: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/rect_unittest.cc
diff --git a/ui/gfx/rect_unittest.cc b/ui/gfx/rect_unittest.cc
index 621e5d90fc73b9d8c844660425a6678897b97bcf..3fd2fd1e27f277912e21d35806f7bdaa9590bdee 100644
--- a/ui/gfx/rect_unittest.cc
+++ b/ui/gfx/rect_unittest.cc
@@ -671,33 +671,54 @@ TEST(RectTest, BoundingRect) {
}
TEST(RectTest, IsExpressibleAsRect) {
- EXPECT_TRUE(gfx::RectF().IsExpressibleAsRect());
+ EXPECT_TRUE(RectF().IsExpressibleAsRect());
float min = std::numeric_limits<int>::min();
float max = std::numeric_limits<int>::max();
float infinity = std::numeric_limits<float>::infinity();
- EXPECT_TRUE(gfx::RectF(
+ EXPECT_TRUE(RectF(
min + 200, min + 200, max - 200, max - 200).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(
+ EXPECT_FALSE(RectF(
min - 200, min + 200, max + 200, max + 200).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(
+ EXPECT_FALSE(RectF(
min + 200 , min - 200, max + 200, max + 200).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(
+ EXPECT_FALSE(RectF(
min + 200, min + 200, max + 200, max - 200).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(
+ EXPECT_FALSE(RectF(
min + 200, min + 200, max - 200, max + 200).IsExpressibleAsRect());
- EXPECT_TRUE(gfx::RectF(0, 0, max - 200, max - 200).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(200, 0, max + 200, max - 200).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(0, 200, max - 200, max + 200).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(0, 0, max + 200, max - 200).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(0, 0, max - 200, max + 200).IsExpressibleAsRect());
+ EXPECT_TRUE(RectF(0, 0, max - 200, max - 200).IsExpressibleAsRect());
+ EXPECT_FALSE(RectF(200, 0, max + 200, max - 200).IsExpressibleAsRect());
+ EXPECT_FALSE(RectF(0, 200, max - 200, max + 200).IsExpressibleAsRect());
+ EXPECT_FALSE(RectF(0, 0, max + 200, max - 200).IsExpressibleAsRect());
+ EXPECT_FALSE(RectF(0, 0, max - 200, max + 200).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(infinity, 0, 1, 1).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(0, infinity, 1, 1).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(0, 0, infinity, 1).IsExpressibleAsRect());
- EXPECT_FALSE(gfx::RectF(0, 0, 1, infinity).IsExpressibleAsRect());
+ EXPECT_FALSE(RectF(infinity, 0, 1, 1).IsExpressibleAsRect());
+ EXPECT_FALSE(RectF(0, infinity, 1, 1).IsExpressibleAsRect());
+ EXPECT_FALSE(RectF(0, 0, infinity, 1).IsExpressibleAsRect());
+ EXPECT_FALSE(RectF(0, 0, 1, infinity).IsExpressibleAsRect());
+}
+
+TEST(RectTest, Offset) {
+ Rect i(1, 2, 3, 4);
+
+ EXPECT_EQ(Rect(2, 1, 3, 4).ToString(), (i + Vector2d(1, -1)).ToString());
+ i += Vector2d(1, -1);
+ EXPECT_EQ(Rect(2, 1, 3, 4).ToString(), i.ToString());
+ EXPECT_EQ(Rect(1, 2, 3, 4).ToString(), (i - Vector2d(1, -1)).ToString());
+ i -= Vector2d(1, -1);
+ EXPECT_EQ(Rect(1, 2, 3, 4).ToString(), i.ToString());
+
+ RectF f(1.1f, 2.2f, 3.3f, 4.4f);
+ EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f).ToString(),
+ (f + Vector2dF(1.1f, -1.1f)).ToString());
+ f += Vector2dF(1.1f, -1.1f);
+ EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f).ToString(), f.ToString());
+ EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f).ToString(),
+ (f - Vector2dF(1.1f, -1.1f)).ToString());
+ f -= Vector2dF(1.1f, -1.1f);
+ EXPECT_EQ(RectF(1.1f, 2.2,f 3.3f, 4.4f).ToString(), f.ToString());
}
} // namespace gfx
« ui/gfx/rect_f.h ('K') | « ui/gfx/rect_f.cc ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698