xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/common/print_elements_test.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 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/common/print_elements.h"
6 
7 #include <list>
8 #include <string>
9 #include <vector>
10 
11 #include "absl/strings/string_view.h"
12 #include "quiche/quic/core/quic_error_codes.h"
13 #include "quiche/common/platform/api/quiche_test.h"
14 
15 using quic::QuicIetfTransportErrorCodes;
16 
17 namespace quiche {
18 namespace test {
19 namespace {
20 
TEST(PrintElementsTest,Empty)21 TEST(PrintElementsTest, Empty) {
22   std::vector<std::string> empty{};
23   EXPECT_EQ("{}", PrintElements(empty));
24 }
25 
TEST(PrintElementsTest,StdContainers)26 TEST(PrintElementsTest, StdContainers) {
27   std::vector<std::string> one{"foo"};
28   EXPECT_EQ("{foo}", PrintElements(one));
29 
30   std::list<std::string> two{"foo", "bar"};
31   EXPECT_EQ("{foo, bar}", PrintElements(two));
32 
33   std::deque<absl::string_view> three{"foo", "bar", "baz"};
34   EXPECT_EQ("{foo, bar, baz}", PrintElements(three));
35 }
36 
37 // QuicIetfTransportErrorCodes has a custom operator<<() override.
TEST(PrintElementsTest,CustomPrinter)38 TEST(PrintElementsTest, CustomPrinter) {
39   std::vector<QuicIetfTransportErrorCodes> empty{};
40   EXPECT_EQ("{}", PrintElements(empty));
41 
42   std::list<QuicIetfTransportErrorCodes> one{
43       QuicIetfTransportErrorCodes::NO_IETF_QUIC_ERROR};
44   EXPECT_EQ("{NO_IETF_QUIC_ERROR}", PrintElements(one));
45 
46   std::vector<QuicIetfTransportErrorCodes> two{
47       QuicIetfTransportErrorCodes::FLOW_CONTROL_ERROR,
48       QuicIetfTransportErrorCodes::STREAM_LIMIT_ERROR};
49   EXPECT_EQ("{FLOW_CONTROL_ERROR, STREAM_LIMIT_ERROR}", PrintElements(two));
50 
51   std::list<QuicIetfTransportErrorCodes> three{
52       QuicIetfTransportErrorCodes::CONNECTION_ID_LIMIT_ERROR,
53       QuicIetfTransportErrorCodes::PROTOCOL_VIOLATION,
54       QuicIetfTransportErrorCodes::INVALID_TOKEN};
55   EXPECT_EQ("{CONNECTION_ID_LIMIT_ERROR, PROTOCOL_VIOLATION, INVALID_TOKEN}",
56             PrintElements(three));
57 }
58 
59 }  // anonymous namespace
60 }  // namespace test
61 }  // namespace quiche
62