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_HTTP2_STRUCTURES_TEST_UTIL_H_
6 #define QUICHE_HTTP2_TEST_TOOLS_HTTP2_STRUCTURES_TEST_UTIL_H_
7 
8 #include <string>
9 
10 #include "quiche/http2/http2_structures.h"
11 #include "quiche/http2/test_tools/http2_frame_builder.h"
12 #include "quiche/http2/test_tools/http2_random.h"
13 #include "quiche/common/platform/api/quiche_test.h"
14 
15 namespace http2 {
16 namespace test {
17 
18 template <class S>
SerializeStructure(const S & s)19 std::string SerializeStructure(const S& s) {
20   Http2FrameBuilder fb;
21   fb.Append(s);
22   EXPECT_EQ(S::EncodedSize(), fb.size());
23   return fb.buffer();
24 }
25 
26 // Randomize the members of out, in a manner that yields encodeable contents
27 // (e.g. a "uint24" field has only the low 24 bits set).
28 void Randomize(Http2FrameHeader* out, Http2Random* rng);
29 void Randomize(Http2PriorityFields* out, Http2Random* rng);
30 void Randomize(Http2RstStreamFields* out, Http2Random* rng);
31 void Randomize(Http2SettingFields* out, Http2Random* rng);
32 void Randomize(Http2PushPromiseFields* out, Http2Random* rng);
33 void Randomize(Http2PingFields* out, Http2Random* rng);
34 void Randomize(Http2GoAwayFields* out, Http2Random* rng);
35 void Randomize(Http2WindowUpdateFields* out, Http2Random* rng);
36 void Randomize(Http2AltSvcFields* out, Http2Random* rng);
37 void Randomize(Http2PriorityUpdateFields* out, Http2Random* rng);
38 
39 // Clear bits of header->flags that are known to be invalid for the
40 // type. For unknown frame types, no change is made.
41 void ScrubFlagsOfHeader(Http2FrameHeader* header);
42 
43 // Is the frame with this header padded? Only true for known/supported frame
44 // types.
45 bool FrameIsPadded(const Http2FrameHeader& header);
46 
47 // Does the frame with this header have Http2PriorityFields?
48 bool FrameHasPriority(const Http2FrameHeader& header);
49 
50 // Does the frame with this header have a variable length payload (including
51 // empty) payload (e.g. DATA or HEADERS)? Really a test of the frame type.
52 bool FrameCanHavePayload(const Http2FrameHeader& header);
53 
54 // Does the frame with this header have a variable length HPACK payload
55 // (including empty) payload (e.g. HEADERS)? Really a test of the frame type.
56 bool FrameCanHaveHpackPayload(const Http2FrameHeader& header);
57 
58 }  // namespace test
59 }  // namespace http2
60 
61 #endif  // QUICHE_HTTP2_TEST_TOOLS_HTTP2_STRUCTURES_TEST_UTIL_H_
62