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

Unified Diff: base/rand_util_unittest.cc

Issue 1419703005: Add missing overflow handling to base::RandInt(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stdint hyyyyyyype Created 5 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 | « base/rand_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/rand_util_unittest.cc
diff --git a/base/rand_util_unittest.cc b/base/rand_util_unittest.cc
index 90690ec2dbb6464041e2e89e93fe606fd5c61cfa..689b8ad3967eacb7a3bf6b1d5497cf73137aa6a3 100644
--- a/base/rand_util_unittest.cc
+++ b/base/rand_util_unittest.cc
@@ -19,10 +19,16 @@ const int kIntMax = std::numeric_limits<int>::max();
} // namespace
-TEST(RandUtilTest, SameMinAndMax) {
+TEST(RandUtilTest, RandInt) {
EXPECT_EQ(base::RandInt(0, 0), 0);
EXPECT_EQ(base::RandInt(kIntMin, kIntMin), kIntMin);
EXPECT_EQ(base::RandInt(kIntMax, kIntMax), kIntMax);
+
+ // Check that the DCHECKS in RandInt() don't fire due to internal overflow.
+ // There was a 50% chance of that happening, so calling it 40 times means
+ // the chances of this passing by accident are tiny (9e-13).
+ for (int i = 0; i < 40; ++i)
+ base::RandInt(kIntMin, kIntMax);
}
TEST(RandUtilTest, RandDouble) {
« no previous file with comments | « base/rand_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698