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 #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 "base/strings/string_piece.h" |
| 24 #include "net/spdy/spdy_protocol.h" |
| 25 #include "net/spdy/spdy_test_utils.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 |
| 28 namespace net { |
| 29 namespace test { |
| 30 |
| 31 // Verify the header entries in two SpdyFrameWithHeaderBlockIR instances |
| 32 // are the same. |
| 33 ::testing::AssertionResult VerifySpdyFrameWithHeaderBlockIREquals( |
| 34 const SpdyFrameWithHeaderBlockIR& expected, |
| 35 const SpdyFrameWithHeaderBlockIR& actual); |
| 36 |
| 37 // Verify that the padding in two frames of type T is the same. |
| 38 template <class T> |
| 39 ::testing::AssertionResult VerifySpdyFrameWithPaddingIREquals(const T& expected, |
| 40 const T& actual) { |
| 41 DVLOG(1) << "VerifySpdyFrameWithPaddingIREquals"; |
| 42 if (expected.padded() != actual.padded()) |
| 43 return ::testing::AssertionFailure(); |
| 44 if (expected.padded()) { |
| 45 if (expected.padding_payload_len() != actual.padding_payload_len()) |
| 46 return ::testing::AssertionFailure(); |
| 47 } |
| 48 |
| 49 return ::testing::AssertionSuccess(); |
| 50 } |
| 51 |
| 52 // Verify the priority fields in two frames of type T are the same. |
| 53 template <class T> |
| 54 ::testing::AssertionResult VerifySpdyFrameWithPriorityIREquals( |
| 55 const T& expected, |
| 56 const T& actual) { |
| 57 DVLOG(1) << "VerifySpdyFrameWithPriorityIREquals"; |
| 58 if (expected.parent_stream_id() != actual.parent_stream_id()) |
| 59 return ::testing::AssertionFailure(); |
| 60 if (expected.weight() != actual.weight()) |
| 61 return ::testing::AssertionFailure(); |
| 62 if (expected.exclusive() != actual.exclusive()) |
| 63 return ::testing::AssertionFailure(); |
| 64 |
| 65 return ::testing::AssertionSuccess(); |
| 66 } |
| 67 |
| 68 // Verify that two SpdyAltSvcIR frames are the same. |
| 69 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyAltSvcIR& expected, |
| 70 const SpdyAltSvcIR& actual); |
| 71 |
| 72 // VerifySpdyFrameIREquals for SpdyContinuationIR frames isn't really needed |
| 73 // because we don't really make use of SpdyContinuationIR, instead creating |
| 74 // SpdyHeadersIR or SpdyPushPromiseIR with the pre-encoding form of the HPACK |
| 75 // block (i.e. we don't yet have a CONTINUATION frame). |
| 76 // |
| 77 // ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 78 // const SpdyContinuationIR& expected, |
| 79 // const SpdyContinuationIR& actual) { |
| 80 // return ::testing::AssertionFailure() |
| 81 // << "VerifySpdyFrameIREquals SpdyContinuationIR NYI"; |
| 82 // } |
| 83 |
| 84 // Verify that two SpdyDataIR frames are the same. |
| 85 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyDataIR& expected, |
| 86 const SpdyDataIR& actual); |
| 87 |
| 88 // Verify that two SpdyGoAwayIR frames are the same. |
| 89 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyGoAwayIR& expected, |
| 90 const SpdyGoAwayIR& actual); |
| 91 |
| 92 // Verify that two SpdyHeadersIR frames are the same. |
| 93 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 94 const SpdyHeadersIR& expected, |
| 95 const SpdyHeadersIR& actual); |
| 96 |
| 97 // Verify that two SpdyPingIR frames are the same. |
| 98 ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyPingIR& expected, |
| 99 const SpdyPingIR& actual); |
| 100 |
| 101 // Verify that two SpdyPriorityIR frames are the same. |
| 102 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 103 const SpdyPriorityIR& expected, |
| 104 const SpdyPriorityIR& actual); |
| 105 |
| 106 // Verify that two SpdyPushPromiseIR frames are the same. |
| 107 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 108 const SpdyPushPromiseIR& expected, |
| 109 const SpdyPushPromiseIR& actual); |
| 110 |
| 111 // Verify that two SpdyRstStreamIR frames are the same. |
| 112 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 113 const SpdyRstStreamIR& expected, |
| 114 const SpdyRstStreamIR& actual); |
| 115 |
| 116 // Verify that two SpdySettingsIR frames are the same. |
| 117 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 118 const SpdySettingsIR& expected, |
| 119 const SpdySettingsIR& actual); |
| 120 |
| 121 // Verify that two SpdyWindowUpdateIR frames are the same. |
| 122 ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 123 const SpdyWindowUpdateIR& expected, |
| 124 const SpdyWindowUpdateIR& actual); |
| 125 |
| 126 // Verify that either expected and actual are both nullptr, or that both are not |
| 127 // nullptr, and that actual is of type E, and that it matches expected. |
| 128 template <class E> |
| 129 ::testing::AssertionResult VerifySpdyFrameIREquals(const E* expected, |
| 130 const SpdyFrameIR* actual) { |
| 131 if (expected == nullptr || actual == nullptr) { |
| 132 DVLOG(1) << "VerifySpdyFrameIREquals one null"; |
| 133 if (expected != nullptr) |
| 134 return ::testing::AssertionFailure(); |
| 135 if (actual != nullptr) |
| 136 return ::testing::AssertionFailure(); |
| 137 |
| 138 return ::testing::AssertionSuccess(); |
| 139 } |
| 140 DVLOG(1) << "VerifySpdyFrameIREquals not null"; |
| 141 const E* actual2 = reinterpret_cast<const E*>(actual); |
| 142 if (actual2 == nullptr) |
| 143 return ::testing::AssertionFailure(); |
| 144 |
| 145 return VerifySpdyFrameIREquals(*expected, *actual2); |
| 146 } |
| 147 |
| 148 // Verify that actual is not nullptr, that it is of type E and that it |
| 149 // matches expected. |
| 150 template <class E> |
| 151 ::testing::AssertionResult VerifySpdyFrameIREquals(const E& expected, |
| 152 const SpdyFrameIR* actual) { |
| 153 DVLOG(1) << "VerifySpdyFrameIREquals"; |
| 154 return VerifySpdyFrameIREquals(&expected, actual); |
| 155 } |
| 156 |
| 157 } // namespace test |
| 158 } // namespace net |
| 159 |
| 160 #endif // NET_SPDY_SPDY_PROTOCOL_TEST_UTILS_H_ |
OLD | NEW |