xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/spdy/core/hpack/hpack_static_table_test.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 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 "quiche/spdy/core/hpack/hpack_static_table.h"
6 
7 #include <set>
8 #include <vector>
9 
10 #include "absl/strings/string_view.h"
11 #include "quiche/common/platform/api/quiche_test.h"
12 #include "quiche/spdy/core/hpack/hpack_constants.h"
13 #include "quiche/spdy/core/hpack/hpack_header_table.h"
14 
15 namespace spdy {
16 
17 namespace test {
18 
19 namespace {
20 
21 class HpackStaticTableTest : public quiche::test::QuicheTest {
22  protected:
HpackStaticTableTest()23   HpackStaticTableTest() : table_() {}
24 
25   HpackStaticTable table_;
26 };
27 
28 // Check that an initialized instance has the right number of entries.
TEST_F(HpackStaticTableTest,Initialize)29 TEST_F(HpackStaticTableTest, Initialize) {
30   EXPECT_FALSE(table_.IsInitialized());
31   table_.Initialize(HpackStaticTableVector().data(),
32                     HpackStaticTableVector().size());
33   EXPECT_TRUE(table_.IsInitialized());
34 
35   const HpackHeaderTable::StaticEntryTable& static_entries =
36       table_.GetStaticEntries();
37   EXPECT_EQ(kStaticTableSize, static_entries.size());
38 
39   const HpackHeaderTable::NameValueToEntryMap& static_index =
40       table_.GetStaticIndex();
41   EXPECT_EQ(kStaticTableSize, static_index.size());
42 
43   const HpackHeaderTable::NameToEntryMap& static_name_index =
44       table_.GetStaticNameIndex();
45   // Count distinct names in static table.
46   std::set<absl::string_view> names;
47   for (const auto& entry : static_entries) {
48     names.insert(entry.name());
49   }
50   EXPECT_EQ(names.size(), static_name_index.size());
51 }
52 
53 // Test that ObtainHpackStaticTable returns the same instance every time.
TEST_F(HpackStaticTableTest,IsSingleton)54 TEST_F(HpackStaticTableTest, IsSingleton) {
55   const HpackStaticTable* static_table_one = &ObtainHpackStaticTable();
56   const HpackStaticTable* static_table_two = &ObtainHpackStaticTable();
57   EXPECT_EQ(static_table_one, static_table_two);
58 }
59 
60 }  // namespace
61 
62 }  // namespace test
63 
64 }  // namespace spdy
65