| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 static size_t kRandomDataLength = 32; | 48 static size_t kRandomDataLength = 32; |
| 49 std::string random1; | 49 std::string random1; |
| 50 std::string random2; | 50 std::string random2; |
| 51 EXPECT_TRUE(CreateRandomData(kRandomDataLength, &random1)); | 51 EXPECT_TRUE(CreateRandomData(kRandomDataLength, &random1)); |
| 52 EXPECT_EQ(kRandomDataLength, random1.size()); | 52 EXPECT_EQ(kRandomDataLength, random1.size()); |
| 53 EXPECT_TRUE(CreateRandomData(kRandomDataLength, &random2)); | 53 EXPECT_TRUE(CreateRandomData(kRandomDataLength, &random2)); |
| 54 EXPECT_EQ(kRandomDataLength, random2.size()); | 54 EXPECT_EQ(kRandomDataLength, random2.size()); |
| 55 EXPECT_NE(0, memcmp(random1.data(), random2.data(), kRandomDataLength)); | 55 EXPECT_NE(0, memcmp(random1.data(), random2.data(), kRandomDataLength)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 TEST_F(RandomTest, TestCreateRandomStringEvenlyDivideTable) { |
| 59 static std::string kUnbiasedTable("01234567"); |
| 60 std::string random; |
| 61 EXPECT_TRUE(CreateRandomString(256, kUnbiasedTable, &random)); |
| 62 EXPECT_EQ(256U, random.size()); |
| 63 |
| 64 static std::string kBiasedTable("0123456789"); |
| 65 EXPECT_FALSE(CreateRandomString(256, kBiasedTable, &random)); |
| 66 EXPECT_EQ(0U, random.size()); |
| 67 } |
| 68 |
| 58 TEST_F(RandomTest, TestCreateRandomUuid) { | 69 TEST_F(RandomTest, TestCreateRandomUuid) { |
| 59 std::string random = CreateRandomUuid(); | 70 std::string random = CreateRandomUuid(); |
| 60 EXPECT_EQ(36U, random.size()); | 71 EXPECT_EQ(36U, random.size()); |
| 61 } | 72 } |
| 62 | 73 |
| 63 TEST_F(RandomTest, TestCreateRandomForTest) { | 74 TEST_F(RandomTest, TestCreateRandomForTest) { |
| 64 // Make sure we get the output we expect. | 75 // Make sure we get the output we expect. |
| 65 SetRandomTestMode(true); | 76 SetRandomTestMode(true); |
| 66 EXPECT_EQ(2154761789U, CreateRandomId()); | 77 EXPECT_EQ(2154761789U, CreateRandomId()); |
| 67 EXPECT_EQ("h0ISP4S5SJKH/9EY", CreateRandomString(16)); | 78 EXPECT_EQ("h0ISP4S5SJKH/9EY", CreateRandomString(16)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 EXPECT_EQ("41706e92-cdd3-46d9-a22d-8ff1737ffb11", CreateRandomUuid()); | 94 EXPECT_EQ("41706e92-cdd3-46d9-a22d-8ff1737ffb11", CreateRandomUuid()); |
| 84 EXPECT_TRUE(CreateRandomData(kRandomDataLength, &random)); | 95 EXPECT_TRUE(CreateRandomData(kRandomDataLength, &random)); |
| 85 EXPECT_EQ(kRandomDataLength, random.size()); | 96 EXPECT_EQ(kRandomDataLength, random.size()); |
| 86 EXPECT_EQ(0, memcmp(expected.data(), random.data(), kRandomDataLength)); | 97 EXPECT_EQ(0, memcmp(expected.data(), random.data(), kRandomDataLength)); |
| 87 | 98 |
| 88 // Test different character sets. | 99 // Test different character sets. |
| 89 SetRandomTestMode(true); | 100 SetRandomTestMode(true); |
| 90 std::string str; | 101 std::string str; |
| 91 EXPECT_TRUE(CreateRandomString(16, "a", &str)); | 102 EXPECT_TRUE(CreateRandomString(16, "a", &str)); |
| 92 EXPECT_EQ("aaaaaaaaaaaaaaaa", str); | 103 EXPECT_EQ("aaaaaaaaaaaaaaaa", str); |
| 93 EXPECT_TRUE(CreateRandomString(16, "abc", &str)); | 104 EXPECT_TRUE(CreateRandomString(16, "abcd", &str)); |
| 94 EXPECT_EQ("acbccaaaabbaacbb", str); | 105 EXPECT_EQ("dbaaabdaccbcabbd", str); |
| 95 | 106 |
| 96 // Turn off test mode for other tests. | 107 // Turn off test mode for other tests. |
| 97 SetRandomTestMode(false); | 108 SetRandomTestMode(false); |
| 98 } | 109 } |
| 99 | 110 |
| 100 } // namespace rtc | 111 } // namespace rtc |
| OLD | NEW |