diff options
Diffstat (limited to 'net/spdy/spdy_test_util.cc')
-rw-r--r-- | net/spdy/spdy_test_util.cc | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/net/spdy/spdy_test_util.cc b/net/spdy/spdy_test_util.cc index eaf48c5..8247f3e 100644 --- a/net/spdy/spdy_test_util.cc +++ b/net/spdy/spdy_test_util.cc @@ -13,7 +13,7 @@ namespace net { // |data| is the frame to chop. // |length| is the length of the frame to chop. // |num_chunks| is the number of chunks to create. -MockWrite* ChopFrame(const char* data, int length, int num_chunks) { +MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks) { MockWrite* chunks = new MockWrite[num_chunks]; int chunk_size = length / num_chunks; for (int index = 0; index < num_chunks; index++) { @@ -28,10 +28,35 @@ MockWrite* ChopFrame(const char* data, int length, int num_chunks) { // Chop a SpdyFrame into an array of MockWrites. // |frame| is the frame to chop. // |num_chunks| is the number of chunks to create. -MockWrite* ChopFrame(const spdy::SpdyFrame* frame, int num_chunks) { - return ChopFrame(frame->data(), - frame->length() + spdy::SpdyFrame::size(), - num_chunks); +MockWrite* ChopWriteFrame(const spdy::SpdyFrame& frame, int num_chunks) { + return ChopWriteFrame(frame.data(), + frame.length() + spdy::SpdyFrame::size(), + num_chunks); +} + +// Chop a frame into an array of MockReads. +// |data| is the frame to chop. +// |length| is the length of the frame to chop. +// |num_chunks| is the number of chunks to create. +MockRead* ChopReadFrame(const char* data, int length, int num_chunks) { + MockRead* chunks = new MockRead[num_chunks]; + int chunk_size = length / num_chunks; + for (int index = 0; index < num_chunks; index++) { + const char* ptr = data + (index * chunk_size); + if (index == num_chunks - 1) + chunk_size += length % chunk_size; // The last chunk takes the remainder. + chunks[index] = MockRead(true, ptr, chunk_size); + } + return chunks; +} + +// Chop a SpdyFrame into an array of MockReads. +// |frame| is the frame to chop. +// |num_chunks| is the number of chunks to create. +MockRead* ChopReadFrame(const spdy::SpdyFrame& frame, int num_chunks) { + return ChopReadFrame(frame.data(), + frame.length() + spdy::SpdyFrame::size(), + num_chunks); } // Adds headers and values to a map. @@ -439,27 +464,27 @@ int ConstructSpdyReplyString(const char* const extra_headers[], } // Create a MockWrite from the given SpdyFrame. -MockWrite CreateMockWrite(spdy::SpdyFrame* req) { +MockWrite CreateMockWrite(const spdy::SpdyFrame& req) { return MockWrite( - true, req->data(), req->length() + spdy::SpdyFrame::size()); + true, req.data(), req.length() + spdy::SpdyFrame::size()); } // Create a MockWrite from the given SpdyFrame and sequence number. -MockWrite CreateMockWrite(spdy::SpdyFrame* req, int seq) { +MockWrite CreateMockWrite(const spdy::SpdyFrame& req, int seq) { return MockWrite( - true, req->data(), req->length() + spdy::SpdyFrame::size(), seq); + true, req.data(), req.length() + spdy::SpdyFrame::size(), seq); } // Create a MockRead from the given SpdyFrame. -MockRead CreateMockRead(spdy::SpdyFrame* resp) { +MockRead CreateMockRead(const spdy::SpdyFrame& resp) { return MockRead( - true, resp->data(), resp->length() + spdy::SpdyFrame::size()); + true, resp.data(), resp.length() + spdy::SpdyFrame::size()); } // Create a MockRead from the given SpdyFrame and sequence number. -MockRead CreateMockRead(spdy::SpdyFrame* resp, int seq) { +MockRead CreateMockRead(const spdy::SpdyFrame& resp, int seq) { return MockRead( - true, resp->data(), resp->length() + spdy::SpdyFrame::size(), seq); + true, resp.data(), resp.length() + spdy::SpdyFrame::size(), seq); } } // namespace net |