| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_buffer.h" | 5 #include "net/spdy/spdy_buffer.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 const char kData[] = "hello!\0hi."; | 22 const char kData[] = "hello!\0hi."; |
| 23 const size_t kDataSize = arraysize(kData); | 23 const size_t kDataSize = arraysize(kData); |
| 24 | 24 |
| 25 class SpdyBufferTest : public ::testing::Test {}; | 25 class SpdyBufferTest : public ::testing::Test {}; |
| 26 | 26 |
| 27 // Make a string from the data remaining in |buffer|. | 27 // Make a string from the data remaining in |buffer|. |
| 28 std::string BufferToString(const SpdyBuffer& buffer) { | 28 std::string BufferToString(const SpdyBuffer& buffer) { |
| 29 return std::string(buffer.GetRemainingData(), buffer.GetRemainingSize()); | 29 return std::string(buffer.GetRemainingData(), buffer.GetRemainingSize()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 // Construct a SpdyBuffer from a SpdyFrame and make sure its data | 32 // Construct a SpdyBuffer from a SpdySerializedFrame and make sure its data |
| 33 // points to the frame's underlying data. | 33 // points to the frame's underlying data. |
| 34 TEST_F(SpdyBufferTest, FrameConstructor) { | 34 TEST_F(SpdyBufferTest, FrameConstructor) { |
| 35 SpdyBuffer buffer( | 35 SpdyBuffer buffer(scoped_ptr<SpdySerializedFrame>(new SpdySerializedFrame( |
| 36 scoped_ptr<SpdyFrame>( | 36 const_cast<char*>(kData), kDataSize, false /* owns_buffer */))); |
| 37 new SpdyFrame(const_cast<char*>(kData), kDataSize, | |
| 38 false /* owns_buffer */))); | |
| 39 | 37 |
| 40 EXPECT_EQ(kData, buffer.GetRemainingData()); | 38 EXPECT_EQ(kData, buffer.GetRemainingData()); |
| 41 EXPECT_EQ(kDataSize, buffer.GetRemainingSize()); | 39 EXPECT_EQ(kDataSize, buffer.GetRemainingSize()); |
| 42 } | 40 } |
| 43 | 41 |
| 44 // Construct a SpdyBuffer from a const char*/size_t pair and make sure | 42 // Construct a SpdyBuffer from a const char*/size_t pair and make sure |
| 45 // it makes a copy of the data. | 43 // it makes a copy of the data. |
| 46 TEST_F(SpdyBufferTest, DataConstructor) { | 44 TEST_F(SpdyBufferTest, DataConstructor) { |
| 47 std::string data(kData, kDataSize); | 45 std::string data(kData, kDataSize); |
| 48 SpdyBuffer buffer(data.data(), data.size()); | 46 SpdyBuffer buffer(data.data(), data.size()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 buffer.reset(); | 125 buffer.reset(); |
| 128 | 126 |
| 129 // This will cause a use-after-free error if |io_buffer| doesn't | 127 // This will cause a use-after-free error if |io_buffer| doesn't |
| 130 // outlive |buffer|. | 128 // outlive |buffer|. |
| 131 std::memcpy(io_buffer->data(), kData, kDataSize); | 129 std::memcpy(io_buffer->data(), kData, kDataSize); |
| 132 } | 130 } |
| 133 | 131 |
| 134 } // namespace | 132 } // namespace |
| 135 | 133 |
| 136 } // namespace net | 134 } // namespace net |
| OLD | NEW |