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

Unified Diff: base/rand_util_unittest.cc

Issue 6683060: Private API for extensions like ssh-client that need access to TCP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: v Created 9 years, 7 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
Index: base/rand_util_unittest.cc
diff --git a/base/rand_util_unittest.cc b/base/rand_util_unittest.cc
index d7fa37af827e8589299c4a066ef83308ca4a384a..78545d8d5cc79c4d5aa8f2a39a2e76ccd3aca70a 100644
--- a/base/rand_util_unittest.cc
+++ b/base/rand_util_unittest.cc
@@ -4,6 +4,7 @@
#include "base/rand_util.h"
+#include <algorithm>
#include <limits>
#include "testing/gtest/include/gtest/gtest.h"
@@ -29,16 +30,14 @@ TEST(RandUtilTest, RandDouble) {
}
TEST(RandUtilTest, RandBytes) {
- const size_t buffer_size = 145;
+ const size_t buffer_size = 50;
char buffer[buffer_size];
memset(buffer, 0, buffer_size);
base::RandBytes(buffer, buffer_size);
- char accumulator = 0;
- for(size_t i = 0; i < buffer_size; ++i)
- accumulator |= buffer[i];
- // In theory this test can fail, but it won't before the universe dies of
- // heat death.
- EXPECT_NE(0, accumulator);
+ std::sort(buffer, buffer + buffer_size);
+ // Probability of occurrence of less than 25 unique bytes in 50 random bytes
+ // is below 10^-25.
+ EXPECT_GT(std::unique(buffer, buffer + buffer_size) - buffer, 25);
}
TEST(RandUtilTest, RandBytesAsString) {
« no previous file with comments | « no previous file | chrome/browser/chromeos/web_socket_proxy.h » ('j') | chrome/browser/chromeos/web_socket_proxy_controller.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698