summaryrefslogtreecommitdiff
path: root/chromium/net/third_party/quiche/src/quic/core/qpack/qpack_static_table_test.cc
blob: 53ab0f49a0445f06ec91caaef7774b8bacf5edb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "quic/core/qpack/qpack_static_table.h"

#include <set>

#include "absl/base/macros.h"
#include "absl/strings/string_view.h"
#include "quic/platform/api/quic_test.h"

namespace quic {

namespace test {

namespace {

// Check that an initialized instance has the right number of entries.
TEST(QpackStaticTableTest, Initialize) {
  QpackStaticTable table;
  EXPECT_FALSE(table.IsInitialized());

  table.Initialize(QpackStaticTableVector().data(),
                   QpackStaticTableVector().size());
  EXPECT_TRUE(table.IsInitialized());

  const auto& static_entries = table.GetStaticEntries();
  EXPECT_EQ(QpackStaticTableVector().size(), static_entries.size());

  const auto& static_index = table.GetStaticIndex();
  EXPECT_EQ(QpackStaticTableVector().size(), static_index.size());

  const auto& static_name_index = table.GetStaticNameIndex();
  // Count distinct names in static table.
  std::set<absl::string_view> names;
  for (const auto& entry : static_entries) {
    names.insert(entry.name());
  }
  EXPECT_EQ(names.size(), static_name_index.size());
}

// Test that ObtainQpackStaticTable returns the same instance every time.
TEST(QpackStaticTableTest, IsSingleton) {
  const QpackStaticTable* static_table_one = &ObtainQpackStaticTable();
  const QpackStaticTable* static_table_two = &ObtainQpackStaticTable();
  EXPECT_EQ(static_table_one, static_table_two);
}

}  // namespace

}  // namespace test

}  // namespace quic