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 uint8_t input_copy[arraysize(kInput)] = {0}; |
21 arraysize(kInput)); | 21 memcpy(input_copy, kInput, 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) { | 30 TEST(InputTest, StaticArray) { |
31 Input input(kInput); | 31 Input input(kInput); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 // Reset the reader and check that we can read to a mark previously set. | 79 // Reset the reader and check that we can read to a mark previously set. |
80 reader = ByteReader(input); | 80 reader = ByteReader(input); |
81 Input marked_data; | 81 Input marked_data; |
82 ASSERT_TRUE(reader.ReadToMark(mark, &marked_data)); | 82 ASSERT_TRUE(reader.ReadToMark(mark, &marked_data)); |
83 } | 83 } |
84 | 84 |
85 TEST(ByteReaderTest, CantReadToWrongMark) { | 85 TEST(ByteReaderTest, CantReadToWrongMark) { |
86 Input out; | 86 Input out; |
87 Input in1(kInput, arraysize(kInput)); | 87 Input in1(kInput, arraysize(kInput)); |
88 Input in2("test"); | 88 |
| 89 const uint8_t in2_bytes[] = {'t', 'e', 's', 't'}; |
| 90 Input in2(in2_bytes); |
89 ByteReader reader1(in1); | 91 ByteReader reader1(in1); |
90 ByteReader reader2(in2); | 92 ByteReader reader2(in2); |
91 ASSERT_TRUE(reader1.ReadBytes(2, &out)); | 93 ASSERT_TRUE(reader1.ReadBytes(2, &out)); |
92 ASSERT_TRUE(reader2.ReadBytes(2, &out)); | 94 ASSERT_TRUE(reader2.ReadBytes(2, &out)); |
93 Mark mark1 = reader1.NewMark(); | 95 Mark mark1 = reader1.NewMark(); |
94 Mark mark2 = reader2.NewMark(); | 96 Mark mark2 = reader2.NewMark(); |
95 reader1 = ByteReader(in1); | 97 reader1 = ByteReader(in1); |
96 reader2 = ByteReader(in2); | 98 reader2 = ByteReader(in2); |
97 | 99 |
98 // It is not possible to advance to a mark outside the underlying input. | 100 // It is not possible to advance to a mark outside the underlying input. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 reader1 = ByteReader(in1); | 141 reader1 = ByteReader(in1); |
140 reader2 = ByteReader(in2); | 142 reader2 = ByteReader(in2); |
141 | 143 |
142 ASSERT_FALSE(reader1.AdvanceToMark(mark2)); | 144 ASSERT_FALSE(reader1.AdvanceToMark(mark2)); |
143 ASSERT_FALSE(reader2.AdvanceToMark(mark1)); | 145 ASSERT_FALSE(reader2.AdvanceToMark(mark1)); |
144 } | 146 } |
145 | 147 |
146 } // namespace test | 148 } // namespace test |
147 } // namespace der | 149 } // namespace der |
148 } // namespace net | 150 } // namespace net |
OLD | NEW |