proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
HTTPCommonHeadersTests.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2015-present, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
*/
10
#include <
folly/portability/GTest.h
>
11
#include <
proxygen/lib/http/HTTPCommonHeaders.h
>
12
13
using namespace
proxygen
;
14
15
class
HTTPCommonHeadersTests
:
public
testing::Test
{
16
};
17
18
TEST_F
(
HTTPCommonHeadersTests
, TestHashing) {
19
std::string
common1(
"Content-Length"
);
20
std::string
common2(
"content-length"
);
21
std::string
uncommon(
"Uncommon"
);
22
23
HTTPHeaderCode
commonCode1 =
HTTPCommonHeaders::hash
(common1);
24
HTTPHeaderCode
commonCode2 =
HTTPCommonHeaders::hash
(common2);
25
HTTPHeaderCode
uncommonCode =
HTTPCommonHeaders::hash
(uncommon);
26
27
EXPECT_EQ
(uncommonCode,
HTTPHeaderCode::HTTP_HEADER_OTHER
);
28
EXPECT_NE
(commonCode1,
HTTPHeaderCode::HTTP_HEADER_OTHER
);
29
30
EXPECT_EQ
(commonCode1, commonCode2);
31
}
32
33
TEST_F
(
HTTPCommonHeadersTests
, TestTwoTablesInitialized) {
34
std::string
common
(
"Content-Length"
);
35
HTTPHeaderCode
code =
HTTPCommonHeaders::hash
(common);
36
37
EXPECT_EQ
(*
HTTPCommonHeaders::getPointerToHeaderName
(code),
"Content-Length"
);
38
EXPECT_EQ
(
39
*
HTTPCommonHeaders::getPointerToHeaderName
(
40
code,
HTTPCommonHeaderTableType::TABLE_LOWERCASE
),
"content-length"
);
41
}
42
43
TEST_F
(
HTTPCommonHeadersTests
, TestIsCommonHeaderNameFromTable) {
44
// The first two hardcoded headers are not considered actual common headers
45
EXPECT_FALSE
(
46
HTTPCommonHeaders::isHeaderNameFromTable
(
47
HTTPCommonHeaders::getPointerToHeaderName
(
HTTP_HEADER_NONE
),
48
TABLE_CAMELCASE
));
49
EXPECT_FALSE
(
50
HTTPCommonHeaders::isHeaderNameFromTable
(
51
HTTPCommonHeaders::getPointerToHeaderName
(
HTTP_HEADER_OTHER
),
52
TABLE_CAMELCASE
));
53
54
// Verify that the first actual common header in the address table checks out
55
// Assuming there is at least one common header in the table (first two
56
// entries are HTTP_HEADER_NONE and HTTP_HEADER_OTHER)
57
if
(
HTTPCommonHeaders::num_header_codes
>
HTTPHeaderCodeCommonOffset
) {
58
EXPECT_TRUE
(
59
HTTPCommonHeaders::isHeaderNameFromTable
(
60
HTTPCommonHeaders::getPointerToHeaderName
(
61
static_cast<HTTPHeaderCode>(
HTTPHeaderCodeCommonOffset
+ 1)),
62
TABLE_CAMELCASE
));
63
64
// Verify that the last header in the common address table checks out
65
EXPECT_TRUE
(
66
HTTPCommonHeaders::isHeaderNameFromTable
(
67
HTTPCommonHeaders::getPointerToHeaderName
(
68
static_cast<HTTPHeaderCode>(
69
HTTPCommonHeaders::num_header_codes
- 1)),
TABLE_CAMELCASE
));
70
}
71
72
// Verify that a random header is not identified as being part of the common
73
// address table
74
std::string
externalHeader =
"externalHeader"
;
75
EXPECT_FALSE
(
HTTPCommonHeaders::isHeaderNameFromTable
(
76
&externalHeader,
TABLE_CAMELCASE
));
77
}
78
79
TEST_F
(
HTTPCommonHeadersTests
, TestGetHeaderCodeFromTableCommonHeaderName) {
80
for
(
uint64_t
j =
HTTPHeaderCodeCommonOffset
;
81
j <
HTTPCommonHeaders::num_header_codes
; ++j) {
82
HTTPHeaderCode
code =
static_cast<
HTTPHeaderCode
>
(j);
83
EXPECT_TRUE
(
84
code ==
85
HTTPCommonHeaders::getHeaderCodeFromTableCommonHeaderName
(
86
HTTPCommonHeaders::getPointerToHeaderName
(code),
TABLE_CAMELCASE
));
87
}
88
std::string
externalHeader =
"externalHeader"
;
89
EXPECT_TRUE
(
HTTP_HEADER_OTHER
==
90
HTTPCommonHeaders::getHeaderCodeFromTableCommonHeaderName
(
91
&externalHeader,
TABLE_CAMELCASE
));
92
}
proxygen::HTTP_HEADER_OTHER
Definition:
HTTPCommonHeaders.h:26
proxygen::TABLE_CAMELCASE
Definition:
HTTPCommonHeaders.h:138
EXPECT_EQ
#define EXPECT_EQ(val1, val2)
Definition:
gtest.h:1922
proxygen::HTTPCommonHeaders::getHeaderCodeFromTableCommonHeaderName
static HTTPHeaderCode getHeaderCodeFromTableCommonHeaderName(const std::string *headerName, HTTPCommonHeaderTableType type)
Definition:
HTTPCommonHeaders.h:172
HTTPCommonHeadersTests
Definition:
HTTPCommonHeadersTests.cpp:15
proxygen::HTTP_HEADER_NONE
Definition:
HTTPCommonHeaders.h:24
GTest.h
testing::Test
Definition:
gtest.h:371
proxygen::HTTPCommonHeaders::isHeaderNameFromTable
static bool isHeaderNameFromTable(const std::string *headerName, HTTPCommonHeaderTableType type)
Definition:
HTTPCommonHeaders.h:162
proxygen::HTTPCommonHeaders::getPointerToHeaderName
static const std::string * getPointerToHeaderName(HTTPHeaderCode code, HTTPCommonHeaderTableType type=TABLE_CAMELCASE)
Definition:
HTTPCommonHeaders.h:157
common
Definition:
common.py:1
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition:
gtest.h:1859
proxygen::HTTPCommonHeaders::num_header_codes
static constexpr uint64_t num_header_codes
Definition:
HTTPCommonHeaders.h:152
string
const char * string
Definition:
Conv.cpp:212
EXPECT_NE
#define EXPECT_NE(val1, val2)
Definition:
gtest.h:1926
uint64_t
uint64_t
Definition:
ConstexprMathBenchmark.cpp:190
proxygen
Definition:
ExMessageHandler.h:14
proxygen::HTTPHeaderCodeCommonOffset
const uint8_t HTTPHeaderCodeCommonOffset
Definition:
HTTPCommonHeaders.h:135
proxygen::HTTPHeaderCode
HTTPHeaderCode
Definition:
HTTPCommonHeaders.h:22
proxygen::TEST_F
TEST_F(HeaderTableTests, IndexTranslation)
Definition:
HeaderTableTests.cpp:54
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition:
gtest.h:1862
proxygen::HTTPCommonHeaders::hash
static FB_EXPORT HTTPHeaderCode hash(const char *name, size_t len)
Definition:
HTTPCommonHeaders.cpp:343
HTTPCommonHeaders.h
proxygen::TABLE_LOWERCASE
Definition:
HTTPCommonHeaders.h:139
proxygen
lib
http
test
HTTPCommonHeadersTests.cpp
Generated by
1.8.11