Chromium Code Reviews| 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)); |
|
Ryan Sleevi
2015/05/26 18:53:30
It's unclear what this is testing or why it's nece
nharper
2015/05/26 22:11:49
It's testing that 2 Inputs are equal that point to
| |
| 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); |
| 32 EXPECT_EQ(arraysize(kInput), input.Length()); | 32 EXPECT_EQ(arraysize(kInput), input.Length()); |
| 33 | 33 |
| 34 Input input2(kInput, arraysize(kInput)); | 34 Input input2(kInput, arraysize(kInput)); |
| 35 EXPECT_TRUE(input.Equals(input2)); | 35 EXPECT_TRUE(input.Equals(input2)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 TEST(InputTest, FromCString) { | |
| 39 Input from_array(kInput); | |
| 40 Input from_string = Input::FromCString("test"); | |
| 41 EXPECT_TRUE(from_array.Equals(from_string)); | |
| 42 | |
| 43 Input zero_length = Input::FromCString(""); | |
| 44 EXPECT_EQ(0u, zero_length.Length()); | |
| 45 } | |
| 46 | |
| 38 TEST(ByteReaderTest, NoReadPastEnd) { | 47 TEST(ByteReaderTest, NoReadPastEnd) { |
| 39 ByteReader reader(Input(nullptr, 0)); | 48 ByteReader reader(Input(nullptr, 0)); |
| 40 uint8_t data; | 49 uint8_t data; |
| 41 EXPECT_FALSE(reader.ReadByte(&data)); | 50 EXPECT_FALSE(reader.ReadByte(&data)); |
| 42 } | 51 } |
| 43 | 52 |
| 44 TEST(ByteReaderTest, ReadToEnd) { | 53 TEST(ByteReaderTest, ReadToEnd) { |
| 45 uint8_t out; | 54 uint8_t out; |
| 46 ByteReader reader(Input(kInput, arraysize(kInput))); | 55 ByteReader reader(Input(kInput, arraysize(kInput))); |
| 47 for (size_t i = 0; i < arraysize(kInput); ++i) { | 56 for (size_t i = 0; i < arraysize(kInput); ++i) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 78 | 87 |
| 79 // Reset the reader and check that we can read to a mark previously set. | 88 // Reset the reader and check that we can read to a mark previously set. |
| 80 reader = ByteReader(input); | 89 reader = ByteReader(input); |
| 81 Input marked_data; | 90 Input marked_data; |
| 82 ASSERT_TRUE(reader.ReadToMark(mark, &marked_data)); | 91 ASSERT_TRUE(reader.ReadToMark(mark, &marked_data)); |
| 83 } | 92 } |
| 84 | 93 |
| 85 TEST(ByteReaderTest, CantReadToWrongMark) { | 94 TEST(ByteReaderTest, CantReadToWrongMark) { |
| 86 Input out; | 95 Input out; |
| 87 Input in1(kInput, arraysize(kInput)); | 96 Input in1(kInput, arraysize(kInput)); |
| 88 Input in2("test"); | 97 Input in2 = Input::FromCString("test"); |
| 89 ByteReader reader1(in1); | 98 ByteReader reader1(in1); |
| 90 ByteReader reader2(in2); | 99 ByteReader reader2(in2); |
| 91 ASSERT_TRUE(reader1.ReadBytes(2, &out)); | 100 ASSERT_TRUE(reader1.ReadBytes(2, &out)); |
| 92 ASSERT_TRUE(reader2.ReadBytes(2, &out)); | 101 ASSERT_TRUE(reader2.ReadBytes(2, &out)); |
| 93 Mark mark1 = reader1.NewMark(); | 102 Mark mark1 = reader1.NewMark(); |
| 94 Mark mark2 = reader2.NewMark(); | 103 Mark mark2 = reader2.NewMark(); |
| 95 reader1 = ByteReader(in1); | 104 reader1 = ByteReader(in1); |
| 96 reader2 = ByteReader(in2); | 105 reader2 = ByteReader(in2); |
| 97 | 106 |
| 98 // It is not possible to advance to a mark outside the underlying input. | 107 // 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); | 148 reader1 = ByteReader(in1); |
| 140 reader2 = ByteReader(in2); | 149 reader2 = ByteReader(in2); |
| 141 | 150 |
| 142 ASSERT_FALSE(reader1.AdvanceToMark(mark2)); | 151 ASSERT_FALSE(reader1.AdvanceToMark(mark2)); |
| 143 ASSERT_FALSE(reader2.AdvanceToMark(mark1)); | 152 ASSERT_FALSE(reader2.AdvanceToMark(mark1)); |
| 144 } | 153 } |
| 145 | 154 |
| 146 } // namespace test | 155 } // namespace test |
| 147 } // namespace der | 156 } // namespace der |
| 148 } // namespace net | 157 } // namespace net |
| OLD | NEW |