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

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

Issue 2832973003: Split net/spdy into core and chromium subdirectories. (Closed)
Patch Set: Fix some more build rules. Created 3 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_pinnable_buffer_piece.cc ('k') | net/spdy/spdy_prefixed_buffer_reader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/spdy/spdy_pinnable_buffer_piece.h"
6
7 #include "net/spdy/platform/api/spdy_string.h"
8 #include "net/spdy/spdy_prefixed_buffer_reader.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace net {
12
13 namespace test {
14
15 class SpdyPinnableBufferPieceTest : public ::testing::Test {
16 protected:
17 SpdyPrefixedBufferReader Build(const SpdyString& prefix,
18 const SpdyString& suffix) {
19 prefix_ = prefix;
20 suffix_ = suffix;
21 return SpdyPrefixedBufferReader(prefix_.data(), prefix_.length(),
22 suffix_.data(), suffix_.length());
23 }
24 SpdyString prefix_, suffix_;
25 };
26
27 TEST_F(SpdyPinnableBufferPieceTest, Pin) {
28 SpdyPrefixedBufferReader reader = Build("foobar", "");
29 SpdyPinnableBufferPiece piece;
30 EXPECT_TRUE(reader.ReadN(6, &piece));
31
32 // Piece points to underlying prefix storage.
33 EXPECT_EQ(SpdyStringPiece("foobar"), SpdyStringPiece(piece));
34 EXPECT_FALSE(piece.IsPinned());
35 EXPECT_EQ(prefix_.data(), piece.buffer());
36
37 piece.Pin();
38
39 // Piece now points to allocated storage.
40 EXPECT_EQ(SpdyStringPiece("foobar"), SpdyStringPiece(piece));
41 EXPECT_TRUE(piece.IsPinned());
42 EXPECT_NE(prefix_.data(), piece.buffer());
43
44 // Pinning again has no effect.
45 const char* buffer = piece.buffer();
46 piece.Pin();
47 EXPECT_EQ(buffer, piece.buffer());
48 }
49
50 TEST_F(SpdyPinnableBufferPieceTest, Swap) {
51 SpdyPrefixedBufferReader reader = Build("foobar", "");
52 SpdyPinnableBufferPiece piece1, piece2;
53 EXPECT_TRUE(reader.ReadN(4, &piece1));
54 EXPECT_TRUE(reader.ReadN(2, &piece2));
55
56 piece1.Pin();
57
58 EXPECT_EQ(SpdyStringPiece("foob"), SpdyStringPiece(piece1));
59 EXPECT_TRUE(piece1.IsPinned());
60 EXPECT_EQ(SpdyStringPiece("ar"), SpdyStringPiece(piece2));
61 EXPECT_FALSE(piece2.IsPinned());
62
63 piece1.Swap(&piece2);
64
65 EXPECT_EQ(SpdyStringPiece("ar"), SpdyStringPiece(piece1));
66 EXPECT_FALSE(piece1.IsPinned());
67 EXPECT_EQ(SpdyStringPiece("foob"), SpdyStringPiece(piece2));
68 EXPECT_TRUE(piece2.IsPinned());
69
70 SpdyPinnableBufferPiece empty;
71 piece2.Swap(&empty);
72
73 EXPECT_EQ(SpdyStringPiece(""), SpdyStringPiece(piece2));
74 EXPECT_FALSE(piece2.IsPinned());
75 }
76
77 } // namespace test
78
79 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_pinnable_buffer_piece.cc ('k') | net/spdy/spdy_prefixed_buffer_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698