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

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

Issue 138243003: Implement basic classes for HPACK (HTTP/2 compression) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding license to new HPACK sources. Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/hpack_entry.cc ('k') | net/spdy/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 (c) 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_entry.h"
6
7 #include <string>
8
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace net {
12
13 namespace {
14
15 using std::string;
16
17 const char kName[] = "headername";
18 const uint32 kNameStringLength = arraysize(kName) - 1;
19 const char kValue[] = "Header Value";
20 const uint32 kValueStringLength = arraysize(kValue) - 1;
21
22 // Make sure a default-constructed entry is still valid and starts off
23 // empty, unreferenced, and untouched.
24 TEST(HpackEntryTest, DefaultConstructor) {
25 HpackEntry entry;
26 EXPECT_TRUE(entry.name().empty());
27 EXPECT_TRUE(entry.value().empty());
28 EXPECT_FALSE(entry.IsReferenced());
29 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
30 EXPECT_EQ(HpackEntry::kSizeOverhead, entry.Size());
31 }
32
33 // Make sure a non-default-constructed HpackEntry starts off with
34 // copies of the given name and value, and unreferenced and untouched.
35 TEST(HpackEntryTest, NormalConstructor) {
36 string name = kName;
37 string value = kValue;
38 HpackEntry entry(name, value);
39 EXPECT_EQ(name, entry.name());
40 EXPECT_EQ(value, entry.value());
41
42 ++name[0];
43 ++value[0];
44 EXPECT_NE(name, entry.name());
45 EXPECT_NE(value, entry.name());
46
47 EXPECT_FALSE(entry.IsReferenced());
48 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
49 EXPECT_EQ(
50 kNameStringLength + kValueStringLength + HpackEntry::kSizeOverhead,
51 entry.Size());
52 }
53
54 // Make sure twiddling the referenced bit doesn't affect the touch
55 // count when it's kUntouched.
56 TEST(HpackEntryTest, IsReferencedUntouched) {
57 HpackEntry entry(kName, kValue);
58 EXPECT_FALSE(entry.IsReferenced());
59 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
60
61 entry.SetReferenced(true);
62 EXPECT_TRUE(entry.IsReferenced());
63 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
64
65 entry.SetReferenced(false);
66 EXPECT_FALSE(entry.IsReferenced());
67 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
68 }
69
70 // Make sure changing the touch count doesn't affect the referenced
71 // bit when it's false.
72 TEST(HpackEntryTest, TouchCountNotReferenced) {
73 HpackEntry entry(kName, kValue);
74 EXPECT_FALSE(entry.IsReferenced());
75 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
76
77 entry.AddTouches(0);
78 EXPECT_FALSE(entry.IsReferenced());
79 EXPECT_EQ(0u, entry.TouchCount());
80
81 entry.AddTouches(255);
82 EXPECT_FALSE(entry.IsReferenced());
83 EXPECT_EQ(255u, entry.TouchCount());
84
85 // Assumes kUntouched is 1 + max touch count.
86 entry.AddTouches(HpackEntry::kUntouched - 256);
87 EXPECT_FALSE(entry.IsReferenced());
88 EXPECT_EQ(HpackEntry::kUntouched - 1, entry.TouchCount());
89
90 entry.ClearTouches();
91 EXPECT_FALSE(entry.IsReferenced());
92 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
93 }
94
95 // Make sure changing the touch count doesn't affect the referenced
96 // bit when it's true.
97 TEST(HpackEntryTest, TouchCountReferenced) {
98 HpackEntry entry(kName, kValue);
99 entry.SetReferenced(true);
100 EXPECT_TRUE(entry.IsReferenced());
101 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
102
103 entry.AddTouches(0);
104 EXPECT_TRUE(entry.IsReferenced());
105 EXPECT_EQ(0u, entry.TouchCount());
106
107 entry.AddTouches(255);
108 EXPECT_TRUE(entry.IsReferenced());
109 EXPECT_EQ(255u, entry.TouchCount());
110
111 // Assumes kUntouched is 1 + max touch count.
112 entry.AddTouches(HpackEntry::kUntouched - 256);
113 EXPECT_TRUE(entry.IsReferenced());
114 EXPECT_EQ(HpackEntry::kUntouched - 1, entry.TouchCount());
115
116 entry.ClearTouches();
117 EXPECT_TRUE(entry.IsReferenced());
118 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
119 }
120
121 // Make sure equality takes into account all entry fields.
122 TEST(HpackEntryTest, Equals) {
123 HpackEntry entry1(kName, kValue);
124 HpackEntry entry2(kName, kValue);
125 EXPECT_TRUE(entry1.Equals(entry2));
126
127 entry2.SetReferenced(true);
128 EXPECT_FALSE(entry1.Equals(entry2));
129 entry2.SetReferenced(false);
130 EXPECT_TRUE(entry1.Equals(entry2));
131
132 entry2.AddTouches(0);
133 EXPECT_FALSE(entry1.Equals(entry2));
134 entry2.ClearTouches();
135 EXPECT_TRUE(entry1.Equals(entry2));
136
137 entry2.AddTouches(1);
138 EXPECT_FALSE(entry1.Equals(entry2));
139 entry2.ClearTouches();
140 EXPECT_TRUE(entry1.Equals(entry2));
141
142 HpackEntry entry3(kName, string(kValue) + kValue);
143 EXPECT_FALSE(entry1.Equals(entry3));
144
145 HpackEntry entry4(string(kName) + kName, kValue);
146 EXPECT_FALSE(entry1.Equals(entry4));
147 }
148
149 } // namespace
150
151 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/hpack_entry.cc ('k') | net/spdy/hpack_header_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698