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
3 // found in the LICENSE file.
5 #include "net/tools/quic/test_tools/quic_test_utils.h"
8 #include "net/quic/quic_connection.h"
9 #include "net/quic/test_tools/quic_connection_peer.h"
10 #include "net/quic/test_tools/quic_test_utils.h"
11 #include "net/tools/quic/quic_epoll_connection_helper.h"
13 using base::StringPiece;
14 using net::test::MockHelper;
20 QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); }
22 QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); }
24 MockConnection::MockConnection(QuicGuid guid,
29 : QuicConnection(guid, address,
30 new QuicEpollConnectionHelper(eps),
31 new QuicDefaultPacketWriter(fd), is_server,
32 QuicSupportedVersions()),
33 has_mock_helper_(false),
34 writer_(net::test::QuicConnectionPeer::GetWriter(this)),
38 MockConnection::MockConnection(QuicGuid guid,
41 : QuicConnection(guid, address, new testing::NiceMock<MockHelper>(),
42 new testing::NiceMock<MockPacketWriter>(),
43 is_server, QuicSupportedVersions()),
44 has_mock_helper_(true),
45 writer_(net::test::QuicConnectionPeer::GetWriter(this)),
49 MockConnection::MockConnection(QuicGuid guid,
51 QuicConnectionHelperInterface* helper,
52 QuicPacketWriter* writer,
54 : QuicConnection(guid, address, helper, writer, is_server,
55 QuicSupportedVersions()),
56 has_mock_helper_(false) {
59 MockConnection::~MockConnection() {
62 void MockConnection::AdvanceTime(QuicTime::Delta delta) {
63 CHECK(has_mock_helper_) << "Cannot advance time unless a MockClock is being"
65 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
68 uint64 SimpleRandom::RandUint64() {
69 unsigned char hash[base::kSHA1Length];
70 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_),
72 memcpy(&seed_, hash, sizeof(seed_));
76 MockQuicSessionOwner::MockQuicSessionOwner() {
79 MockQuicSessionOwner::~MockQuicSessionOwner() {
82 bool TestDecompressorVisitor::OnDecompressedData(StringPiece data) {
83 data.AppendToString(&data_);
87 void TestDecompressorVisitor::OnDecompressionError() {
91 TestSession::TestSession(QuicConnection* connection,
92 const QuicConfig& config,
94 : QuicSession(connection, config, is_server),
95 crypto_stream_(NULL) {
98 TestSession::~TestSession() {}
100 void TestSession::SetCryptoStream(QuicCryptoStream* stream) {
101 crypto_stream_ = stream;
104 QuicCryptoStream* TestSession::GetCryptoStream() {
105 return crypto_stream_;
108 MockAckNotifierDelegate::MockAckNotifierDelegate() {
111 MockAckNotifierDelegate::~MockAckNotifierDelegate() {
114 MockPacketWriter::MockPacketWriter() {
117 MockPacketWriter::~MockPacketWriter() {