OLD | NEW |
(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 #include <stdint.h> |
| 6 |
| 7 #include "net/spdy/spdy_protocol_test_utils.h" |
| 8 |
| 9 namespace net { |
| 10 namespace test { |
| 11 |
| 12 // TODO(jamessynge): Where it makes sense in these functions, it would be nice |
| 13 // to make use of the existing gMock matchers here, instead of rolling our own. |
| 14 |
| 15 ::testing::AssertionResult VerifySpdyFrameWithHeaderBlockIREquals( |
| 16 const SpdyFrameWithHeaderBlockIR& expected, |
| 17 const SpdyFrameWithHeaderBlockIR& actual) { |
| 18 DVLOG(1) << "VerifySpdyFrameWithHeaderBlockIREquals"; |
| 19 if (actual.header_block() != expected.header_block()) |
| 20 return ::testing::AssertionFailure(); |
| 21 |
| 22 return ::testing::AssertionSuccess(); |
| 23 } |
| 24 |
| 25 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyAltSvcIR& expected, |
| 26 const SpdyAltSvcIR& actual) { |
| 27 if (expected.stream_id() != actual.stream_id()) |
| 28 return ::testing::AssertionFailure(); |
| 29 if (expected.origin() != actual.origin()) |
| 30 return ::testing::AssertionFailure(); |
| 31 if (actual.altsvc_vector() != expected.altsvc_vector()) |
| 32 return ::testing::AssertionFailure(); |
| 33 |
| 34 return ::testing::AssertionSuccess(); |
| 35 } |
| 36 |
| 37 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 38 const SpdyContinuationIR& expected, |
| 39 const SpdyContinuationIR& actual) { |
| 40 return ::testing::AssertionFailure() |
| 41 << "VerifySpdyFrameIREquals SpdyContinuationIR not yet implemented"; |
| 42 } |
| 43 |
| 44 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyDataIR& expected, |
| 45 const SpdyDataIR& actual) { |
| 46 DVLOG(1) << "VerifySpdyFrameIREquals SpdyDataIR"; |
| 47 if (expected.stream_id() != actual.stream_id()) |
| 48 return ::testing::AssertionFailure(); |
| 49 if (expected.fin() != actual.fin()) |
| 50 return ::testing::AssertionFailure(); |
| 51 if (expected.data().size() != actual.data().size()) |
| 52 return ::testing::AssertionFailure(); |
| 53 if (expected.data() != actual.data()) |
| 54 return ::testing::AssertionFailure(); |
| 55 if (!VerifySpdyFrameWithPaddingIREquals(expected, actual)) |
| 56 return ::testing::AssertionFailure(); |
| 57 |
| 58 return ::testing::AssertionSuccess(); |
| 59 } |
| 60 |
| 61 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyGoAwayIR& expected, |
| 62 const SpdyGoAwayIR& actual) { |
| 63 DVLOG(1) << "VerifySpdyFrameIREquals SpdyGoAwayIR"; |
| 64 if (expected.last_good_stream_id() != actual.last_good_stream_id()) |
| 65 return ::testing::AssertionFailure(); |
| 66 if (expected.status() != actual.status()) |
| 67 return ::testing::AssertionFailure(); |
| 68 if (expected.description() != actual.description()) |
| 69 return ::testing::AssertionFailure(); |
| 70 |
| 71 return ::testing::AssertionSuccess(); |
| 72 } |
| 73 |
| 74 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 75 const SpdyHeadersIR& expected, |
| 76 const SpdyHeadersIR& actual) { |
| 77 DVLOG(1) << "VerifySpdyFrameIREquals SpdyHeadersIR"; |
| 78 if (expected.stream_id() != actual.stream_id()) |
| 79 return ::testing::AssertionFailure(); |
| 80 if (expected.fin() != actual.fin()) |
| 81 return ::testing::AssertionFailure(); |
| 82 if (!VerifySpdyFrameWithHeaderBlockIREquals(expected, actual)) |
| 83 return ::testing::AssertionFailure(); |
| 84 if (expected.has_priority() != actual.has_priority()) |
| 85 return ::testing::AssertionFailure(); |
| 86 if (expected.has_priority()) { |
| 87 if (!VerifySpdyFrameWithPriorityIREquals(expected, actual)) |
| 88 return ::testing::AssertionFailure(); |
| 89 } |
| 90 if (!VerifySpdyFrameWithPaddingIREquals(expected, actual)) |
| 91 return ::testing::AssertionFailure(); |
| 92 |
| 93 return ::testing::AssertionSuccess(); |
| 94 } |
| 95 |
| 96 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyPingIR& expected, |
| 97 const SpdyPingIR& actual) { |
| 98 DVLOG(1) << "VerifySpdyFrameIREquals SpdyPingIR"; |
| 99 if (expected.id() != actual.id()) |
| 100 return ::testing::AssertionFailure(); |
| 101 if (expected.is_ack() != actual.is_ack()) |
| 102 return ::testing::AssertionFailure(); |
| 103 |
| 104 return ::testing::AssertionSuccess(); |
| 105 } |
| 106 |
| 107 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 108 const SpdyPriorityIR& expected, |
| 109 const SpdyPriorityIR& actual) { |
| 110 DVLOG(1) << "VerifySpdyFrameIREquals SpdyPriorityIR"; |
| 111 if (expected.stream_id() != actual.stream_id()) |
| 112 return ::testing::AssertionFailure(); |
| 113 if (!VerifySpdyFrameWithPriorityIREquals(expected, actual)) |
| 114 return ::testing::AssertionFailure(); |
| 115 |
| 116 return ::testing::AssertionSuccess(); |
| 117 } |
| 118 |
| 119 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 120 const SpdyPushPromiseIR& expected, |
| 121 const SpdyPushPromiseIR& actual) { |
| 122 DVLOG(1) << "VerifySpdyFrameIREquals SpdyPushPromiseIR"; |
| 123 if (expected.stream_id() != actual.stream_id()) |
| 124 return ::testing::AssertionFailure(); |
| 125 if (!VerifySpdyFrameWithPaddingIREquals(expected, actual)) |
| 126 return ::testing::AssertionFailure(); |
| 127 if (expected.promised_stream_id() != actual.promised_stream_id()) |
| 128 return ::testing::AssertionFailure(); |
| 129 if (!VerifySpdyFrameWithHeaderBlockIREquals(expected, actual)) |
| 130 return ::testing::AssertionFailure(); |
| 131 |
| 132 return ::testing::AssertionSuccess(); |
| 133 } |
| 134 |
| 135 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 136 const SpdyRstStreamIR& expected, |
| 137 const SpdyRstStreamIR& actual) { |
| 138 DVLOG(1) << "VerifySpdyFrameIREquals SpdyRstStreamIR"; |
| 139 if (expected.stream_id() != actual.stream_id()) |
| 140 return ::testing::AssertionFailure(); |
| 141 if (expected.status() != actual.status()) |
| 142 return ::testing::AssertionFailure(); |
| 143 |
| 144 return ::testing::AssertionSuccess(); |
| 145 } |
| 146 |
| 147 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 148 const SpdySettingsIR& expected, |
| 149 const SpdySettingsIR& actual) { |
| 150 DVLOG(1) << "VerifySpdyFrameIREquals SpdySettingsIR"; |
| 151 // Note, ignoring non-HTTP/2 fields such as clear_settings. |
| 152 if (expected.is_ack() != actual.is_ack()) |
| 153 return ::testing::AssertionFailure(); |
| 154 |
| 155 if (expected.values().size() != actual.values().size()) |
| 156 return ::testing::AssertionFailure(); |
| 157 for (const auto& entry : expected.values()) { |
| 158 const auto& param = entry.first; |
| 159 auto actual_itr = actual.values().find(param); |
| 160 if (actual_itr == actual.values().end()) { |
| 161 DVLOG(1) << "actual doesn't contain param: " << param; |
| 162 return ::testing::AssertionFailure(); |
| 163 } |
| 164 uint32_t expected_value = entry.second.value; |
| 165 uint32_t actual_value = actual_itr->second.value; |
| 166 if (expected_value != actual_value) { |
| 167 DVLOG(1) << "Values don't match for parameter: " << param; |
| 168 return ::testing::AssertionFailure(); |
| 169 } |
| 170 } |
| 171 |
| 172 return ::testing::AssertionSuccess(); |
| 173 } |
| 174 |
| 175 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 176 const SpdyWindowUpdateIR& expected, |
| 177 const SpdyWindowUpdateIR& actual) { |
| 178 DVLOG(1) << "VerifySpdyFrameIREquals SpdyWindowUpdateIR"; |
| 179 if (expected.stream_id() != actual.stream_id()) |
| 180 return ::testing::AssertionFailure(); |
| 181 if (expected.delta() != actual.delta()) |
| 182 return ::testing::AssertionFailure(); |
| 183 |
| 184 return ::testing::AssertionSuccess(); |
| 185 } |
| 186 |
| 187 } // namespace test |
| 188 } // namespace net |
OLD | NEW |