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

Side by Side Diff: net/tools/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/tools/quic/test_tools/quic_test_utils.h ('k') | no next file » | 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/tools/quic/test_tools/quic_test_utils.h" 5 #include "net/tools/quic/test_tools/quic_test_utils.h"
6 6
7 #include "base/sha1.h" 7 #include "base/sha1.h"
8 #include "net/quic/quic_connection.h" 8 #include "net/quic/quic_connection.h"
9 #include "net/quic/test_tools/quic_connection_peer.h" 9 #include "net/quic/test_tools/quic_connection_peer.h"
10 #include "net/quic/test_tools/quic_test_utils.h" 10 #include "net/quic/test_tools/quic_test_utils.h"
11 #include "net/tools/quic/quic_epoll_connection_helper.h" 11 #include "net/tools/quic/quic_epoll_connection_helper.h"
12 12
13 using base::StringPiece; 13 using base::StringPiece;
14 using net::test::MockHelper; 14 using net::test::MockHelper;
15 15
16 namespace net { 16 namespace net {
17 namespace tools { 17 namespace tools {
18 namespace test { 18 namespace test {
19 19
20 QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); } 20 MockConnection::MockConnection(bool is_server)
21 : QuicConnection(kTestGuid,
22 IPEndPoint(net::test::Loopback4(), kTestPort),
23 new testing::NiceMock<MockHelper>(),
24 new testing::NiceMock<MockPacketWriter>(),
25 is_server, QuicSupportedVersions()),
26 writer_(net::test::QuicConnectionPeer::GetWriter(this)),
27 helper_(helper()) {
28 }
21 29
22 QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); } 30 MockConnection::MockConnection(IPEndPoint address,
23
24 MockConnection::MockConnection(QuicGuid guid,
25 IPEndPoint address,
26 int fd,
27 EpollServer* eps,
28 bool is_server) 31 bool is_server)
29 : QuicConnection(guid, address, 32 : QuicConnection(kTestGuid, address,
30 new QuicEpollConnectionHelper(eps), 33 new testing::NiceMock<MockHelper>(),
31 new QuicDefaultPacketWriter(fd), is_server, 34 new testing::NiceMock<MockPacketWriter>(),
32 QuicSupportedVersions()), 35 is_server, QuicSupportedVersions()),
33 has_mock_helper_(false),
34 writer_(net::test::QuicConnectionPeer::GetWriter(this)), 36 writer_(net::test::QuicConnectionPeer::GetWriter(this)),
35 helper_(helper()) { 37 helper_(helper()) {
36 } 38 }
37 39
38 MockConnection::MockConnection(QuicGuid guid, 40 MockConnection::MockConnection(QuicGuid guid,
39 IPEndPoint address,
40 bool is_server) 41 bool is_server)
41 : QuicConnection(guid, address, new testing::NiceMock<MockHelper>(), 42 : QuicConnection(guid,
43 IPEndPoint(net::test::Loopback4(), kTestPort),
44 new testing::NiceMock<MockHelper>(),
42 new testing::NiceMock<MockPacketWriter>(), 45 new testing::NiceMock<MockPacketWriter>(),
43 is_server, QuicSupportedVersions()), 46 is_server, QuicSupportedVersions()),
44 has_mock_helper_(true),
45 writer_(net::test::QuicConnectionPeer::GetWriter(this)), 47 writer_(net::test::QuicConnectionPeer::GetWriter(this)),
46 helper_(helper()) { 48 helper_(helper()) {
47 } 49 }
48 50
49 MockConnection::MockConnection(QuicGuid guid,
50 IPEndPoint address,
51 QuicConnectionHelperInterface* helper,
52 QuicPacketWriter* writer,
53 bool is_server)
54 : QuicConnection(guid, address, helper, writer, is_server,
55 QuicSupportedVersions()),
56 has_mock_helper_(false) {
57 }
58
59 MockConnection::~MockConnection() { 51 MockConnection::~MockConnection() {
60 } 52 }
61 53
62 void MockConnection::AdvanceTime(QuicTime::Delta delta) { 54 void MockConnection::AdvanceTime(QuicTime::Delta delta) {
63 CHECK(has_mock_helper_) << "Cannot advance time unless a MockClock is being"
64 " used";
65 static_cast<MockHelper*>(helper())->AdvanceTime(delta); 55 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
66 } 56 }
67 57
68 uint64 SimpleRandom::RandUint64() { 58 uint64 SimpleRandom::RandUint64() {
69 unsigned char hash[base::kSHA1Length]; 59 unsigned char hash[base::kSHA1Length];
70 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_), 60 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_),
71 hash); 61 hash);
72 memcpy(&seed_, hash, sizeof(seed_)); 62 memcpy(&seed_, hash, sizeof(seed_));
73 return seed_; 63 return seed_;
74 } 64 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 103
114 MockAckNotifierDelegate::MockAckNotifierDelegate() { 104 MockAckNotifierDelegate::MockAckNotifierDelegate() {
115 } 105 }
116 106
117 MockAckNotifierDelegate::~MockAckNotifierDelegate() { 107 MockAckNotifierDelegate::~MockAckNotifierDelegate() {
118 } 108 }
119 109
120 } // namespace test 110 } // namespace test
121 } // namespace tools 111 } // namespace tools
122 } // namespace net 112 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/test_tools/quic_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698