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