proxygen
LoggingTests.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  */
11 #include <list>
15 #include <sstream>
16 #include <vector>
17 
18 using namespace proxygen;
19 using namespace std;
20 using namespace testing;
21 
22 class LoggingTests : public testing::Test {
23 };
24 
25 TEST_F(LoggingTests, Refset) {
26  list<uint32_t> refset;
27  refset.push_back(3);
28  refset.push_back(5);
29  stringstream out;
30  out << &refset;
31  EXPECT_EQ(out.str(), "\n[3 5 ]\n");
32 }
33 
34 TEST_F(LoggingTests, DumpHeaderVector) {
35  vector<HPACKHeader> headers;
36  headers.push_back(HPACKHeader(":path", "index.html"));
37  headers.push_back(HPACKHeader("content-type", "gzip"));
38  stringstream out;
39  out << headers;
40  EXPECT_EQ(out.str(), ":path: index.html\ncontent-type: gzip\n\n");
41 }
42 
43 TEST_F(LoggingTests, PrintDelta) {
44  vector<HPACKHeader> v1;
45  v1.push_back(HPACKHeader(":path", "/"));
46  v1.push_back(HPACKHeader(":host", "www.facebook.com"));
47  vector<HPACKHeader> v2;
48 
49  // empty v1 or v2
50  EXPECT_EQ(printDelta(v1, v2), "\n + :path: /\n + :host: www.facebook.com\n");
51  EXPECT_EQ(printDelta(v2, v1), "\n - :path: /\n - :host: www.facebook.com\n");
52 
53  // skip first header from v1
54  v2.push_back(HPACKHeader(":path", "/"));
55  EXPECT_EQ(printDelta(v1, v2), "\n + :host: www.facebook.com\n");
56 
57  v2.push_back(HPACKHeader(":path", "/"));
58  EXPECT_EQ(printDelta(v2, v1),
59  "\n - :host: www.facebook.com\n + :path: / (duplicate)\n");
60 
61  v2.pop_back();
62  v1.clear();
63  v1.push_back(HPACKHeader(":a", "b"));
64  v1.push_back(HPACKHeader(":a", "b"));
65  v1.push_back(HPACKHeader(":path", "/"));
66  EXPECT_EQ(printDelta(v1, v2), "\n + :a: b\n duplicate :a: b\n");
67 }
68 
69 TEST_F(LoggingTests, DumpBin) {
70  // test with an HPACKEncodeBuffer
71  HPACKEncodeBuffer buf(128);
72  buf.encodeLiteral("test");
73  EXPECT_EQ(buf.toBin(),
74  "00000100 01110100 t 01100101 e 01110011 s 01110100 t \n");
75 }
uint32_t encodeLiteral(folly::StringPiece literal)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
STL namespace.
string printDelta(const vector< HPACKHeader > &v1, const vector< HPACKHeader > &v2)
Definition: Logging.cpp:38
TEST_F(HeaderTableTests, IndexTranslation)