proxygen
HPACKHeaderTests.cpp File Reference

Go to the source code of this file.

Classes

class  HPACKHeaderTests
 
class  HPACKHeaderNameTest
 

Functions

 TEST_F (HPACKHeaderTests, Size)
 
 TEST_F (HPACKHeaderTests, Operators)
 
 TEST_F (HPACKHeaderTests, HasValue)
 
 TEST_F (HPACKHeaderTests, HeaderIndexingStrategyBasic)
 
HPACKHeaderName destroyedHPACKHeaderName (std::string name)
 
 TEST_F (HPACKHeaderNameTest, TestConstructor)
 
 TEST_F (HPACKHeaderNameTest, TestCopyConstructor)
 
 TEST_F (HPACKHeaderNameTest, TestMoveConstructor)
 
 TEST_F (HPACKHeaderNameTest, TestAssignmentOperators)
 
 TEST_F (HPACKHeaderNameTest, TestGetSize)
 
 TEST_F (HPACKHeaderNameTest, TestOperators)
 
 TEST_F (HPACKHeaderNameTest, TestIsCommonHeader)
 

Function Documentation

HPACKHeaderName destroyedHPACKHeaderName ( std::string  name)

Definition at line 71 of file HPACKHeaderTests.cpp.

Referenced by TEST_F().

71  {
72  //return a HPACKHeaderName that goes destroyed
73  HPACKHeaderName headerName(name);
74  return headerName;
75 }
const char * name
Definition: http_parser.c:437
TEST_F ( HPACKHeaderTests  ,
Size   
)

Definition at line 22 of file HPACKHeaderTests.cpp.

References proxygen::HPACKHeader::bytes(), EXPECT_EQ, and h.

22  {
23  HPACKHeader h(":path", "/");
24  EXPECT_EQ(h.bytes(), 32 + 5 + 1);
25 }
*than *hazptr_holder h
Definition: Hazptr.h:116
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST_F ( HPACKHeaderTests  ,
Operators   
)

Definition at line 27 of file HPACKHeaderTests.cpp.

References EXPECT_EQ, EXPECT_FALSE, and EXPECT_TRUE.

27  {
28  HPACKHeader h0(":path", "/");
29  HPACKHeader h1(":path", "/");
30  HPACKHeader h2(":path", "/index.php");
31  HPACKHeader h3("x-fb-debug", "test");
32  // ==
33  EXPECT_TRUE(h0 == h1);
34  EXPECT_FALSE(h1 == h2);
35  // <
36  EXPECT_FALSE(h1 < h1);
37  EXPECT_TRUE(h1 < h2);
38  EXPECT_TRUE(h1 < h3);
39  // >
40  EXPECT_FALSE(h2 > h2);
41  EXPECT_TRUE(h3 > h2);
42  EXPECT_TRUE(h2 > h1);
43 
44  stringstream out;
45  out << h1;
46  EXPECT_EQ(out.str(), ":path: /");
47 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( HPACKHeaderTests  ,
HasValue   
)

Definition at line 49 of file HPACKHeaderTests.cpp.

References EXPECT_FALSE, EXPECT_TRUE, and proxygen::HPACKHeader::hasValue().

49  {
50  HPACKHeader h1(":path", "");
51  HPACKHeader h2(":path", "/");
52  EXPECT_FALSE(h1.hasValue());
53  EXPECT_TRUE(h2.hasValue());
54 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( HPACKHeaderTests  ,
HeaderIndexingStrategyBasic   
)

Definition at line 56 of file HPACKHeaderTests.cpp.

References data, EXPECT_FALSE, EXPECT_TRUE, and proxygen::HeaderIndexingStrategy::indexHeader().

56  {
57  HeaderIndexingStrategy indexingStrat;
58  HPACKHeader path(":path", "index.php?q=42");
59  EXPECT_FALSE(indexingStrat.indexHeader(path));
60  HPACKHeader cdn(":path", "/hprofile-ak-prn1/49496_6024432_1026115112_n.jpg");
61  EXPECT_FALSE(indexingStrat.indexHeader(cdn));
62  HPACKHeader clen("content-length", "512");
63  EXPECT_FALSE(indexingStrat.indexHeader(clen));
64  HPACKHeader data("data", "value");
65  EXPECT_TRUE(indexingStrat.indexHeader(data));
66 }
virtual bool indexHeader(const HPACKHeader &header) const
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
TEST_F ( HPACKHeaderNameTest  ,
TestConstructor   
)

Definition at line 77 of file HPACKHeaderTests.cpp.

References EXPECT_EQ, and proxygen::HPACKHeaderName::get().

77  {
78  // Test constructor
79  HPACKHeaderName name1("accept-encoding");
80  HPACKHeaderName name2("content-length");
81  HPACKHeaderName name3("uncommon-name");
82  HPACKHeaderName name4("uncommon-name-2");
83  EXPECT_EQ(name1.get(), "accept-encoding");
84  EXPECT_EQ(name2.get(), "content-length");
85  EXPECT_EQ(name3.get(), "uncommon-name");
86  EXPECT_EQ(name4.get(), "uncommon-name-2");
87 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST_F ( HPACKHeaderNameTest  ,
TestCopyConstructor   
)

Definition at line 89 of file HPACKHeaderTests.cpp.

References destroyedHPACKHeaderName(), EXPECT_EQ, and proxygen::HPACKHeaderName::get().

89  {
90  HPACKHeaderName name1("accept-encoding");
91  HPACKHeaderName name2("uncommon-name");
92 
93  // Test copy constructor
94  HPACKHeaderName name3(name1);
95  HPACKHeaderName name4(name2);
96  HPACKHeaderName name5(destroyedHPACKHeaderName("x-fb-debug"));
97  HPACKHeaderName name6(destroyedHPACKHeaderName("uncommon-name"));
98  EXPECT_EQ(name3.get(), "accept-encoding");
99  EXPECT_EQ(name4.get(), "uncommon-name");
100  EXPECT_EQ(name5.get(), "x-fb-debug");
101  EXPECT_EQ(name6.get(), "uncommon-name");
102 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
HPACKHeaderName destroyedHPACKHeaderName(std::string name)
TEST_F ( HPACKHeaderNameTest  ,
TestMoveConstructor   
)

Definition at line 104 of file HPACKHeaderTests.cpp.

References EXPECT_EQ, proxygen::HPACKHeaderName::get(), and folly::gen::move.

104  {
105  HPACKHeaderName name1("accept-encoding");
106  HPACKHeaderName name2("uncommon-name");
107 
108  // Test move constructor
109  HPACKHeaderName name3(std::move(name1));
110  HPACKHeaderName name4(std::move(name2));
111  EXPECT_EQ(name3.get(), "accept-encoding");
112  EXPECT_EQ(name4.get(), "uncommon-name");
113 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST_F ( HPACKHeaderNameTest  ,
TestAssignmentOperators   
)

Definition at line 115 of file HPACKHeaderTests.cpp.

References EXPECT_EQ, proxygen::HPACKHeaderName::get(), folly::gen::move, and string.

115  {
116  std::string testHeaderName = "accept-encoding";
117 
118  HPACKHeaderName name1(testHeaderName);
119  EXPECT_EQ(name1.get(), testHeaderName);
120 
121  // Explicitly test some self assignment overloads
122 #ifdef __clang__
123 #pragma clang diagnostic push
124 #pragma clang diagnostic ignored "-Wunknown-warning-option"
125 #pragma clang diagnostic ignored "-Wself-assign-overloaded"
126 #endif
127  name1 = name1;
128 #ifdef __clang__
129 #pragma clang diagnostic pop
130 #endif
131  EXPECT_EQ(name1.get(), testHeaderName);
132  HPACKHeaderName* pName1 = &name1;
133  // Specifically require a temporary above to throw off the compiler/lint:
134  // explicitly moving variable of type 'proxygen::HPACKHeaderName' to itself
135  name1 = std::move(*pName1);
136  EXPECT_EQ(name1.get(), testHeaderName);
137 
138  std::string otherHeaderName = "uncommon-name";
139  HPACKHeaderName name2(otherHeaderName);
140  name1 = name2;
141  EXPECT_EQ(name1.get(), otherHeaderName);
142  EXPECT_EQ(name2.get(), otherHeaderName);
143 
144  HPACKHeaderName name3(testHeaderName);
145  name1 = std::move(name3);
146  EXPECT_EQ(name1.get(), testHeaderName);
147 
148  name1 = otherHeaderName;
149  EXPECT_EQ(name1.get(), otherHeaderName);
150 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const char * string
Definition: Conv.cpp:212
TEST_F ( HPACKHeaderNameTest  ,
TestGetSize   
)

Definition at line 152 of file HPACKHeaderTests.cpp.

References EXPECT_EQ, and proxygen::HPACKHeaderName::size().

152  {
153  // Test size()
154  HPACKHeaderName name1("accept-encoding");
155  HPACKHeaderName name2("uncommon-header_now");
156  EXPECT_EQ(name1.size(), 15);
157  EXPECT_EQ(name2.size(), 19);
158 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST_F ( HPACKHeaderNameTest  ,
TestOperators   
)

Definition at line 160 of file HPACKHeaderTests.cpp.

160  {
161  // Test operators
162  HPACKHeaderName name1("aaa");
163  HPACKHeaderName name2("bbb");
164  HPACKHeaderName name3("aaa");
165  HPACKHeaderName name4("bbb");
166  CHECK(name1 == name3);
167  CHECK(name1 != name2);
168  CHECK(name1 < name2);
169  CHECK(name2 > name1);
170  CHECK(name1 >= name3);
171  CHECK(name2 >= name1);
172  CHECK(name2 <= name4);
173  CHECK(name1 <= name2);
174 }
TEST_F ( HPACKHeaderNameTest  ,
TestIsCommonHeader   
)

Definition at line 176 of file HPACKHeaderTests.cpp.

References EXPECT_EQ, EXPECT_FALSE, proxygen::HTTPCommonHeaders::getPointerToHeaderName(), proxygen::HTTPHeaderCodeCommonOffset, proxygen::HPACKHeaderName::isCommonHeader(), proxygen::HPACKHeader::name, proxygen::HTTPCommonHeaders::num_header_codes, string, and uint64_t.

176  {
177  for (uint64_t j = 0; j < HTTPCommonHeaders::num_header_codes; ++j) {
178  HTTPHeaderCode code = static_cast<HTTPHeaderCode>(j);
179  HPACKHeader testHPACKHeader(
180  *HTTPCommonHeaders::getPointerToHeaderName(code), "");
181 
182  bool checkResult = j >= HTTPHeaderCodeCommonOffset;
183  EXPECT_EQ(testHPACKHeader.name.isCommonHeader(), checkResult);
184  }
185  std::string externalHeader = "externalHeader";
186  HPACKHeader testHPACKHeader(externalHeader, "");
187  EXPECT_FALSE(testHPACKHeader.name.isCommonHeader());
188 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const char * string
Definition: Conv.cpp:212
const uint8_t HTTPHeaderCodeCommonOffset
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862