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

Side by Side Diff: third_party/WebKit/Source/platform/LayoutUnitTest.cpp

Issue 2160983007: Avoid integer overflow in LayoutUnit's unary minus operator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Full UnaryMinus test case Created 4 years, 5 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 | « third_party/WebKit/Source/platform/LayoutUnit.h ('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 /* 1 /*
2 * Copyright (c) 2012, Google Inc. All rights reserved. 2 * Copyright (c) 2012, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 249
250 TEST(LayoutUnitTest, LayoutUnitFloatOverflow) 250 TEST(LayoutUnitTest, LayoutUnitFloatOverflow)
251 { 251 {
252 // These should overflow to the max/min according to their sign. 252 // These should overflow to the max/min according to their sign.
253 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(176972000.0f).toInt()); 253 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(176972000.0f).toInt());
254 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(-176972000.0f).toInt()); 254 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(-176972000.0f).toInt());
255 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(176972000.0).toInt()); 255 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(176972000.0).toInt());
256 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(-176972000.0).toInt()); 256 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(-176972000.0).toInt());
257 } 257 }
258 258
259 TEST(LayoutUnitTest, UnaryMinus)
260 {
261 EXPECT_EQ(LayoutUnit(), -LayoutUnit());
262 EXPECT_EQ(LayoutUnit(999), -LayoutUnit(-999));
263 EXPECT_EQ(LayoutUnit(-999), -LayoutUnit(999));
264
265 LayoutUnit negativeMax;
266 negativeMax.setRawValue(LayoutUnit::min().rawValue() + 1);
267 EXPECT_EQ(negativeMax, -LayoutUnit::max());
268 EXPECT_EQ(LayoutUnit::max(), -negativeMax);
269
270 // -LayoutUnit::min() is saturated to LayoutUnit::max()
271 EXPECT_EQ(LayoutUnit::max(), -LayoutUnit::min());
272 }
273
259 } // namespace blink 274 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/LayoutUnit.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698