| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/spdy/spdy_prefixed_buffer_reader.h" | 5 #include "net/spdy/spdy_prefixed_buffer_reader.h" |
| 6 | 6 |
| 7 #include "net/spdy/platform/api/spdy_string.h" |
| 7 #include "net/spdy/platform/api/spdy_string_piece.h" | 8 #include "net/spdy/platform/api/spdy_string_piece.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 11 |
| 11 namespace net { | 12 namespace net { |
| 12 | 13 |
| 13 namespace test { | 14 namespace test { |
| 14 | 15 |
| 15 using testing::ElementsAreArray; | 16 using testing::ElementsAreArray; |
| 16 | 17 |
| 17 class SpdyPrefixedBufferReaderTest : public ::testing::Test { | 18 class SpdyPrefixedBufferReaderTest : public ::testing::Test { |
| 18 protected: | 19 protected: |
| 19 SpdyPrefixedBufferReader Build(const std::string& prefix, | 20 SpdyPrefixedBufferReader Build(const SpdyString& prefix, |
| 20 const std::string& suffix) { | 21 const SpdyString& suffix) { |
| 21 prefix_ = prefix; | 22 prefix_ = prefix; |
| 22 suffix_ = suffix; | 23 suffix_ = suffix; |
| 23 return SpdyPrefixedBufferReader(prefix_.data(), prefix_.length(), | 24 return SpdyPrefixedBufferReader(prefix_.data(), prefix_.length(), |
| 24 suffix_.data(), suffix_.length()); | 25 suffix_.data(), suffix_.length()); |
| 25 } | 26 } |
| 26 std::string prefix_, suffix_; | 27 SpdyString prefix_, suffix_; |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 TEST_F(SpdyPrefixedBufferReaderTest, ReadRawFromPrefix) { | 30 TEST_F(SpdyPrefixedBufferReaderTest, ReadRawFromPrefix) { |
| 30 SpdyPrefixedBufferReader reader = Build("foobar", ""); | 31 SpdyPrefixedBufferReader reader = Build("foobar", ""); |
| 31 EXPECT_EQ(6u, reader.Available()); | 32 EXPECT_EQ(6u, reader.Available()); |
| 32 | 33 |
| 33 char buffer[] = "123456"; | 34 char buffer[] = "123456"; |
| 34 EXPECT_FALSE(reader.ReadN(10, buffer)); // Not enough buffer. | 35 EXPECT_FALSE(reader.ReadN(10, buffer)); // Not enough buffer. |
| 35 EXPECT_TRUE(reader.ReadN(6, buffer)); | 36 EXPECT_TRUE(reader.ReadN(6, buffer)); |
| 36 EXPECT_THAT(buffer, ElementsAreArray("foobar")); | 37 EXPECT_THAT(buffer, ElementsAreArray("foobar")); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 EXPECT_EQ(1u, reader.Available()); | 122 EXPECT_EQ(1u, reader.Available()); |
| 122 | 123 |
| 123 EXPECT_TRUE(reader.ReadN(1, buffer)); | 124 EXPECT_TRUE(reader.ReadN(1, buffer)); |
| 124 EXPECT_THAT(buffer, ElementsAreArray("lec4")); | 125 EXPECT_THAT(buffer, ElementsAreArray("lec4")); |
| 125 EXPECT_EQ(0u, reader.Available()); | 126 EXPECT_EQ(0u, reader.Available()); |
| 126 } | 127 } |
| 127 | 128 |
| 128 } // namespace test | 129 } // namespace test |
| 129 | 130 |
| 130 } // namespace net | 131 } // namespace net |
| OLD | NEW |