| 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); | 16 Input test(kInput); |
| 17 Input test2(kInput); | 17 Input test2(kInput); |
| 18 EXPECT_TRUE(test.Equals(test2)); | 18 EXPECT_TRUE(test.Equals(test2)); |
| 19 | 19 |
| 20 uint8_t input_copy[arraysize(kInput)] = {0}; | 20 uint8_t input_copy[arraysize(kInput)] = {0}; |
| 21 memcpy(input_copy, kInput, 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, AsString) { |
| 31 Input input(kInput); |
| 32 std::string expected_string(reinterpret_cast<const char*>(kInput), |
| 33 arraysize(kInput)); |
| 34 EXPECT_EQ(expected_string, input.AsString()); |
| 35 } |
| 36 |
| 30 TEST(InputTest, StaticArray) { | 37 TEST(InputTest, StaticArray) { |
| 31 Input input(kInput); | 38 Input input(kInput); |
| 32 EXPECT_EQ(arraysize(kInput), input.Length()); | 39 EXPECT_EQ(arraysize(kInput), input.Length()); |
| 33 | 40 |
| 34 Input input2(kInput); | 41 Input input2(kInput); |
| 35 EXPECT_TRUE(input.Equals(input2)); | 42 EXPECT_TRUE(input.Equals(input2)); |
| 36 } | 43 } |
| 37 | 44 |
| 38 TEST(ByteReaderTest, NoReadPastEnd) { | 45 TEST(ByteReaderTest, NoReadPastEnd) { |
| 39 ByteReader reader(Input(nullptr, 0)); | 46 ByteReader reader(Input(nullptr, 0)); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 reader1 = ByteReader(in1); | 148 reader1 = ByteReader(in1); |
| 142 reader2 = ByteReader(in2); | 149 reader2 = ByteReader(in2); |
| 143 | 150 |
| 144 ASSERT_FALSE(reader1.AdvanceToMark(mark2)); | 151 ASSERT_FALSE(reader1.AdvanceToMark(mark2)); |
| 145 ASSERT_FALSE(reader2.AdvanceToMark(mark1)); | 152 ASSERT_FALSE(reader2.AdvanceToMark(mark1)); |
| 146 } | 153 } |
| 147 | 154 |
| 148 } // namespace test | 155 } // namespace test |
| 149 } // namespace der | 156 } // namespace der |
| 150 } // namespace net | 157 } // namespace net |
| OLD | NEW |