Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: net/spdy/spdy_buffer_unittest.cc

Issue 1852423004: Implement SpdySerializedFrame move semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_buffer.cc ('k') | net/spdy/spdy_frame_builder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « net/spdy/spdy_buffer.cc ('k') | net/spdy/spdy_frame_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698