| 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/quic/quic_protocol.h" | 5 #include "net/quic/quic_protocol.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED,QUIC_VERSION_25", | 187 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED,QUIC_VERSION_25", |
| 188 QuicVersionVectorToString(versions_vector)); | 188 QuicVersionVectorToString(versions_vector)); |
| 189 | 189 |
| 190 // Make sure that all supported versions are present in QuicVersionToString. | 190 // Make sure that all supported versions are present in QuicVersionToString. |
| 191 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | 191 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
| 192 QuicVersion version = kSupportedQuicVersions[i]; | 192 QuicVersion version = kSupportedQuicVersions[i]; |
| 193 EXPECT_NE("QUIC_VERSION_UNSUPPORTED", QuicVersionToString(version)); | 193 EXPECT_NE("QUIC_VERSION_UNSUPPORTED", QuicVersionToString(version)); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 TEST(QuicProtocolTest, AckFrameToString) { |
| 198 QuicAckFrame frame; |
| 199 frame.entropy_hash = 1; |
| 200 frame.largest_observed = 2; |
| 201 frame.ack_delay_time = QuicTime::Delta::FromMicroseconds(3); |
| 202 frame.packets.Add(4); |
| 203 frame.packets.Add(5); |
| 204 frame.received_packet_times = { |
| 205 {6, QuicTime::Zero().Add(QuicTime::Delta::FromMicroseconds(7))}}; |
| 206 std::ostringstream stream; |
| 207 stream << frame; |
| 208 EXPECT_EQ( |
| 209 "{ entropy_hash: 1, largest_observed: 2, ack_delay_time: 3, " |
| 210 "packets: [ 4 5 ], is_truncated: 0, received_packets: [ 6 at 7 ] }\n", |
| 211 stream.str()); |
| 212 } |
| 213 |
| 214 TEST(QuicProtocolTest, PaddingFrameToString) { |
| 215 QuicPaddingFrame frame; |
| 216 frame.num_padding_bytes = 1; |
| 217 std::ostringstream stream; |
| 218 stream << frame; |
| 219 EXPECT_EQ("{ num_padding_bytes: 1 }\n", stream.str()); |
| 220 } |
| 221 |
| 222 TEST(QuicProtocolTest, RstStreamFrameToString) { |
| 223 QuicRstStreamFrame frame; |
| 224 frame.stream_id = 1; |
| 225 frame.error_code = QUIC_STREAM_CANCELLED; |
| 226 std::ostringstream stream; |
| 227 stream << frame; |
| 228 EXPECT_EQ("{ stream_id: 1, error_code: 6 }\n", stream.str()); |
| 229 } |
| 230 |
| 231 TEST(QuicProtocolTest, ConnectionCloseFrameToString) { |
| 232 QuicConnectionCloseFrame frame; |
| 233 frame.error_code = QUIC_NETWORK_IDLE_TIMEOUT; |
| 234 frame.error_details = "No recent network activity."; |
| 235 std::ostringstream stream; |
| 236 stream << frame; |
| 237 EXPECT_EQ( |
| 238 "{ error_code: 25, error_details: 'No recent network activity.' }\n", |
| 239 stream.str()); |
| 240 } |
| 241 |
| 242 TEST(QuicProtocolTest, GoAwayFrameToString) { |
| 243 QuicGoAwayFrame frame; |
| 244 frame.error_code = QUIC_NETWORK_IDLE_TIMEOUT; |
| 245 frame.last_good_stream_id = 2; |
| 246 frame.reason_phrase = "Reason"; |
| 247 std::ostringstream stream; |
| 248 stream << frame; |
| 249 EXPECT_EQ( |
| 250 "{ error_code: 25, last_good_stream_id: 2, reason_phrase: 'Reason' }\n", |
| 251 stream.str()); |
| 252 } |
| 253 |
| 254 TEST(QuicProtocolTest, WindowUpdateFrameToString) { |
| 255 QuicWindowUpdateFrame frame; |
| 256 std::ostringstream stream; |
| 257 frame.stream_id = 1; |
| 258 frame.byte_offset = 2; |
| 259 stream << frame; |
| 260 EXPECT_EQ("{ stream_id: 1, byte_offset: 2 }\n", stream.str()); |
| 261 } |
| 262 |
| 263 TEST(QuicProtocolTest, BlockedFrameToString) { |
| 264 QuicBlockedFrame frame; |
| 265 frame.stream_id = 1; |
| 266 std::ostringstream stream; |
| 267 stream << frame; |
| 268 EXPECT_EQ("{ stream_id: 1 }\n", stream.str()); |
| 269 } |
| 270 |
| 271 TEST(QuicProtocolTest, StreamFrameToString) { |
| 272 QuicStreamFrame frame; |
| 273 frame.stream_id = 1; |
| 274 frame.fin = false; |
| 275 frame.offset = 2; |
| 276 frame.data_length = 3; |
| 277 std::ostringstream stream; |
| 278 stream << frame; |
| 279 EXPECT_EQ("{ stream_id: 1, fin: 0, offset: 2, length: 3 }\n", stream.str()); |
| 280 } |
| 281 |
| 282 TEST(QuicProtocolTest, StopWaitingFrameToString) { |
| 283 QuicStopWaitingFrame frame; |
| 284 frame.entropy_hash = 1; |
| 285 frame.least_unacked = 2; |
| 286 std::ostringstream stream; |
| 287 stream << frame; |
| 288 EXPECT_EQ("{ entropy_hash: 1, least_unacked: 2 }\n", stream.str()); |
| 289 } |
| 290 |
| 291 TEST(QuicProtocolTest, PathCloseFrameToString) { |
| 292 QuicPathCloseFrame frame; |
| 293 frame.path_id = 1; |
| 294 std::ostringstream stream; |
| 295 stream << frame; |
| 296 EXPECT_EQ("{ path_id: 1 }\n", stream.str()); |
| 297 } |
| 298 |
| 197 // Tests that a queue contains the expected data after calls to Add(). | 299 // Tests that a queue contains the expected data after calls to Add(). |
| 198 TEST(PacketNumberQueueTest, AddRange) { | 300 TEST(PacketNumberQueueTest, AddRange) { |
| 199 PacketNumberQueue queue; | 301 PacketNumberQueue queue; |
| 200 queue.Add(1, 51); | 302 queue.Add(1, 51); |
| 201 queue.Add(53); | 303 queue.Add(53); |
| 202 | 304 |
| 203 EXPECT_FALSE(queue.Contains(0)); | 305 EXPECT_FALSE(queue.Contains(0)); |
| 204 for (int i = 1; i < 51; ++i) { | 306 for (int i = 1; i < 51; ++i) { |
| 205 EXPECT_TRUE(queue.Contains(i)); | 307 EXPECT_TRUE(queue.Contains(i)); |
| 206 } | 308 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 EXPECT_EQ(10u, queue.LastIntervalLength()); | 398 EXPECT_EQ(10u, queue.LastIntervalLength()); |
| 297 queue.Remove(9, 21); | 399 queue.Remove(9, 21); |
| 298 EXPECT_EQ(3u, queue.NumIntervals()); | 400 EXPECT_EQ(3u, queue.NumIntervals()); |
| 299 EXPECT_FALSE(queue.Contains(9)); | 401 EXPECT_FALSE(queue.Contains(9)); |
| 300 EXPECT_FALSE(queue.Contains(20)); | 402 EXPECT_FALSE(queue.Contains(20)); |
| 301 } | 403 } |
| 302 | 404 |
| 303 } // namespace | 405 } // namespace |
| 304 } // namespace test | 406 } // namespace test |
| 305 } // namespace net | 407 } // namespace net |
| OLD | NEW |