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

Unified Diff: webrtc/base/helpers_unittest.cc

Issue 2115793003: Check that table evenly divides 256 when generating random string. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 4 years, 4 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 | « webrtc/base/helpers.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/helpers_unittest.cc
diff --git a/webrtc/base/helpers_unittest.cc b/webrtc/base/helpers_unittest.cc
index e4903f58694b83613b8d4c9748e7d57839d1981f..394e2b0dd47d8904967e7eacdf5cece709a4a74b 100644
--- a/webrtc/base/helpers_unittest.cc
+++ b/webrtc/base/helpers_unittest.cc
@@ -55,6 +55,17 @@ TEST_F(RandomTest, TestCreateRandomData) {
EXPECT_NE(0, memcmp(random1.data(), random2.data(), kRandomDataLength));
}
+TEST_F(RandomTest, TestCreateRandomStringEvenlyDivideTable) {
+ static std::string kUnbiasedTable("01234567");
+ std::string random;
+ EXPECT_TRUE(CreateRandomString(256, kUnbiasedTable, &random));
+ EXPECT_EQ(256U, random.size());
+
+ static std::string kBiasedTable("0123456789");
+ EXPECT_FALSE(CreateRandomString(256, kBiasedTable, &random));
+ EXPECT_EQ(0U, random.size());
+}
+
TEST_F(RandomTest, TestCreateRandomUuid) {
std::string random = CreateRandomUuid();
EXPECT_EQ(36U, random.size());
@@ -90,8 +101,8 @@ TEST_F(RandomTest, TestCreateRandomForTest) {
std::string str;
EXPECT_TRUE(CreateRandomString(16, "a", &str));
EXPECT_EQ("aaaaaaaaaaaaaaaa", str);
- EXPECT_TRUE(CreateRandomString(16, "abc", &str));
- EXPECT_EQ("acbccaaaabbaacbb", str);
+ EXPECT_TRUE(CreateRandomString(16, "abcd", &str));
+ EXPECT_EQ("dbaaabdaccbcabbd", str);
// Turn off test mode for other tests.
SetRandomTestMode(false);
« no previous file with comments | « webrtc/base/helpers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698