Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: net/quic/test_tools/quic_test_utils.cc

Issue 47283002: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compilation error Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/quic/test_tools/simple_quic_framer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/test_tools/quic_test_utils.h" 5 #include "net/quic/test_tools/quic_test_utils.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "net/quic/crypto/crypto_framer.h" 8 #include "net/quic/crypto/crypto_framer.h"
9 #include "net/quic/crypto/crypto_handshake.h" 9 #include "net/quic/crypto/crypto_handshake.h"
10 #include "net/quic/crypto/crypto_utils.h" 10 #include "net/quic/crypto/crypto_utils.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 void MockHelper::AdvanceTime(QuicTime::Delta delta) { 207 void MockHelper::AdvanceTime(QuicTime::Delta delta) {
208 clock_.AdvanceTime(delta); 208 clock_.AdvanceTime(delta);
209 } 209 }
210 210
211 MockConnection::MockConnection(QuicGuid guid, 211 MockConnection::MockConnection(QuicGuid guid,
212 IPEndPoint address, 212 IPEndPoint address,
213 bool is_server) 213 bool is_server)
214 : QuicConnection(guid, address, new testing::NiceMock<MockHelper>(), 214 : QuicConnection(guid, address, new testing::NiceMock<MockHelper>(),
215 new testing::NiceMock<MockPacketWriter>(), 215 new testing::NiceMock<MockPacketWriter>(),
216 is_server, QuicVersionMax()), 216 is_server, QuicSupportedVersions()),
217 has_mock_helper_(true), 217 has_mock_helper_(true),
218 writer_(QuicConnectionPeer::GetWriter(this)), 218 writer_(QuicConnectionPeer::GetWriter(this)),
219 helper_(helper()) { 219 helper_(helper()) {
220 } 220 }
221 221
222 MockConnection::MockConnection(QuicGuid guid, 222 MockConnection::MockConnection(QuicGuid guid,
223 IPEndPoint address, 223 IPEndPoint address,
224 QuicConnectionHelperInterface* helper, 224 QuicConnectionHelperInterface* helper,
225 QuicPacketWriter* writer, 225 QuicPacketWriter* writer,
226 bool is_server) 226 bool is_server)
227 : QuicConnection(guid, address, helper, writer, is_server, 227 : QuicConnection(guid, address, helper, writer, is_server,
228 QuicVersionMax()), 228 QuicSupportedVersions()),
229 has_mock_helper_(false) { 229 has_mock_helper_(false) {
230 } 230 }
231 231
232 MockConnection::~MockConnection() { 232 MockConnection::~MockConnection() {
233 } 233 }
234 234
235 void MockConnection::AdvanceTime(QuicTime::Delta delta) { 235 void MockConnection::AdvanceTime(QuicTime::Delta delta) {
236 CHECK(has_mock_helper_) << "Cannot advance time unless a MockClock is being" 236 CHECK(has_mock_helper_) << "Cannot advance time unless a MockClock is being"
237 " used"; 237 " used";
238 static_cast<MockHelper*>(helper())->AdvanceTime(delta); 238 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 for (const char *p = row; p < row + 4 && p < row + length; ++p) 343 for (const char *p = row; p < row + 4 && p < row + length; ++p)
344 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.'; 344 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.';
345 345
346 hex = hex + '\n'; 346 hex = hex + '\n';
347 } 347 }
348 return hex; 348 return hex;
349 } 349 }
350 350
351 } // namespace 351 } // namespace
352 352
353 QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); }
354
355 QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); }
356
353 void CompareCharArraysWithHexError( 357 void CompareCharArraysWithHexError(
354 const string& description, 358 const string& description,
355 const char* actual, 359 const char* actual,
356 const int actual_len, 360 const int actual_len,
357 const char* expected, 361 const char* expected,
358 const int expected_len) { 362 const int expected_len) {
363 EXPECT_EQ(actual_len, expected_len);
359 const int min_len = min(actual_len, expected_len); 364 const int min_len = min(actual_len, expected_len);
360 const int max_len = max(actual_len, expected_len); 365 const int max_len = max(actual_len, expected_len);
361 scoped_ptr<bool[]> marks(new bool[max_len]); 366 scoped_ptr<bool[]> marks(new bool[max_len]);
362 bool identical = (actual_len == expected_len); 367 bool identical = (actual_len == expected_len);
363 for (int i = 0; i < min_len; ++i) { 368 for (int i = 0; i < min_len; ++i) {
364 if (actual[i] != expected[i]) { 369 if (actual[i] != expected[i]) {
365 marks[i] = true; 370 marks[i] = true;
366 identical = false; 371 identical = false;
367 } else { 372 } else {
368 marks[i] = false; 373 marks[i] = false;
(...skipping 11 matching lines...) Expand all
380 << "\nActual:\n" 385 << "\nActual:\n"
381 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len); 386 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len);
382 } 387 }
383 388
384 static QuicPacket* ConstructPacketFromHandshakeMessage( 389 static QuicPacket* ConstructPacketFromHandshakeMessage(
385 QuicGuid guid, 390 QuicGuid guid,
386 const CryptoHandshakeMessage& message, 391 const CryptoHandshakeMessage& message,
387 bool should_include_version) { 392 bool should_include_version) {
388 CryptoFramer crypto_framer; 393 CryptoFramer crypto_framer;
389 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message)); 394 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message));
390 QuicFramer quic_framer(QuicVersionMax(), QuicTime::Zero(), false); 395 QuicFramer quic_framer(QuicSupportedVersions(), QuicTime::Zero(), false);
391 396
392 QuicPacketHeader header; 397 QuicPacketHeader header;
393 header.public_header.guid = guid; 398 header.public_header.guid = guid;
394 header.public_header.reset_flag = false; 399 header.public_header.reset_flag = false;
395 header.public_header.version_flag = should_include_version; 400 header.public_header.version_flag = should_include_version;
396 header.packet_sequence_number = 1; 401 header.packet_sequence_number = 1;
397 header.entropy_flag = false; 402 header.entropy_flag = false;
398 header.entropy_hash = 0; 403 header.entropy_hash = 0;
399 header.fec_flag = false; 404 header.fec_flag = false;
400 header.fec_group = 0; 405 header.fec_group = 0;
(...skipping 13 matching lines...) Expand all
414 return ConstructPacketFromHandshakeMessage(guid, message, false); 419 return ConstructPacketFromHandshakeMessage(guid, message, false);
415 } 420 }
416 421
417 size_t GetPacketLengthForOneStream( 422 size_t GetPacketLengthForOneStream(
418 QuicVersion version, 423 QuicVersion version,
419 bool include_version, 424 bool include_version,
420 QuicSequenceNumberLength sequence_number_length, 425 QuicSequenceNumberLength sequence_number_length,
421 InFecGroup is_in_fec_group, 426 InFecGroup is_in_fec_group,
422 size_t* payload_length) { 427 size_t* payload_length) {
423 *payload_length = 1; 428 *payload_length = 1;
424 bool use_short_hash = version >= QUIC_VERSION_11;
425 const size_t stream_length = 429 const size_t stream_length =
426 NullEncrypter(use_short_hash).GetCiphertextSize(*payload_length) + 430 NullEncrypter(false).GetCiphertextSize(*payload_length) +
427 QuicPacketCreator::StreamFramePacketOverhead( 431 QuicPacketCreator::StreamFramePacketOverhead(
428 version, PACKET_8BYTE_GUID, include_version, 432 version, PACKET_8BYTE_GUID, include_version,
429 sequence_number_length, is_in_fec_group); 433 sequence_number_length, is_in_fec_group);
430 const size_t ack_length = NullEncrypter(use_short_hash).GetCiphertextSize( 434 const size_t ack_length = NullEncrypter(false).GetCiphertextSize(
431 QuicFramer::GetMinAckFrameSize()) + 435 QuicFramer::GetMinAckFrameSize()) +
432 GetPacketHeaderSize(PACKET_8BYTE_GUID, include_version, 436 GetPacketHeaderSize(PACKET_8BYTE_GUID, include_version,
433 sequence_number_length, is_in_fec_group); 437 sequence_number_length, is_in_fec_group);
434 if (stream_length < ack_length) { 438 if (stream_length < ack_length) {
435 *payload_length = 1 + ack_length - stream_length; 439 *payload_length = 1 + ack_length - stream_length;
436 } 440 }
437 441
438 return NullEncrypter(use_short_hash).GetCiphertextSize(*payload_length) + 442 return NullEncrypter(false).GetCiphertextSize(*payload_length) +
439 QuicPacketCreator::StreamFramePacketOverhead( 443 QuicPacketCreator::StreamFramePacketOverhead(
440 version, PACKET_8BYTE_GUID, include_version, 444 version, PACKET_8BYTE_GUID, include_version,
441 sequence_number_length, is_in_fec_group); 445 sequence_number_length, is_in_fec_group);
442 } 446 }
443 447
444 // Size in bytes of the stream frame fields for an arbitrary StreamID and 448 // Size in bytes of the stream frame fields for an arbitrary StreamID and
445 // offset and the last frame in a packet. 449 // offset and the last frame in a packet.
446 size_t GetMinStreamFrameSize(QuicVersion version) { 450 size_t GetMinStreamFrameSize(QuicVersion version) {
447 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize; 451 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize;
448 } 452 }
(...skipping 13 matching lines...) Expand all
462 data.AppendToString(&data_); 466 data.AppendToString(&data_);
463 return true; 467 return true;
464 } 468 }
465 469
466 void TestDecompressorVisitor::OnDecompressionError() { 470 void TestDecompressorVisitor::OnDecompressionError() {
467 error_ = true; 471 error_ = true;
468 } 472 }
469 473
470 } // namespace test 474 } // namespace test
471 } // namespace net 475 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/quic/test_tools/simple_quic_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698