summaryrefslogtreecommitdiffstats
path: root/base/rand_util_unittest.cc
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-29 21:03:54 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-29 21:03:54 +0000
commit29548d8d4f224f681c70e85a7fa0466dff4df92f (patch)
tree12cd6faa39cb43e879e907f09ab9734156724ce0 /base/rand_util_unittest.cc
parentdeaa35b7bad1d06f28ed394fb850b4f3dd7bc871 (diff)
downloadchromium_src-29548d8d4f224f681c70e85a7fa0466dff4df92f.zip
chromium_src-29548d8d4f224f681c70e85a7fa0466dff4df92f.tar.gz
chromium_src-29548d8d4f224f681c70e85a7fa0466dff4df92f.tar.bz2
Add a rand_util method for generating a random string.
We need this function to generate a nonce for MAC cookies. Review URL: http://codereview.chromium.org/6904118 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83588 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/rand_util_unittest.cc')
-rw-r--r--base/rand_util_unittest.cc23
1 files changed, 18 insertions, 5 deletions
diff --git a/base/rand_util_unittest.cc b/base/rand_util_unittest.cc
index cbc338a..3bdb815 100644
--- a/base/rand_util_unittest.cc
+++ b/base/rand_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,10 +22,23 @@ TEST(RandUtilTest, SameMinAndMax) {
}
TEST(RandUtilTest, RandDouble) {
- // Force 64-bit precision, making sure we're not in a 80-bit FPU register.
- volatile double number = base::RandDouble();
- EXPECT_GT(1.0, number);
- EXPECT_LE(0.0, number);
+ // Force 64-bit precision, making sure we're not in a 80-bit FPU register.
+ volatile double number = base::RandDouble();
+ EXPECT_GT(1.0, number);
+ EXPECT_LE(0.0, number);
+}
+
+TEST(RandUtilTest, RandBytesAsString) {
+ std::string random_string = base::RandBytesAsString(0);
+ EXPECT_EQ(0U, random_string.size());
+ random_string = base::RandBytesAsString(145);
+ EXPECT_EQ(145U, random_string.size());
+ char accumulator = 0;
+ for (size_t i = 0; i < random_string.size(); ++i)
+ accumulator |= random_string[i];
+ // In theory this test can fail, but it won't before the universe dies of
+ // heat death.
+ EXPECT_NE(0, accumulator);
}
// Make sure that it is still appropriate to use RandGenerator in conjunction