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

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

Issue 2354783004: Fix overflow/underflow in gfx geometry once and for all (Closed)
Patch Set: Now with more tests Created 4 years, 3 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
« ui/gfx/geometry/rect.cc ('K') | « ui/gfx/geometry/vector2d.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/geometry/vector2d_unittest.cc
diff --git a/ui/gfx/geometry/vector2d_unittest.cc b/ui/gfx/geometry/vector2d_unittest.cc
index 98d75f22bf8db6f5842e53aa1261ed8c504905b0..253b10a33db6766890aa75b8d4a6d623572b9c17 100644
--- a/ui/gfx/geometry/vector2d_unittest.cc
+++ b/ui/gfx/geometry/vector2d_unittest.cc
@@ -249,4 +249,44 @@ TEST(Vector2dTest, ClampVector2dF) {
EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString());
}
+TEST(Vector2dTest, IntegerOverflow) {
+ int int_max = std::numeric_limits<int>::max();
+ int int_min = std::numeric_limits<int>::min();
+
+ Vector2d max_vector(int_max, int_max);
+ Vector2d min_vector(int_min, int_min);
+ Vector2d test;
+
+ test = Vector2d();
+ test += Vector2d(int_max, int_max);
+ EXPECT_EQ(test, max_vector);
+
+ test = Vector2d();
+ test += Vector2d(int_min, int_min);
+ EXPECT_EQ(test, min_vector);
+
+ test = Vector2d(10, 20);
+ test += Vector2d(int_max, int_max);
+ EXPECT_EQ(test, max_vector);
+
+ test = Vector2d(-10, -20);
+ test += Vector2d(int_min, int_min);
+ EXPECT_EQ(test, min_vector);
+
+ test = Vector2d();
+ test -= Vector2d(int_max, int_max);
+ EXPECT_EQ(test, Vector2d(-int_max, -int_max));
+
+ test = Vector2d();
+ test -= Vector2d(int_min, int_min);
+ EXPECT_EQ(test, max_vector);
+
+ test = Vector2d(10, 20);
+ test -= Vector2d(int_min, int_min);
+ EXPECT_EQ(test, max_vector);
+
+ test = Vector2d(-10, -20);
+ test -= Vector2d(int_max, int_max);
+ EXPECT_EQ(test, min_vector);
+}
} // namespace gfx
danakj 2016/09/21 22:01:36 nit: whitespace below
« ui/gfx/geometry/rect.cc ('K') | « ui/gfx/geometry/vector2d.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698