| 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_protocol.h" | 5 #include "net/spdy/spdy_protocol.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "net/spdy/spdy_bitmasks.h" | 11 #include "net/spdy/spdy_bitmasks.h" |
| 12 #include "net/spdy/spdy_framer.h" | 12 #include "net/spdy/spdy_framer.h" |
| 13 #include "net/spdy/spdy_test_utils.h" | 13 #include "net/spdy/spdy_test_utils.h" |
| 14 #include "net/test/gtest_util.h" | 14 #include "net/test/gtest_util.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using std::string; | |
| 18 | |
| 19 namespace net { | 17 namespace net { |
| 20 | 18 |
| 21 std::ostream& operator<<(std::ostream& os, | 19 std::ostream& operator<<(std::ostream& os, |
| 22 const SpdyStreamPrecedence precedence) { | 20 const SpdyStreamPrecedence precedence) { |
| 23 if (precedence.is_spdy3_priority()) { | 21 if (precedence.is_spdy3_priority()) { |
| 24 os << "SpdyStreamPrecedence[spdy3_priority=" << precedence.spdy3_priority() | 22 os << "SpdyStreamPrecedence[spdy3_priority=" << precedence.spdy3_priority() |
| 25 << "]"; | 23 << "]"; |
| 26 } else { | 24 } else { |
| 27 os << "SpdyStreamPrecedence[parent_id=" << precedence.parent_id() | 25 os << "SpdyStreamPrecedence[parent_id=" << precedence.parent_id() |
| 28 << ", weight=" << precedence.weight() | 26 << ", weight=" << precedence.weight() |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 EXPECT_EQ(SETTINGS_MAX_FRAME_SIZE, setting_id); | 119 EXPECT_EQ(SETTINGS_MAX_FRAME_SIZE, setting_id); |
| 122 EXPECT_TRUE(ParseSettingsId(6, &setting_id)); | 120 EXPECT_TRUE(ParseSettingsId(6, &setting_id)); |
| 123 EXPECT_EQ(SETTINGS_MAX_HEADER_LIST_SIZE, setting_id); | 121 EXPECT_EQ(SETTINGS_MAX_HEADER_LIST_SIZE, setting_id); |
| 124 EXPECT_FALSE(ParseSettingsId(7, &setting_id)); | 122 EXPECT_FALSE(ParseSettingsId(7, &setting_id)); |
| 125 } | 123 } |
| 126 | 124 |
| 127 TEST(SpdyProtocolTest, SettingsIdToString) { | 125 TEST(SpdyProtocolTest, SettingsIdToString) { |
| 128 struct { | 126 struct { |
| 129 SpdySettingsIds setting_id; | 127 SpdySettingsIds setting_id; |
| 130 bool expected_bool; | 128 bool expected_bool; |
| 131 const string expected_string; | 129 const SpdyString expected_string; |
| 132 } test_cases[] = { | 130 } test_cases[] = { |
| 133 {static_cast<SpdySettingsIds>(0), false, "SETTINGS_UNKNOWN"}, | 131 {static_cast<SpdySettingsIds>(0), false, "SETTINGS_UNKNOWN"}, |
| 134 {SETTINGS_HEADER_TABLE_SIZE, true, "SETTINGS_HEADER_TABLE_SIZE"}, | 132 {SETTINGS_HEADER_TABLE_SIZE, true, "SETTINGS_HEADER_TABLE_SIZE"}, |
| 135 {SETTINGS_ENABLE_PUSH, true, "SETTINGS_ENABLE_PUSH"}, | 133 {SETTINGS_ENABLE_PUSH, true, "SETTINGS_ENABLE_PUSH"}, |
| 136 {SETTINGS_MAX_CONCURRENT_STREAMS, true, | 134 {SETTINGS_MAX_CONCURRENT_STREAMS, true, |
| 137 "SETTINGS_MAX_CONCURRENT_STREAMS"}, | 135 "SETTINGS_MAX_CONCURRENT_STREAMS"}, |
| 138 {SETTINGS_INITIAL_WINDOW_SIZE, true, "SETTINGS_INITIAL_WINDOW_SIZE"}, | 136 {SETTINGS_INITIAL_WINDOW_SIZE, true, "SETTINGS_INITIAL_WINDOW_SIZE"}, |
| 139 {SETTINGS_MAX_FRAME_SIZE, true, "SETTINGS_MAX_FRAME_SIZE"}, | 137 {SETTINGS_MAX_FRAME_SIZE, true, "SETTINGS_MAX_FRAME_SIZE"}, |
| 140 {SETTINGS_MAX_HEADER_LIST_SIZE, true, "SETTINGS_MAX_HEADER_LIST_SIZE"}, | 138 {SETTINGS_MAX_HEADER_LIST_SIZE, true, "SETTINGS_MAX_HEADER_LIST_SIZE"}, |
| 141 {static_cast<SpdySettingsIds>(7), false, "SETTINGS_UNKNOWN"}}; | 139 {static_cast<SpdySettingsIds>(7), false, "SETTINGS_UNKNOWN"}}; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 EXPECT_EQ(d1.data_len(), 0ul); | 225 EXPECT_EQ(d1.data_len(), 0ul); |
| 228 EXPECT_NE(d1.data(), nullptr); | 226 EXPECT_NE(d1.data(), nullptr); |
| 229 | 227 |
| 230 // Confirms makes a copy of char array. | 228 // Confirms makes a copy of char array. |
| 231 const char s2[] = "something"; | 229 const char s2[] = "something"; |
| 232 SpdyDataIR d2(2, s2); | 230 SpdyDataIR d2(2, s2); |
| 233 EXPECT_EQ(SpdyStringPiece(d2.data(), d2.data_len()), s2); | 231 EXPECT_EQ(SpdyStringPiece(d2.data(), d2.data_len()), s2); |
| 234 EXPECT_NE(SpdyStringPiece(d1.data(), d1.data_len()), s2); | 232 EXPECT_NE(SpdyStringPiece(d1.data(), d1.data_len()), s2); |
| 235 | 233 |
| 236 // Confirm copies a const string. | 234 // Confirm copies a const string. |
| 237 const string foo = "foo"; | 235 const SpdyString foo = "foo"; |
| 238 SpdyDataIR d3(3, foo); | 236 SpdyDataIR d3(3, foo); |
| 239 EXPECT_EQ(foo, d3.data()); | 237 EXPECT_EQ(foo, d3.data()); |
| 240 | 238 |
| 241 // Confirm copies a non-const string. | 239 // Confirm copies a non-const string. |
| 242 string bar = "bar"; | 240 SpdyString bar = "bar"; |
| 243 SpdyDataIR d4(4, bar); | 241 SpdyDataIR d4(4, bar); |
| 244 EXPECT_EQ("bar", bar); | 242 EXPECT_EQ("bar", bar); |
| 245 EXPECT_EQ("bar", SpdyStringPiece(d4.data(), d4.data_len())); | 243 EXPECT_EQ("bar", SpdyStringPiece(d4.data(), d4.data_len())); |
| 246 | 244 |
| 247 // Confirm moves an rvalue reference. Note that the test string "baz" is too | 245 // Confirm moves an rvalue reference. Note that the test string "baz" is too |
| 248 // short to trigger the move optimization, and instead a copy occurs. | 246 // short to trigger the move optimization, and instead a copy occurs. |
| 249 string baz = "the quick brown fox"; | 247 SpdyString baz = "the quick brown fox"; |
| 250 SpdyDataIR d5(5, std::move(baz)); | 248 SpdyDataIR d5(5, std::move(baz)); |
| 251 EXPECT_EQ("", baz); | 249 EXPECT_EQ("", baz); |
| 252 EXPECT_EQ(SpdyStringPiece(d5.data(), d5.data_len()), "the quick brown fox"); | 250 EXPECT_EQ(SpdyStringPiece(d5.data(), d5.data_len()), "the quick brown fox"); |
| 253 | 251 |
| 254 // Confirms makes a copy of string literal. | 252 // Confirms makes a copy of string literal. |
| 255 SpdyDataIR d7(7, "something else"); | 253 SpdyDataIR d7(7, "something else"); |
| 256 EXPECT_EQ(SpdyStringPiece(d7.data(), d7.data_len()), "something else"); | 254 EXPECT_EQ(SpdyStringPiece(d7.data(), d7.data_len()), "something else"); |
| 257 } | 255 } |
| 258 | 256 |
| 259 } // namespace test | 257 } // namespace test |
| 260 } // namespace net | 258 } // namespace net |
| OLD | NEW |