xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/http2/test_tools/hpack_example_test.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 #include "quiche/http2/test_tools/hpack_example.h"
2 
3 // Tests of HpackExampleToStringOrDie.
4 
5 #include "quiche/common/platform/api/quiche_test.h"
6 
7 namespace http2 {
8 namespace test {
9 namespace {
10 
TEST(HpackExampleToStringOrDie,GoodInput)11 TEST(HpackExampleToStringOrDie, GoodInput) {
12   std::string bytes = HpackExampleToStringOrDie(R"(
13       40                                      | == Literal never indexed ==
14                                               | Blank lines are OK in example:
15 
16       08                                      |   Literal name (len = 8)
17       7061 7373 776f 7264                     | password
18       06                                      |   Literal value (len = 6)
19       7365 6372 6574                          | secret
20                                               | -> password: secret
21       )");
22 
23   // clang-format off
24   const char kExpected[] = {
25     0x40,                      // Never Indexed, Literal Name and Value
26     0x08,                      //  Name Len: 8
27     0x70, 0x61, 0x73, 0x73,    //      Name: password
28     0x77, 0x6f, 0x72, 0x64,    //
29     0x06,                      // Value Len: 6
30     0x73, 0x65, 0x63, 0x72,    //     Value: secret
31     0x65, 0x74,                //
32   };
33   // clang-format on
34   EXPECT_EQ(absl::string_view(kExpected, sizeof kExpected), bytes);
35 }
36 
37 #ifdef GTEST_HAS_DEATH_TEST
TEST(HpackExampleToStringOrDie,InvalidInput)38 TEST(HpackExampleToStringOrDie, InvalidInput) {
39   EXPECT_QUICHE_DEATH(HpackExampleToStringOrDie("4"), "Truncated");
40   EXPECT_QUICHE_DEATH(HpackExampleToStringOrDie("4x"), "half");
41   EXPECT_QUICHE_DEATH(HpackExampleToStringOrDie(""), "empty");
42 }
43 #endif
44 
45 }  // namespace
46 }  // namespace test
47 }  // namespace http2
48