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

Side by Side Diff: ui/gfx/geometry/vector2d_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 unified diff | Download patch
« no previous file with comments | « ui/gfx/geometry/vector2d.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 a.SetToMin(Vector2dF(8.5f, 10.5f)); 242 a.SetToMin(Vector2dF(8.5f, 10.5f));
243 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString()); 243 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString());
244 a.SetToMin(Vector2dF(11.5f, 9.5f)); 244 a.SetToMin(Vector2dF(11.5f, 9.5f));
245 EXPECT_EQ(Vector2dF(8.5f, 9.5f).ToString(), a.ToString()); 245 EXPECT_EQ(Vector2dF(8.5f, 9.5f).ToString(), a.ToString());
246 a.SetToMin(Vector2dF(7.5f, 11.5f)); 246 a.SetToMin(Vector2dF(7.5f, 11.5f));
247 EXPECT_EQ(Vector2dF(7.5f, 9.5f).ToString(), a.ToString()); 247 EXPECT_EQ(Vector2dF(7.5f, 9.5f).ToString(), a.ToString());
248 a.SetToMin(Vector2dF(3.5f, 5.5f)); 248 a.SetToMin(Vector2dF(3.5f, 5.5f));
249 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString()); 249 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString());
250 } 250 }
251 251
252 TEST(Vector2dTest, IntegerOverflow) {
253 int int_max = std::numeric_limits<int>::max();
254 int int_min = std::numeric_limits<int>::min();
255
256 Vector2d max_vector(int_max, int_max);
257 Vector2d min_vector(int_min, int_min);
258 Vector2d test;
259
260 test = Vector2d();
261 test += Vector2d(int_max, int_max);
262 EXPECT_EQ(test, max_vector);
263
264 test = Vector2d();
265 test += Vector2d(int_min, int_min);
266 EXPECT_EQ(test, min_vector);
267
268 test = Vector2d(10, 20);
269 test += Vector2d(int_max, int_max);
270 EXPECT_EQ(test, max_vector);
271
272 test = Vector2d(-10, -20);
273 test += Vector2d(int_min, int_min);
274 EXPECT_EQ(test, min_vector);
275
276 test = Vector2d();
277 test -= Vector2d(int_max, int_max);
278 EXPECT_EQ(test, Vector2d(-int_max, -int_max));
279
280 test = Vector2d();
281 test -= Vector2d(int_min, int_min);
282 EXPECT_EQ(test, max_vector);
283
284 test = Vector2d(10, 20);
285 test -= Vector2d(int_min, int_min);
286 EXPECT_EQ(test, max_vector);
287
288 test = Vector2d(-10, -20);
289 test -= Vector2d(int_max, int_max);
290 EXPECT_EQ(test, min_vector);
291 }
292
252 } // namespace gfx 293 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/geometry/vector2d.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698