blob: 3863b06d02949f0e56f90f937f00ef3a97bc8b42 [file] [log] [blame]
Bence Békybac04052022-04-07 15:44:29 -04001// 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
birenroy87c3f7e2024-07-09 12:09:37 -07005#include "quiche/http2/hpack/hpack_static_table.h"
Bence Békybac04052022-04-07 15:44:29 -04006
7#include <set>
8#include <vector>
9
10#include "absl/strings/string_view.h"
birenroy87c3f7e2024-07-09 12:09:37 -070011#include "quiche/http2/hpack/hpack_constants.h"
12#include "quiche/http2/hpack/hpack_header_table.h"
Bence Békybac04052022-04-07 15:44:29 -040013#include "quiche/common/platform/api/quiche_test.h"
Bence Békybac04052022-04-07 15:44:29 -040014
15namespace spdy {
16
17namespace test {
18
19namespace {
20
bnc7ddea9b2022-05-18 08:36:18 -070021class HpackStaticTableTest : public quiche::test::QuicheTest {
Bence Békybac04052022-04-07 15:44:29 -040022 protected:
23 HpackStaticTableTest() : table_() {}
24
25 HpackStaticTable table_;
26};
27
28// Check that an initialized instance has the right number of entries.
29TEST_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.
54TEST_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