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

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

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/crypto_test_utils.cc ('k') | net/quic/test_tools/quic_test_utils.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 // Common utilities for Quic tests 5 // Common utilities for Quic tests
6 6
7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
9 9
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "net/quic/congestion_control/send_algorithm_interface.h" 14 #include "net/quic/congestion_control/send_algorithm_interface.h"
15 #include "net/quic/quic_ack_notifier.h" 15 #include "net/quic/quic_ack_notifier.h"
16 #include "net/quic/quic_connection.h" 16 #include "net/quic/quic_connection.h"
17 #include "net/quic/quic_framer.h" 17 #include "net/quic/quic_framer.h"
18 #include "net/quic/quic_session.h" 18 #include "net/quic/quic_session.h"
19 #include "net/quic/quic_spdy_decompressor.h" 19 #include "net/quic/quic_spdy_decompressor.h"
20 #include "net/quic/test_tools/mock_clock.h" 20 #include "net/quic/test_tools/mock_clock.h"
21 #include "net/quic/test_tools/mock_random.h" 21 #include "net/quic/test_tools/mock_random.h"
22 #include "net/spdy/spdy_framer.h" 22 #include "net/spdy/spdy_framer.h"
23 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
24 24
25 namespace net { 25 namespace net {
26 26
27 namespace test { 27 namespace test {
28 28
29 static const QuicGuid kTestGuid = 42;
30 static const int kTestPort = 123;
31
29 // Upper limit on versions we support. 32 // Upper limit on versions we support.
30 QuicVersion QuicVersionMax(); 33 QuicVersion QuicVersionMax();
31 34
32 // Lower limit on versions we support. 35 // Lower limit on versions we support.
33 QuicVersion QuicVersionMin(); 36 QuicVersion QuicVersionMin();
34 37
38 // Returns an address for 127.0.0.1.
39 IPAddressNumber Loopback4();
40
35 void CompareCharArraysWithHexError(const std::string& description, 41 void CompareCharArraysWithHexError(const std::string& description,
36 const char* actual, 42 const char* actual,
37 const int actual_len, 43 const int actual_len,
38 const char* expected, 44 const char* expected,
39 const int expected_len); 45 const int expected_len);
40 46
41 bool DecodeHexString(const base::StringPiece& hex, std::string* bytes); 47 bool DecodeHexString(const base::StringPiece& hex, std::string* bytes);
42 48
43 // Returns the length of a QuicPacket that is capable of holding either a 49 // Returns the length of a QuicPacket that is capable of holding either a
44 // stream frame or a minimal ack frame. Sets |*payload_length| to the number 50 // stream frame or a minimal ack frame. Sets |*payload_length| to the number
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 void AdvanceTime(QuicTime::Delta delta); 243 void AdvanceTime(QuicTime::Delta delta);
238 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate); 244 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate);
239 245
240 private: 246 private:
241 MockClock clock_; 247 MockClock clock_;
242 MockRandom random_generator_; 248 MockRandom random_generator_;
243 }; 249 };
244 250
245 class MockConnection : public QuicConnection { 251 class MockConnection : public QuicConnection {
246 public: 252 public:
247 // Uses a MockHelper. 253 // Uses a MockHelper, GUID of 42, and 127.0.0.1:123.
248 MockConnection(QuicGuid guid, IPEndPoint address, bool is_server); 254 explicit MockConnection(bool is_server);
255
256 // Uses a MockHelper, GUID of 42.
257 MockConnection(IPEndPoint address,
258 bool is_server);
259
260 // Uses a MockHelper, and 127.0.0.1:123
249 MockConnection(QuicGuid guid, 261 MockConnection(QuicGuid guid,
250 IPEndPoint address,
251 QuicConnectionHelperInterface* helper,
252 QuicPacketWriter* writer,
253 bool is_server); 262 bool is_server);
263
254 virtual ~MockConnection(); 264 virtual ~MockConnection();
255 265
256 // If the constructor that uses a MockHelper has been used then this method 266 // If the constructor that uses a MockHelper has been used then this method
257 // will advance the time of the MockClock. 267 // will advance the time of the MockClock.
258 void AdvanceTime(QuicTime::Delta delta); 268 void AdvanceTime(QuicTime::Delta delta);
259 269
260 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address, 270 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address,
261 const IPEndPoint& peer_address, 271 const IPEndPoint& peer_address,
262 const QuicEncryptedPacket& packet)); 272 const QuicEncryptedPacket& packet));
263 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); 273 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error));
(...skipping 11 matching lines...) Expand all
275 const IPEndPoint& peer_address, 285 const IPEndPoint& peer_address,
276 const QuicEncryptedPacket& packet) { 286 const QuicEncryptedPacket& packet) {
277 QuicConnection::ProcessUdpPacket(self_address, peer_address, packet); 287 QuicConnection::ProcessUdpPacket(self_address, peer_address, packet);
278 } 288 }
279 289
280 virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE { 290 virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE {
281 return false; 291 return false;
282 } 292 }
283 293
284 private: 294 private:
285 const bool has_mock_helper_;
286 scoped_ptr<QuicPacketWriter> writer_; 295 scoped_ptr<QuicPacketWriter> writer_;
287 scoped_ptr<QuicConnectionHelperInterface> helper_; 296 scoped_ptr<QuicConnectionHelperInterface> helper_;
288 297
289 DISALLOW_COPY_AND_ASSIGN(MockConnection); 298 DISALLOW_COPY_AND_ASSIGN(MockConnection);
290 }; 299 };
291 300
292 class PacketSavingConnection : public MockConnection { 301 class PacketSavingConnection : public MockConnection {
293 public: 302 public:
294 PacketSavingConnection(QuicGuid guid, IPEndPoint address, bool is_server); 303 explicit PacketSavingConnection(bool is_server);
295 virtual ~PacketSavingConnection(); 304 virtual ~PacketSavingConnection();
296 305
297 virtual bool SendOrQueuePacket(EncryptionLevel level, 306 virtual bool SendOrQueuePacket(EncryptionLevel level,
298 const SerializedPacket& packet, 307 const SerializedPacket& packet,
299 TransmissionType transmission_type) OVERRIDE; 308 TransmissionType transmission_type) OVERRIDE;
300 309
301 std::vector<QuicPacket*> packets_; 310 std::vector<QuicPacket*> packets_;
302 std::vector<QuicEncryptedPacket*> encrypted_packets_; 311 std::vector<QuicEncryptedPacket*> encrypted_packets_;
303 312
304 private: 313 private:
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 MockAckNotifierDelegate(); 445 MockAckNotifierDelegate();
437 virtual ~MockAckNotifierDelegate(); 446 virtual ~MockAckNotifierDelegate();
438 447
439 MOCK_METHOD0(OnAckNotification, void()); 448 MOCK_METHOD0(OnAckNotification, void());
440 }; 449 };
441 450
442 } // namespace test 451 } // namespace test
443 } // namespace net 452 } // namespace net
444 453
445 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 454 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.cc ('k') | net/quic/test_tools/quic_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698