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

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

Issue 114933003: Minor cleanup of QUIC MockConnection and PacketSavingConnection (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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/tools/quic/quic_client_session_test.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 "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "net/quic/crypto/crypto_framer.h" 9 #include "net/quic/crypto/crypto_framer.h"
10 #include "net/quic/crypto/crypto_handshake.h" 10 #include "net/quic/crypto/crypto_handshake.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 224 }
225 225
226 QuicAlarm* MockHelper::CreateAlarm(QuicAlarm::Delegate* delegate) { 226 QuicAlarm* MockHelper::CreateAlarm(QuicAlarm::Delegate* delegate) {
227 return new TestAlarm(delegate); 227 return new TestAlarm(delegate);
228 } 228 }
229 229
230 void MockHelper::AdvanceTime(QuicTime::Delta delta) { 230 void MockHelper::AdvanceTime(QuicTime::Delta delta) {
231 clock_.AdvanceTime(delta); 231 clock_.AdvanceTime(delta);
232 } 232 }
233 233
234 MockConnection::MockConnection(QuicGuid guid, 234 MockConnection::MockConnection(bool is_server)
235 IPEndPoint address, 235 : QuicConnection(kTestGuid,
236 bool is_server) 236 IPEndPoint(Loopback4(), kTestPort),
237 : QuicConnection(guid, address, new testing::NiceMock<MockHelper>(), 237 new testing::NiceMock<MockHelper>(),
238 new testing::NiceMock<MockPacketWriter>(), 238 new testing::NiceMock<MockPacketWriter>(),
239 is_server, QuicSupportedVersions()), 239 is_server, QuicSupportedVersions()),
240 has_mock_helper_(true), 240 writer_(QuicConnectionPeer::GetWriter(this)),
241 helper_(helper()) {
242 }
243
244 MockConnection::MockConnection(IPEndPoint address,
245 bool is_server)
246 : QuicConnection(kTestGuid, address,
247 new testing::NiceMock<MockHelper>(),
248 new testing::NiceMock<MockPacketWriter>(),
249 is_server, QuicSupportedVersions()),
241 writer_(QuicConnectionPeer::GetWriter(this)), 250 writer_(QuicConnectionPeer::GetWriter(this)),
242 helper_(helper()) { 251 helper_(helper()) {
243 } 252 }
244 253
245 MockConnection::MockConnection(QuicGuid guid, 254 MockConnection::MockConnection(QuicGuid guid,
246 IPEndPoint address,
247 QuicConnectionHelperInterface* helper,
248 QuicPacketWriter* writer,
249 bool is_server) 255 bool is_server)
250 : QuicConnection(guid, address, helper, writer, is_server, 256 : QuicConnection(guid,
251 QuicSupportedVersions()), 257 IPEndPoint(Loopback4(), kTestPort),
252 has_mock_helper_(false) { 258 new testing::NiceMock<MockHelper>(),
259 new testing::NiceMock<MockPacketWriter>(),
260 is_server, QuicSupportedVersions()),
261 writer_(QuicConnectionPeer::GetWriter(this)),
262 helper_(helper()) {
253 } 263 }
254 264
255 MockConnection::~MockConnection() { 265 MockConnection::~MockConnection() {
256 } 266 }
257 267
258 void MockConnection::AdvanceTime(QuicTime::Delta delta) { 268 void MockConnection::AdvanceTime(QuicTime::Delta delta) {
259 CHECK(has_mock_helper_) << "Cannot advance time unless a MockClock is being"
260 " used";
261 static_cast<MockHelper*>(helper())->AdvanceTime(delta); 269 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
262 } 270 }
263 271
264 PacketSavingConnection::PacketSavingConnection(QuicGuid guid, 272 PacketSavingConnection::PacketSavingConnection(bool is_server)
265 IPEndPoint address, 273 : MockConnection(is_server) {
266 bool is_server)
267 : MockConnection(guid, address, is_server) {
268 } 274 }
269 275
270 PacketSavingConnection::~PacketSavingConnection() { 276 PacketSavingConnection::~PacketSavingConnection() {
271 STLDeleteElements(&packets_); 277 STLDeleteElements(&packets_);
272 STLDeleteElements(&encrypted_packets_); 278 STLDeleteElements(&encrypted_packets_);
273 } 279 }
274 280
275 bool PacketSavingConnection::SendOrQueuePacket( 281 bool PacketSavingConnection::SendOrQueuePacket(
276 EncryptionLevel level, 282 EncryptionLevel level,
277 const SerializedPacket& packet, 283 const SerializedPacket& packet,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 } 371 }
366 return hex; 372 return hex;
367 } 373 }
368 374
369 } // namespace 375 } // namespace
370 376
371 QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); } 377 QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); }
372 378
373 QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); } 379 QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); }
374 380
381 IPAddressNumber Loopback4() {
382 net::IPAddressNumber addr;
383 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &addr));
384 return addr;
385 }
386
375 void CompareCharArraysWithHexError( 387 void CompareCharArraysWithHexError(
376 const string& description, 388 const string& description,
377 const char* actual, 389 const char* actual,
378 const int actual_len, 390 const int actual_len,
379 const char* expected, 391 const char* expected,
380 const int expected_len) { 392 const int expected_len) {
381 EXPECT_EQ(actual_len, expected_len); 393 EXPECT_EQ(actual_len, expected_len);
382 const int min_len = min(actual_len, expected_len); 394 const int min_len = min(actual_len, expected_len);
383 const int max_len = max(actual_len, expected_len); 395 const int max_len = max(actual_len, expected_len);
384 scoped_ptr<bool[]> marks(new bool[max_len]); 396 scoped_ptr<bool[]> marks(new bool[max_len]);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 data.AppendToString(&data_); 517 data.AppendToString(&data_);
506 return true; 518 return true;
507 } 519 }
508 520
509 void TestDecompressorVisitor::OnDecompressionError() { 521 void TestDecompressorVisitor::OnDecompressionError() {
510 error_ = true; 522 error_ = true;
511 } 523 }
512 524
513 } // namespace test 525 } // namespace test
514 } // namespace net 526 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/tools/quic/quic_client_session_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698