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

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: Created 4 years, 6 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
« webrtc/base/helpers.cc ('K') | « 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 83cc68591995b5dfdcb2331e84ac0f3d006ce693..2e7efcf367e2bb0cb4bdd95734ac2de1df913e2f 100644
--- a/webrtc/base/helpers_unittest.cc
+++ b/webrtc/base/helpers_unittest.cc
@@ -43,6 +43,17 @@ TEST_F(RandomTest, TestCreateRandomString) {
EXPECT_EQ(256U, random2.size());
}
+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());
@@ -66,8 +77,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);
« webrtc/base/helpers.cc ('K') | « webrtc/base/helpers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698