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

Side by Side Diff: webrtc/base/helpers_unittest.cc

Issue 1528843005: Add support for GCM cipher suites from RFC 7714. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Feedback from Matt Created 4 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 unified diff | Download patch
OLDNEW
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
11 #include <string> 11 #include <string>
12 12
13 #include "webrtc/base/buffer.h"
13 #include "webrtc/base/gunit.h" 14 #include "webrtc/base/gunit.h"
14 #include "webrtc/base/helpers.h" 15 #include "webrtc/base/helpers.h"
15 #include "webrtc/base/ssladapter.h" 16 #include "webrtc/base/ssladapter.h"
16 17
17 namespace rtc { 18 namespace rtc {
18 19
19 class RandomTest : public testing::Test {}; 20 class RandomTest : public testing::Test {};
20 21
21 TEST_F(RandomTest, TestCreateRandomId) { 22 TEST_F(RandomTest, TestCreateRandomId) {
22 CreateRandomId(); 23 CreateRandomId();
(...skipping 13 matching lines...) Expand all
36 37
37 TEST_F(RandomTest, TestCreateRandomString) { 38 TEST_F(RandomTest, TestCreateRandomString) {
38 std::string random = CreateRandomString(256); 39 std::string random = CreateRandomString(256);
39 EXPECT_EQ(256U, random.size()); 40 EXPECT_EQ(256U, random.size());
40 std::string random2; 41 std::string random2;
41 EXPECT_TRUE(CreateRandomString(256, &random2)); 42 EXPECT_TRUE(CreateRandomString(256, &random2));
42 EXPECT_NE(random, random2); 43 EXPECT_NE(random, random2);
43 EXPECT_EQ(256U, random2.size()); 44 EXPECT_EQ(256U, random2.size());
44 } 45 }
45 46
47 TEST_F(RandomTest, TestCreateRandomData) {
48 static size_t kRandomDataLength = 32;
49 Buffer random1(kRandomDataLength);
50 Buffer random2(kRandomDataLength);
51 EXPECT_TRUE(CreateRandomData(kRandomDataLength, random1.data()));
52 EXPECT_TRUE(CreateRandomData(kRandomDataLength, random2.data()));
53 EXPECT_NE(0, memcmp(random1.data(), random2.data(), kRandomDataLength));
54 }
55
46 TEST_F(RandomTest, TestCreateRandomUuid) { 56 TEST_F(RandomTest, TestCreateRandomUuid) {
47 std::string random = CreateRandomUuid(); 57 std::string random = CreateRandomUuid();
48 EXPECT_EQ(36U, random.size()); 58 EXPECT_EQ(36U, random.size());
49 } 59 }
50 60
51 TEST_F(RandomTest, TestCreateRandomForTest) { 61 TEST_F(RandomTest, TestCreateRandomForTest) {
52 // Make sure we get the output we expect. 62 // Make sure we get the output we expect.
53 SetRandomTestMode(true); 63 SetRandomTestMode(true);
54 EXPECT_EQ(2154761789U, CreateRandomId()); 64 EXPECT_EQ(2154761789U, CreateRandomId());
55 EXPECT_EQ("h0ISP4S5SJKH/9EY", CreateRandomString(16)); 65 EXPECT_EQ("h0ISP4S5SJKH/9EY", CreateRandomString(16));
56 EXPECT_EQ("41706e92-cdd3-46d9-a22d-8ff1737ffb11", CreateRandomUuid()); 66 EXPECT_EQ("41706e92-cdd3-46d9-a22d-8ff1737ffb11", CreateRandomUuid());
67 static size_t kRandomDataLength = 32;
68 Buffer random(kRandomDataLength);
69 EXPECT_TRUE(CreateRandomData(kRandomDataLength, random.data()));
70 Buffer expected("\xbd\x52\x2a\x4b\x97\x93\x2f\x1c"
71 "\xc4\x72\xab\xa2\x88\x68\x3e\xcc"
72 "\xa3\x8d\xaf\x13\x3b\xbc\x83\xbb"
73 "\x16\xf1\xcf\x56\x0c\xf5\x4a\x8b", kRandomDataLength);
74 EXPECT_EQ(0, memcmp(expected.data(), random.data(), kRandomDataLength));
57 75
58 // Reset and make sure we get the same output. 76 // Reset and make sure we get the same output.
59 SetRandomTestMode(true); 77 SetRandomTestMode(true);
60 EXPECT_EQ(2154761789U, CreateRandomId()); 78 EXPECT_EQ(2154761789U, CreateRandomId());
61 EXPECT_EQ("h0ISP4S5SJKH/9EY", CreateRandomString(16)); 79 EXPECT_EQ("h0ISP4S5SJKH/9EY", CreateRandomString(16));
62 EXPECT_EQ("41706e92-cdd3-46d9-a22d-8ff1737ffb11", CreateRandomUuid()); 80 EXPECT_EQ("41706e92-cdd3-46d9-a22d-8ff1737ffb11", CreateRandomUuid());
81 EXPECT_TRUE(CreateRandomData(kRandomDataLength, random.data()));
82 EXPECT_EQ(0, memcmp(expected.data(), random.data(), kRandomDataLength));
63 83
64 // Test different character sets. 84 // Test different character sets.
65 SetRandomTestMode(true); 85 SetRandomTestMode(true);
66 std::string str; 86 std::string str;
67 EXPECT_TRUE(CreateRandomString(16, "a", &str)); 87 EXPECT_TRUE(CreateRandomString(16, "a", &str));
68 EXPECT_EQ("aaaaaaaaaaaaaaaa", str); 88 EXPECT_EQ("aaaaaaaaaaaaaaaa", str);
69 EXPECT_TRUE(CreateRandomString(16, "abc", &str)); 89 EXPECT_TRUE(CreateRandomString(16, "abc", &str));
70 EXPECT_EQ("acbccaaaabbaacbb", str); 90 EXPECT_EQ("acbccaaaabbaacbb", str);
71 91
72 // Turn off test mode for other tests. 92 // Turn off test mode for other tests.
73 SetRandomTestMode(false); 93 SetRandomTestMode(false);
74 } 94 }
75 95
76 } // namespace rtc 96 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698