OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/crypto/null_encrypter.h" | 5 #include "net/quic/crypto/null_encrypter.h" |
6 #include "net/quic/test_tools/quic_test_utils.h" | 6 #include "net/quic/test_tools/quic_test_utils.h" |
7 | 7 |
8 using base::StringPiece; | 8 using base::StringPiece; |
9 | 9 |
10 namespace net { | 10 namespace net { |
11 namespace test { | 11 namespace test { |
12 | 12 |
13 class NullEncrypterTest : public ::testing::TestWithParam<bool> { | 13 class NullEncrypterTest : public ::testing::TestWithParam<bool> {}; |
14 }; | |
15 | 14 |
16 TEST_F(NullEncrypterTest, Encrypt) { | 15 TEST_F(NullEncrypterTest, Encrypt) { |
17 unsigned char expected[] = { | 16 unsigned char expected[] = {// fnv hash |
18 // fnv hash | 17 0xa0, 0x6f, 0x44, 0x8a, 0x44, 0xf8, 0x18, 0x3b, |
19 0xa0, 0x6f, 0x44, 0x8a, | 18 0x47, 0x91, 0xb2, 0x13, |
20 0x44, 0xf8, 0x18, 0x3b, | 19 // payload |
21 0x47, 0x91, 0xb2, 0x13, | 20 'g', 'o', 'o', 'd', 'b', 'y', 'e', '!', |
22 // payload | |
23 'g', 'o', 'o', 'd', | |
24 'b', 'y', 'e', '!', | |
25 }; | 21 }; |
26 NullEncrypter encrypter; | 22 NullEncrypter encrypter; |
27 scoped_ptr<QuicData> encrypted( | 23 scoped_ptr<QuicData> encrypted( |
28 encrypter.EncryptPacket(0, "hello world!", "goodbye!")); | 24 encrypter.EncryptPacket(0, "hello world!", "goodbye!")); |
29 ASSERT_TRUE(encrypted.get()); | 25 ASSERT_TRUE(encrypted.get()); |
30 test::CompareCharArraysWithHexError( | 26 test::CompareCharArraysWithHexError("encrypted data", |
31 "encrypted data", encrypted->data(), encrypted->length(), | 27 encrypted->data(), |
32 reinterpret_cast<const char*>(expected), | 28 encrypted->length(), |
33 arraysize(expected)); | 29 reinterpret_cast<const char*>(expected), |
| 30 arraysize(expected)); |
34 } | 31 } |
35 | 32 |
36 TEST_F(NullEncrypterTest, GetMaxPlaintextSize) { | 33 TEST_F(NullEncrypterTest, GetMaxPlaintextSize) { |
37 NullEncrypter encrypter; | 34 NullEncrypter encrypter; |
38 EXPECT_EQ(1000u, encrypter.GetMaxPlaintextSize(1012)); | 35 EXPECT_EQ(1000u, encrypter.GetMaxPlaintextSize(1012)); |
39 EXPECT_EQ(100u, encrypter.GetMaxPlaintextSize(112)); | 36 EXPECT_EQ(100u, encrypter.GetMaxPlaintextSize(112)); |
40 EXPECT_EQ(10u, encrypter.GetMaxPlaintextSize(22)); | 37 EXPECT_EQ(10u, encrypter.GetMaxPlaintextSize(22)); |
41 } | 38 } |
42 | 39 |
43 TEST_F(NullEncrypterTest, GetCiphertextSize) { | 40 TEST_F(NullEncrypterTest, GetCiphertextSize) { |
44 NullEncrypter encrypter; | 41 NullEncrypter encrypter; |
45 EXPECT_EQ(1012u, encrypter.GetCiphertextSize(1000)); | 42 EXPECT_EQ(1012u, encrypter.GetCiphertextSize(1000)); |
46 EXPECT_EQ(112u, encrypter.GetCiphertextSize(100)); | 43 EXPECT_EQ(112u, encrypter.GetCiphertextSize(100)); |
47 EXPECT_EQ(22u, encrypter.GetCiphertextSize(10)); | 44 EXPECT_EQ(22u, encrypter.GetCiphertextSize(10)); |
48 } | 45 } |
49 | 46 |
50 } // namespace test | 47 } // namespace test |
51 } // namespace net | 48 } // namespace net |
OLD | NEW |