| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/spdy/spdy_test_utils.h" | 5 #include "net/spdy/spdy_test_utils.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 if (identical) return; | 76 if (identical) return; |
| 77 ADD_FAILURE() | 77 ADD_FAILURE() |
| 78 << "Description:\n" | 78 << "Description:\n" |
| 79 << description | 79 << description |
| 80 << "\n\nExpected:\n" | 80 << "\n\nExpected:\n" |
| 81 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len) | 81 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len) |
| 82 << "\nActual:\n" | 82 << "\nActual:\n" |
| 83 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len); | 83 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void SetFrameFlags(SpdyFrame* frame, uint8 flags, int spdy_version) { | 86 void SetFrameFlags(SpdyFrame* frame, |
| 87 uint8 flags, |
| 88 SpdyMajorVersion spdy_version) { |
| 87 switch (spdy_version) { | 89 switch (spdy_version) { |
| 88 case 2: | 90 case SPDY2: |
| 89 case 3: | 91 case SPDY3: |
| 90 frame->data()[4] = flags; | 92 frame->data()[4] = flags; |
| 91 break; | 93 break; |
| 92 case 4: | 94 case SPDY4: |
| 95 case SPDY5: |
| 93 frame->data()[3] = flags; | 96 frame->data()[3] = flags; |
| 94 break; | 97 break; |
| 95 default: | 98 default: |
| 96 LOG(FATAL) << "Unsupported SPDY version."; | 99 LOG(FATAL) << "Unsupported SPDY version."; |
| 97 } | 100 } |
| 98 } | 101 } |
| 99 | 102 |
| 100 void SetFrameLength(SpdyFrame* frame, size_t length, int spdy_version) { | 103 void SetFrameLength(SpdyFrame* frame, |
| 104 size_t length, |
| 105 SpdyMajorVersion spdy_version) { |
| 101 switch (spdy_version) { | 106 switch (spdy_version) { |
| 102 case 2: | 107 case SPDY2: |
| 103 case 3: | 108 case SPDY3: |
| 104 CHECK_EQ(0u, length & ~kLengthMask); | 109 CHECK_EQ(0u, length & ~kLengthMask); |
| 105 { | 110 { |
| 106 int32 wire_length = base::HostToNet32(length); | 111 int32 wire_length = base::HostToNet32(length); |
| 107 // The length field in SPDY 2 and 3 is a 24-bit (3B) integer starting at | 112 // The length field in SPDY 2 and 3 is a 24-bit (3B) integer starting at |
| 108 // offset 5. | 113 // offset 5. |
| 109 memcpy(frame->data() + 5, reinterpret_cast<char*>(&wire_length) + 1, 3); | 114 memcpy(frame->data() + 5, reinterpret_cast<char*>(&wire_length) + 1, 3); |
| 110 } | 115 } |
| 111 break; | 116 break; |
| 112 case 4: | 117 case SPDY4: |
| 118 case SPDY5: |
| 113 CHECK_GT(1u<<14, length); | 119 CHECK_GT(1u<<14, length); |
| 114 { | 120 { |
| 115 int32 wire_length = base::HostToNet16(static_cast<uint16>(length)); | 121 int32 wire_length = base::HostToNet16(static_cast<uint16>(length)); |
| 116 memcpy(frame->data(), | 122 memcpy(frame->data(), |
| 117 reinterpret_cast<char*>(&wire_length), | 123 reinterpret_cast<char*>(&wire_length), |
| 118 sizeof(uint16)); | 124 sizeof(uint16)); |
| 119 } | 125 } |
| 120 break; | 126 break; |
| 121 default: | 127 default: |
| 122 LOG(FATAL) << "Unsupported SPDY version."; | 128 LOG(FATAL) << "Unsupported SPDY version."; |
| 123 } | 129 } |
| 124 } | 130 } |
| 125 | 131 |
| 126 | 132 |
| 127 } // namespace test | 133 } // namespace test |
| 128 | 134 |
| 129 } // namespace net | 135 } // namespace net |
| OLD | NEW |