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

Unified Diff: ui/gfx/geometry/point_unittest.cc

Issue 2354783004: Fix overflow/underflow in gfx geometry once and for all (Closed)
Patch Set: Remove accessibility test changes Created 4 years, 2 months 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
« no previous file with comments | « ui/gfx/geometry/point.h ('k') | ui/gfx/geometry/rect.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/geometry/point_unittest.cc
diff --git a/ui/gfx/geometry/point_unittest.cc b/ui/gfx/geometry/point_unittest.cc
index 6acef25f0b41a9902033ef0e3798661efdf5dbc8..b453dd768421a814becda714d83030d955d99ef5 100644
--- a/ui/gfx/geometry/point_unittest.cc
+++ b/ui/gfx/geometry/point_unittest.cc
@@ -160,4 +160,77 @@ TEST(PointTest, ClampPointF) {
EXPECT_EQ(PointF(3.5f, 5.5f).ToString(), a.ToString());
}
+TEST(PointTest, Offset) {
+ Point test(3, 4);
+ test.Offset(5, -8);
+ EXPECT_EQ(test, Point(8, -4));
+}
+
+TEST(PointTest, VectorMath) {
+ Point test = Point(3, 4);
+ test += Vector2d(5, -8);
+ EXPECT_EQ(test, Point(8, -4));
+
+ Point test2 = Point(3, 4);
+ test2 -= Vector2d(5, -8);
+ EXPECT_EQ(test2, Point(-2, 12));
+}
+
+TEST(PointTest, IntegerOverflow) {
+ int int_max = std::numeric_limits<int>::max();
+ int int_min = std::numeric_limits<int>::min();
+
+ Point max_point(int_max, int_max);
+ Point min_point(int_min, int_min);
+ Point test;
+
+ test = Point();
+ test.Offset(int_max, int_max);
+ EXPECT_EQ(test, max_point);
+
+ test = Point();
+ test.Offset(int_min, int_min);
+ EXPECT_EQ(test, min_point);
+
+ test = Point(10, 20);
+ test.Offset(int_max, int_max);
+ EXPECT_EQ(test, max_point);
+
+ test = Point(-10, -20);
+ test.Offset(int_min, int_min);
+ EXPECT_EQ(test, min_point);
+
+ test = Point();
+ test += Vector2d(int_max, int_max);
+ EXPECT_EQ(test, max_point);
+
+ test = Point();
+ test += Vector2d(int_min, int_min);
+ EXPECT_EQ(test, min_point);
+
+ test = Point(10, 20);
+ test += Vector2d(int_max, int_max);
+ EXPECT_EQ(test, max_point);
+
+ test = Point(-10, -20);
+ test += Vector2d(int_min, int_min);
+ EXPECT_EQ(test, min_point);
+
+ test = Point();
+ test -= Vector2d(int_max, int_max);
+ EXPECT_EQ(test, Point(-int_max, -int_max));
+
+ test = Point();
+ test -= Vector2d(int_min, int_min);
+ EXPECT_EQ(test, max_point);
+
+ test = Point(10, 20);
+ test -= Vector2d(int_min, int_min);
+ EXPECT_EQ(test, max_point);
+
+ test = Point(-10, -20);
+ test -= Vector2d(int_max, int_max);
+ EXPECT_EQ(test, min_point);
+}
+
} // namespace gfx
« no previous file with comments | « ui/gfx/geometry/point.h ('k') | ui/gfx/geometry/rect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698