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

Side by Side Diff: net/spdy/hpack/hpack_entry_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/hpack/hpack_entry.cc ('k') | net/spdy/hpack/hpack_header_table.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/hpack/hpack_entry.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace net {
10
11 namespace {
12
13 class HpackEntryTest : public ::testing::Test {
14 protected:
15 HpackEntryTest()
16 : name_("header-name"),
17 value_("header value"),
18 total_insertions_(0),
19 table_size_(0) {}
20
21 // These builders maintain the same external table invariants that a "real"
22 // table (ie HpackHeaderTable) would.
23 HpackEntry StaticEntry() {
24 return HpackEntry(name_, value_, true, total_insertions_++);
25 }
26 HpackEntry DynamicEntry() {
27 ++table_size_;
28 size_t index = total_insertions_++;
29 return HpackEntry(name_, value_, false, index);
30 }
31 void DropEntry() { --table_size_; }
32
33 size_t IndexOf(const HpackEntry& entry) const {
34 if (entry.IsStatic()) {
35 return 1 + entry.InsertionIndex() + table_size_;
36 } else {
37 return total_insertions_ - entry.InsertionIndex();
38 }
39 }
40
41 size_t Size() {
42 return name_.size() + value_.size() + HpackEntry::kSizeOverhead;
43 }
44
45 SpdyString name_, value_;
46
47 private:
48 // Referenced by HpackEntry instances.
49 size_t total_insertions_;
50 size_t table_size_;
51 };
52
53 TEST_F(HpackEntryTest, StaticConstructor) {
54 HpackEntry entry(StaticEntry());
55
56 EXPECT_EQ(name_, entry.name());
57 EXPECT_EQ(value_, entry.value());
58 EXPECT_TRUE(entry.IsStatic());
59 EXPECT_EQ(1u, IndexOf(entry));
60 EXPECT_EQ(Size(), entry.Size());
61 }
62
63 TEST_F(HpackEntryTest, DynamicConstructor) {
64 HpackEntry entry(DynamicEntry());
65
66 EXPECT_EQ(name_, entry.name());
67 EXPECT_EQ(value_, entry.value());
68 EXPECT_FALSE(entry.IsStatic());
69 EXPECT_EQ(1u, IndexOf(entry));
70 EXPECT_EQ(Size(), entry.Size());
71 }
72
73 TEST_F(HpackEntryTest, LookupConstructor) {
74 HpackEntry entry(name_, value_);
75
76 EXPECT_EQ(name_, entry.name());
77 EXPECT_EQ(value_, entry.value());
78 EXPECT_FALSE(entry.IsStatic());
79 EXPECT_EQ(0u, IndexOf(entry));
80 EXPECT_EQ(Size(), entry.Size());
81 }
82
83 TEST_F(HpackEntryTest, DefaultConstructor) {
84 HpackEntry entry;
85
86 EXPECT_TRUE(entry.name().empty());
87 EXPECT_TRUE(entry.value().empty());
88 EXPECT_EQ(HpackEntry::kSizeOverhead, entry.Size());
89 }
90
91 TEST_F(HpackEntryTest, IndexUpdate) {
92 HpackEntry static1(StaticEntry());
93 HpackEntry static2(StaticEntry());
94
95 EXPECT_EQ(1u, IndexOf(static1));
96 EXPECT_EQ(2u, IndexOf(static2));
97
98 HpackEntry dynamic1(DynamicEntry());
99 HpackEntry dynamic2(DynamicEntry());
100
101 EXPECT_EQ(1u, IndexOf(dynamic2));
102 EXPECT_EQ(2u, IndexOf(dynamic1));
103 EXPECT_EQ(3u, IndexOf(static1));
104 EXPECT_EQ(4u, IndexOf(static2));
105
106 DropEntry(); // Drops |dynamic1|.
107
108 EXPECT_EQ(1u, IndexOf(dynamic2));
109 EXPECT_EQ(2u, IndexOf(static1));
110 EXPECT_EQ(3u, IndexOf(static2));
111
112 HpackEntry dynamic3(DynamicEntry());
113
114 EXPECT_EQ(1u, IndexOf(dynamic3));
115 EXPECT_EQ(2u, IndexOf(dynamic2));
116 EXPECT_EQ(3u, IndexOf(static1));
117 EXPECT_EQ(4u, IndexOf(static2));
118 }
119
120 } // namespace
121
122 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/hpack/hpack_entry.cc ('k') | net/spdy/hpack/hpack_header_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698