- add sources.
[platform/framework/web/crosswalk.git] / src / net / quic / crypto / null_encrypter_test.cc
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
3 // found in the LICENSE file.
4
5 #include "net/quic/crypto/null_encrypter.h"
6 #include "net/quic/test_tools/quic_test_utils.h"
7
8 using base::StringPiece;
9
10 namespace net {
11 namespace test {
12
13 class NullEncrypterTest : public ::testing::TestWithParam<bool> {
14 };
15
16 INSTANTIATE_TEST_CASE_P(HashLength, NullEncrypterTest,
17                         ::testing::Values(false, true));
18
19 TEST_P(NullEncrypterTest, Encrypt) {
20   unsigned char expected[] = {
21     // fnv hash
22     0xa0, 0x6f, 0x44, 0x8a,
23     0x44, 0xf8, 0x18, 0x3b,
24     0x47, 0x91, 0xb2, 0x13,
25     0x6b, 0x09, 0xbb, 0xae,
26     // payload
27     'g',  'o',  'o',  'd',
28     'b',  'y',  'e',  '!',
29   };
30   unsigned char expected_short[] = {
31     // fnv hash
32     0xa0, 0x6f, 0x44, 0x8a,
33     0x44, 0xf8, 0x18, 0x3b,
34     0x47, 0x91, 0xb2, 0x13,
35     // payload
36     'g',  'o',  'o',  'd',
37     'b',  'y',  'e',  '!',
38   };
39   NullEncrypter encrypter(GetParam());
40   scoped_ptr<QuicData> encrypted(
41       encrypter.EncryptPacket(0, "hello world!", "goodbye!"));
42   ASSERT_TRUE(encrypted.get());
43   if (GetParam()) {
44     test::CompareCharArraysWithHexError(
45         "encrypted data", encrypted->data(), encrypted->length(),
46         reinterpret_cast<const char*>(expected_short),
47         arraysize(expected_short));
48   } else {
49     test::CompareCharArraysWithHexError(
50         "encrypted data", encrypted->data(), encrypted->length(),
51         reinterpret_cast<const char*>(expected), arraysize(expected));
52   }
53 }
54
55 TEST_P(NullEncrypterTest, GetMaxPlaintextSize) {
56   NullEncrypter encrypter(GetParam());
57   if (GetParam()) {
58     EXPECT_EQ(1000u, encrypter.GetMaxPlaintextSize(1012));
59     EXPECT_EQ(100u, encrypter.GetMaxPlaintextSize(112));
60     EXPECT_EQ(10u, encrypter.GetMaxPlaintextSize(22));
61   } else {
62     EXPECT_EQ(1000u, encrypter.GetMaxPlaintextSize(1016));
63     EXPECT_EQ(100u, encrypter.GetMaxPlaintextSize(116));
64     EXPECT_EQ(10u, encrypter.GetMaxPlaintextSize(26));
65   }
66 }
67
68 TEST_P(NullEncrypterTest, GetCiphertextSize) {
69   NullEncrypter encrypter(GetParam());
70   if (GetParam()) {
71     EXPECT_EQ(1012u, encrypter.GetCiphertextSize(1000));
72     EXPECT_EQ(112u, encrypter.GetCiphertextSize(100));
73     EXPECT_EQ(22u, encrypter.GetCiphertextSize(10));
74   } else {
75     EXPECT_EQ(1016u, encrypter.GetCiphertextSize(1000));
76     EXPECT_EQ(116u, encrypter.GetCiphertextSize(100));
77     EXPECT_EQ(26u, encrypter.GetCiphertextSize(10));
78   }
79 }
80
81 }  // namespace test
82 }  // namespace net