| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/core/hpack/hpack_output_stream.h" | 5 #include "net/spdy/core/hpack/hpack_output_stream.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace net { | 11 namespace net { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // Make sure that AppendBits() appends bits starting from the most | 15 // Make sure that AppendBits() appends bits starting from the most |
| 16 // significant bit, and that it can handle crossing a byte boundary. | 16 // significant bit, and that it can handle crossing a byte boundary. |
| 17 TEST(HpackOutputStreamTest, AppendBits) { | 17 TEST(HpackOutputStreamTest, AppendBits) { |
| 18 HpackOutputStream output_stream; | 18 HpackOutputStream output_stream; |
| 19 SpdyString expected_str; | 19 SpdyString expected_str; |
| 20 | 20 |
| 21 output_stream.AppendBits(0x1, 1); | 21 output_stream.AppendBits(0x1, 1); |
| 22 expected_str.append(1, 0x00); | 22 expected_str.append(1, 0x00); |
| 23 *expected_str.rbegin() |= (0x1 << 7); | 23 expected_str.back() |= (0x1 << 7); |
| 24 | 24 |
| 25 output_stream.AppendBits(0x0, 1); | 25 output_stream.AppendBits(0x0, 1); |
| 26 | 26 |
| 27 output_stream.AppendBits(0x3, 2); | 27 output_stream.AppendBits(0x3, 2); |
| 28 *expected_str.rbegin() |= (0x3 << 4); | 28 *expected_str.rbegin() |= (0x3 << 4); |
| 29 | 29 |
| 30 output_stream.AppendBits(0x0, 2); | 30 output_stream.AppendBits(0x0, 2); |
| 31 | 31 |
| 32 // Byte-crossing append. | 32 // Byte-crossing append. |
| 33 output_stream.AppendBits(0x7, 3); | 33 output_stream.AppendBits(0x7, 3); |
| 34 *expected_str.rbegin() |= (0x7 >> 1); | 34 *expected_str.rbegin() |= (0x7 >> 1); |
| 35 expected_str.append(1, 0x00); | 35 expected_str.append(1, 0x00); |
| 36 *expected_str.rbegin() |= (0x7 << 7); | 36 expected_str.back() |= (0x7 << 7); |
| 37 | 37 |
| 38 output_stream.AppendBits(0x0, 7); | 38 output_stream.AppendBits(0x0, 7); |
| 39 | 39 |
| 40 SpdyString str; | 40 SpdyString str; |
| 41 output_stream.TakeString(&str); | 41 output_stream.TakeString(&str); |
| 42 EXPECT_EQ(expected_str, str); | 42 EXPECT_EQ(expected_str, str); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Utility function to return I as a string encoded with an N-bit | 45 // Utility function to return I as a string encoded with an N-bit |
| 46 // prefix. | 46 // prefix. |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 output_stream.BoundedTakeString(9, &str); | 267 output_stream.BoundedTakeString(9, &str); |
| 268 EXPECT_EQ("uffer456\xff", str); | 268 EXPECT_EQ("uffer456\xff", str); |
| 269 | 269 |
| 270 output_stream.BoundedTakeString(9, &str); | 270 output_stream.BoundedTakeString(9, &str); |
| 271 EXPECT_EQ("\x10", str); | 271 EXPECT_EQ("\x10", str); |
| 272 } | 272 } |
| 273 | 273 |
| 274 } // namespace | 274 } // namespace |
| 275 | 275 |
| 276 } // namespace net | 276 } // namespace net |
| OLD | NEW |