Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: net/spdy/spdy_protocol_test_utils.h

Issue 2832973003: Split net/spdy into core and chromium subdirectories. (Closed)
Patch Set: Fix some more build rules. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_protocol_test.cc ('k') | net/spdy/spdy_protocol_test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 NET_SPDY_SPDY_PROTOCOL_TEST_UTILS_H_
6 #define NET_SPDY_SPDY_PROTOCOL_TEST_UTILS_H_
7
8 // These functions support tests that need to compare two concrete SpdyFrameIR
9 // instances for equality. They return AssertionResult, so they may be used as
10 // follows:
11 //
12 // SomeSpdyFrameIRSubClass expected_ir(...);
13 // std::unique_ptr<SpdyFrameIR> collected_frame;
14 // ... some test code that may fill in collected_frame ...
15 // ASSERT_TRUE(VerifySpdyFrameIREquals(expected_ir, collected_frame.get()));
16 //
17 // TODO(jamessynge): Where it makes sense in these functions, it would be nice
18 // to make use of the existing gMock matchers here, instead of rolling our own.
19
20 #include <typeinfo>
21
22 #include "base/logging.h"
23 #include "net/spdy/spdy_protocol.h"
24 #include "net/spdy/spdy_test_utils.h"
25 #include "testing/gmock/include/gmock/gmock.h"
26
27 namespace net {
28 namespace test {
29
30 // Verify the header entries in two SpdyFrameWithHeaderBlockIR instances
31 // are the same.
32 ::testing::AssertionResult VerifySpdyFrameWithHeaderBlockIREquals(
33 const SpdyFrameWithHeaderBlockIR& expected,
34 const SpdyFrameWithHeaderBlockIR& actual);
35
36 // Verify that the padding in two frames of type T is the same.
37 template <class T>
38 ::testing::AssertionResult VerifySpdyFrameWithPaddingIREquals(const T& expected,
39 const T& actual) {
40 DVLOG(1) << "VerifySpdyFrameWithPaddingIREquals";
41 if (expected.padded() != actual.padded())
42 return ::testing::AssertionFailure();
43 if (expected.padded()) {
44 if (expected.padding_payload_len() != actual.padding_payload_len())
45 return ::testing::AssertionFailure();
46 }
47
48 return ::testing::AssertionSuccess();
49 }
50
51 // Verify the priority fields in two frames of type T are the same.
52 template <class T>
53 ::testing::AssertionResult VerifySpdyFrameWithPriorityIREquals(
54 const T& expected,
55 const T& actual) {
56 DVLOG(1) << "VerifySpdyFrameWithPriorityIREquals";
57 if (expected.parent_stream_id() != actual.parent_stream_id())
58 return ::testing::AssertionFailure();
59 if (expected.weight() != actual.weight())
60 return ::testing::AssertionFailure();
61 if (expected.exclusive() != actual.exclusive())
62 return ::testing::AssertionFailure();
63
64 return ::testing::AssertionSuccess();
65 }
66
67 // Verify that two SpdyAltSvcIR frames are the same.
68 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyAltSvcIR& expected,
69 const SpdyAltSvcIR& actual);
70
71 // VerifySpdyFrameIREquals for SpdyContinuationIR frames isn't really needed
72 // because we don't really make use of SpdyContinuationIR, instead creating
73 // SpdyHeadersIR or SpdyPushPromiseIR with the pre-encoding form of the HPACK
74 // block (i.e. we don't yet have a CONTINUATION frame).
75 //
76 // ::testing::AssertionResult VerifySpdyFrameIREquals(
77 // const SpdyContinuationIR& expected,
78 // const SpdyContinuationIR& actual) {
79 // return ::testing::AssertionFailure()
80 // << "VerifySpdyFrameIREquals SpdyContinuationIR NYI";
81 // }
82
83 // Verify that two SpdyDataIR frames are the same.
84 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyDataIR& expected,
85 const SpdyDataIR& actual);
86
87 // Verify that two SpdyGoAwayIR frames are the same.
88 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyGoAwayIR& expected,
89 const SpdyGoAwayIR& actual);
90
91 // Verify that two SpdyHeadersIR frames are the same.
92 ::testing::AssertionResult VerifySpdyFrameIREquals(
93 const SpdyHeadersIR& expected,
94 const SpdyHeadersIR& actual);
95
96 // Verify that two SpdyPingIR frames are the same.
97 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyPingIR& expected,
98 const SpdyPingIR& actual);
99
100 // Verify that two SpdyPriorityIR frames are the same.
101 ::testing::AssertionResult VerifySpdyFrameIREquals(
102 const SpdyPriorityIR& expected,
103 const SpdyPriorityIR& actual);
104
105 // Verify that two SpdyPushPromiseIR frames are the same.
106 ::testing::AssertionResult VerifySpdyFrameIREquals(
107 const SpdyPushPromiseIR& expected,
108 const SpdyPushPromiseIR& actual);
109
110 // Verify that two SpdyRstStreamIR frames are the same.
111 ::testing::AssertionResult VerifySpdyFrameIREquals(
112 const SpdyRstStreamIR& expected,
113 const SpdyRstStreamIR& actual);
114
115 // Verify that two SpdySettingsIR frames are the same.
116 ::testing::AssertionResult VerifySpdyFrameIREquals(
117 const SpdySettingsIR& expected,
118 const SpdySettingsIR& actual);
119
120 // Verify that two SpdyWindowUpdateIR frames are the same.
121 ::testing::AssertionResult VerifySpdyFrameIREquals(
122 const SpdyWindowUpdateIR& expected,
123 const SpdyWindowUpdateIR& actual);
124
125 // Verify that either expected and actual are both nullptr, or that both are not
126 // nullptr, and that actual is of type E, and that it matches expected.
127 template <class E>
128 ::testing::AssertionResult VerifySpdyFrameIREquals(const E* expected,
129 const SpdyFrameIR* actual) {
130 if (expected == nullptr || actual == nullptr) {
131 DVLOG(1) << "VerifySpdyFrameIREquals one null";
132 if (expected != nullptr)
133 return ::testing::AssertionFailure();
134 if (actual != nullptr)
135 return ::testing::AssertionFailure();
136
137 return ::testing::AssertionSuccess();
138 }
139 DVLOG(1) << "VerifySpdyFrameIREquals not null";
140 const E* actual2 = reinterpret_cast<const E*>(actual);
141 if (actual2 == nullptr)
142 return ::testing::AssertionFailure();
143
144 return VerifySpdyFrameIREquals(*expected, *actual2);
145 }
146
147 // Verify that actual is not nullptr, that it is of type E and that it
148 // matches expected.
149 template <class E>
150 ::testing::AssertionResult VerifySpdyFrameIREquals(const E& expected,
151 const SpdyFrameIR* actual) {
152 DVLOG(1) << "VerifySpdyFrameIREquals";
153 return VerifySpdyFrameIREquals(&expected, actual);
154 }
155
156 } // namespace test
157 } // namespace net
158
159 #endif // NET_SPDY_SPDY_PROTOCOL_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_protocol_test.cc ('k') | net/spdy/spdy_protocol_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698