Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 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 | |
birenroy | 87c3f7e | 2024-07-09 12:09:37 -0700 | [diff] [blame] | 5 | #include "quiche/http2/hpack/hpack_static_table.h" |
Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 6 | |
| 7 | #include <set> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "absl/strings/string_view.h" |
birenroy | 87c3f7e | 2024-07-09 12:09:37 -0700 | [diff] [blame] | 11 | #include "quiche/http2/hpack/hpack_constants.h" |
| 12 | #include "quiche/http2/hpack/hpack_header_table.h" |
Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 13 | #include "quiche/common/platform/api/quiche_test.h" |
Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 14 | |
| 15 | namespace spdy { |
| 16 | |
| 17 | namespace test { |
| 18 | |
| 19 | namespace { |
| 20 | |
bnc | 7ddea9b | 2022-05-18 08:36:18 -0700 | [diff] [blame] | 21 | class HpackStaticTableTest : public quiche::test::QuicheTest { |
Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 22 | protected: |
| 23 | HpackStaticTableTest() : table_() {} |
| 24 | |
| 25 | HpackStaticTable table_; |
| 26 | }; |
| 27 | |
| 28 | // Check that an initialized instance has the right number of entries. |
| 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. |
| 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 |