xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/http2/test_tools/hpack_string_collector.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 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 #ifndef QUICHE_HTTP2_TEST_TOOLS_HPACK_STRING_COLLECTOR_H_
6 #define QUICHE_HTTP2_TEST_TOOLS_HPACK_STRING_COLLECTOR_H_
7 
8 // Supports tests of decoding HPACK strings.
9 
10 #include <stddef.h>
11 
12 #include <iosfwd>
13 #include <string>
14 
15 #include "absl/strings/string_view.h"
16 #include "quiche/http2/hpack/decoder/hpack_string_decoder_listener.h"
17 #include "quiche/common/platform/api/quiche_export.h"
18 #include "quiche/common/platform/api/quiche_test.h"
19 
20 namespace http2 {
21 namespace test {
22 
23 // Records the callbacks associated with a decoding a string; must
24 // call Clear() between decoding successive strings.
25 struct QUICHE_NO_EXPORT HpackStringCollector
26     : public HpackStringDecoderListener {
27   enum CollectorState {
28     kGenesis,
29     kStarted,
30     kEnded,
31   };
32 
33   HpackStringCollector();
34   HpackStringCollector(const std::string& str, bool huffman);
35 
36   void Clear();
37   bool IsClear() const;
38   bool IsInProgress() const;
39   bool HasEnded() const;
40 
41   void OnStringStart(bool huffman, size_t length) override;
42   void OnStringData(const char* data, size_t length) override;
43   void OnStringEnd() override;
44 
45   ::testing::AssertionResult Collected(absl::string_view str,
46                                        bool is_huffman_encoded) const;
47 
48   std::string ToString() const;
49 
50   std::string s;
51   size_t len;
52   bool huffman_encoded;
53   CollectorState state;
54 };
55 
56 bool operator==(const HpackStringCollector& a, const HpackStringCollector& b);
57 
58 bool operator!=(const HpackStringCollector& a, const HpackStringCollector& b);
59 
60 QUICHE_NO_EXPORT std::ostream& operator<<(std::ostream& out,
61                                           const HpackStringCollector& v);
62 
63 }  // namespace test
64 }  // namespace http2
65 
66 #endif  // QUICHE_HTTP2_TEST_TOOLS_HPACK_STRING_COLLECTOR_H_
67