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 | 14 |
15 TEST(InputTest, Equals) { | 15 TEST(InputTest, Equals) { |
16 Input test(kInput, arraysize(kInput)); | 16 Input test(kInput, arraysize(kInput)); |
17 Input test2(kInput, arraysize(kInput)); | 17 Input test2(kInput, arraysize(kInput)); |
18 EXPECT_TRUE(test.Equals(test2)); | 18 EXPECT_TRUE(test.Equals(test2)); |
19 | 19 |
20 std::string input_copy(reinterpret_cast<const char*>(kInput), | 20 std::string input_copy(reinterpret_cast<const char*>(kInput), |
21 arraysize(kInput)); | 21 arraysize(kInput)); |
22 Input test_copy(input_copy); | 22 Input test_copy(input_copy); |
23 EXPECT_TRUE(test.Equals(test_copy)); | 23 EXPECT_TRUE(test.Equals(test_copy)); |
24 | 24 |
25 Input test_truncated(kInput, arraysize(kInput) - 1); | 25 Input test_truncated(kInput, arraysize(kInput) - 1); |
26 EXPECT_FALSE(test.Equals(test_truncated)); | 26 EXPECT_FALSE(test.Equals(test_truncated)); |
27 EXPECT_FALSE(test_truncated.Equals(test)); | 27 EXPECT_FALSE(test_truncated.Equals(test)); |
28 } | 28 } |
29 | 29 |
| 30 TEST(InputTest, StaticArray) { |
| 31 Input input(kInput); |
| 32 EXPECT_EQ(arraysize(kInput), input.Length()); |
| 33 |
| 34 Input input2(kInput, arraysize(kInput)); |
| 35 EXPECT_TRUE(input.Equals(input2)); |
| 36 } |
| 37 |
30 TEST(ByteReaderTest, NoReadPastEnd) { | 38 TEST(ByteReaderTest, NoReadPastEnd) { |
31 ByteReader reader(Input(nullptr, 0)); | 39 ByteReader reader(Input(nullptr, 0)); |
32 uint8_t data; | 40 uint8_t data; |
33 EXPECT_FALSE(reader.ReadByte(&data)); | 41 EXPECT_FALSE(reader.ReadByte(&data)); |
34 } | 42 } |
35 | 43 |
36 TEST(ByteReaderTest, ReadToEnd) { | 44 TEST(ByteReaderTest, ReadToEnd) { |
37 uint8_t out; | 45 uint8_t out; |
38 ByteReader reader(Input(kInput, arraysize(kInput))); | 46 ByteReader reader(Input(kInput, arraysize(kInput))); |
39 for (size_t i = 0; i < arraysize(kInput); ++i) { | 47 for (size_t i = 0; i < arraysize(kInput); ++i) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 reader1 = ByteReader(in1); | 139 reader1 = ByteReader(in1); |
132 reader2 = ByteReader(in2); | 140 reader2 = ByteReader(in2); |
133 | 141 |
134 ASSERT_FALSE(reader1.AdvanceToMark(mark2)); | 142 ASSERT_FALSE(reader1.AdvanceToMark(mark2)); |
135 ASSERT_FALSE(reader2.AdvanceToMark(mark1)); | 143 ASSERT_FALSE(reader2.AdvanceToMark(mark1)); |
136 } | 144 } |
137 | 145 |
138 } // namespace test | 146 } // namespace test |
139 } // namespace der | 147 } // namespace der |
140 } // namespace net | 148 } // namespace net |
OLD | NEW |