blob: 76be13b743cfd9644b697fd729a54412366ab420 [file] [log] [blame]
QUICHE teamfd50a402018-12-07 22:54:05 -05001// 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_HPACK_DECODER_HPACK_STRING_COLLECTOR_H_
6#define QUICHE_HTTP2_HPACK_DECODER_HPACK_STRING_COLLECTOR_H_
7
8// Supports tests of decoding HPACK strings.
9
10#include <stddef.h>
11
12#include <iosfwd>
13
14#include "testing/gtest/include/gtest/gtest.h"
15#include "net/third_party/quiche/src/http2/hpack/decoder/hpack_string_decoder_listener.h"
16#include "net/third_party/quiche/src/http2/platform/api/http2_string.h"
17#include "net/third_party/quiche/src/http2/platform/api/http2_string_piece.h"
18
19namespace http2 {
20namespace test {
21
22// Records the callbacks associated with a decoding a string; must
23// call Clear() between decoding successive strings.
24struct HpackStringCollector : public HpackStringDecoderListener {
25 enum CollectorState {
26 kGenesis,
27 kStarted,
28 kEnded,
29 };
30
31 HpackStringCollector();
32 HpackStringCollector(const Http2String& str, bool huffman);
33
34 void Clear();
35 bool IsClear() const;
36 bool IsInProgress() const;
37 bool HasEnded() const;
38
39 void OnStringStart(bool huffman, size_t length) override;
40 void OnStringData(const char* data, size_t length) override;
41 void OnStringEnd() override;
42
43 ::testing::AssertionResult Collected(Http2StringPiece str,
44 bool is_huffman_encoded) const;
45
46 Http2String ToString() const;
47
48 Http2String s;
49 size_t len;
50 bool huffman_encoded;
51 CollectorState state;
52};
53
54bool operator==(const HpackStringCollector& a, const HpackStringCollector& b);
55
56bool operator!=(const HpackStringCollector& a, const HpackStringCollector& b);
57
58std::ostream& operator<<(std::ostream& out, const HpackStringCollector& v);
59
60} // namespace test
61} // namespace http2
62
63#endif // QUICHE_HTTP2_HPACK_DECODER_HPACK_STRING_COLLECTOR_H_