OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "net/der/input.h" | 6 #include "net/der/input.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 namespace der { | 10 namespace der { |
11 namespace test { | 11 namespace test { |
12 | 12 |
13 const uint8_t kInput[] = {'t', 'e', 's', 't'}; | 13 const uint8_t kInput[] = {'t', 'e', 's', 't'}; |
14 const uint8_t kInput2[] = {'t', 'e', 'a', 'l'}; | 14 const uint8_t kInput2[] = {'t', 'e', 'a', 'l'}; |
15 | 15 |
16 TEST(InputTest, Equals) { | 16 TEST(InputTest, Equals) { |
17 Input test(kInput); | 17 Input test(kInput); |
18 Input test2(kInput); | 18 Input test2(kInput); |
19 EXPECT_TRUE(test.Equals(test2)); | 19 EXPECT_EQ(test, test2); |
20 | 20 |
21 uint8_t input_copy[arraysize(kInput)] = {0}; | 21 uint8_t input_copy[arraysize(kInput)] = {0}; |
22 memcpy(input_copy, kInput, arraysize(kInput)); | 22 memcpy(input_copy, kInput, arraysize(kInput)); |
23 Input test_copy(input_copy); | 23 Input test_copy(input_copy); |
24 EXPECT_TRUE(test.Equals(test_copy)); | 24 EXPECT_EQ(test, test_copy); |
25 | 25 |
26 Input test_truncated(kInput, arraysize(kInput) - 1); | 26 Input test_truncated(kInput, arraysize(kInput) - 1); |
27 EXPECT_FALSE(test.Equals(test_truncated)); | 27 EXPECT_NE(test, test_truncated); |
28 EXPECT_FALSE(test_truncated.Equals(test)); | 28 EXPECT_NE(test_truncated, test); |
29 } | 29 } |
30 | 30 |
31 TEST(InputTest, LessThan) { | 31 TEST(InputTest, LessThan) { |
32 Input test(kInput); | 32 Input test(kInput); |
33 EXPECT_FALSE(test < test); | 33 EXPECT_FALSE(test < test); |
34 | 34 |
35 Input test2(kInput2); | 35 Input test2(kInput2); |
36 EXPECT_FALSE(test < test2); | 36 EXPECT_FALSE(test < test2); |
37 EXPECT_TRUE(test2 < test); | 37 EXPECT_TRUE(test2 < test); |
38 | 38 |
39 Input test_truncated(kInput, arraysize(kInput) - 1); | 39 Input test_truncated(kInput, arraysize(kInput) - 1); |
40 EXPECT_FALSE(test < test_truncated); | 40 EXPECT_FALSE(test < test_truncated); |
41 EXPECT_TRUE(test_truncated < test); | 41 EXPECT_TRUE(test_truncated < test); |
42 } | 42 } |
43 | 43 |
44 TEST(InputTest, AsString) { | 44 TEST(InputTest, AsString) { |
45 Input input(kInput); | 45 Input input(kInput); |
46 std::string expected_string(reinterpret_cast<const char*>(kInput), | 46 std::string expected_string(reinterpret_cast<const char*>(kInput), |
47 arraysize(kInput)); | 47 arraysize(kInput)); |
48 EXPECT_EQ(expected_string, input.AsString()); | 48 EXPECT_EQ(expected_string, input.AsString()); |
49 } | 49 } |
50 | 50 |
51 TEST(InputTest, StaticArray) { | 51 TEST(InputTest, StaticArray) { |
52 Input input(kInput); | 52 Input input(kInput); |
53 EXPECT_EQ(arraysize(kInput), input.Length()); | 53 EXPECT_EQ(arraysize(kInput), input.Length()); |
54 | 54 |
55 Input input2(kInput); | 55 Input input2(kInput); |
56 EXPECT_TRUE(input.Equals(input2)); | 56 EXPECT_EQ(input, input2); |
57 } | 57 } |
58 | 58 |
59 TEST(ByteReaderTest, NoReadPastEnd) { | 59 TEST(ByteReaderTest, NoReadPastEnd) { |
60 ByteReader reader(Input(nullptr, 0)); | 60 ByteReader reader(Input(nullptr, 0)); |
61 uint8_t data; | 61 uint8_t data; |
62 EXPECT_FALSE(reader.ReadByte(&data)); | 62 EXPECT_FALSE(reader.ReadByte(&data)); |
63 } | 63 } |
64 | 64 |
65 TEST(ByteReaderTest, ReadToEnd) { | 65 TEST(ByteReaderTest, ReadToEnd) { |
66 uint8_t out; | 66 uint8_t out; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 reader1 = ByteReader(in1); | 162 reader1 = ByteReader(in1); |
163 reader2 = ByteReader(in2); | 163 reader2 = ByteReader(in2); |
164 | 164 |
165 ASSERT_FALSE(reader1.AdvanceToMark(mark2)); | 165 ASSERT_FALSE(reader1.AdvanceToMark(mark2)); |
166 ASSERT_FALSE(reader2.AdvanceToMark(mark1)); | 166 ASSERT_FALSE(reader2.AdvanceToMark(mark1)); |
167 } | 167 } |
168 | 168 |
169 } // namespace test | 169 } // namespace test |
170 } // namespace der | 170 } // namespace der |
171 } // namespace net | 171 } // namespace net |
OLD | NEW |