- add sources.
[platform/framework/web/crosswalk.git] / src / net / tools / quic / test_tools / quic_test_utils.cc
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.
4
5 #include "net/tools/quic/test_tools/quic_test_utils.h"
6
7 #include "base/sha1.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"
12
13 using base::StringPiece;
14 using net::test::MockHelper;
15
16 namespace net {
17 namespace tools {
18 namespace test {
19
20 QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); }
21
22 QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); }
23
24 MockConnection::MockConnection(QuicGuid guid,
25                                IPEndPoint address,
26                                int fd,
27                                EpollServer* eps,
28                                bool is_server)
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)),
35       helper_(helper()) {
36 }
37
38 MockConnection::MockConnection(QuicGuid guid,
39                                IPEndPoint address,
40                                bool is_server)
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)),
46       helper_(helper()) {
47 }
48
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() {
60 }
61
62 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);
66 }
67
68 uint64 SimpleRandom::RandUint64() {
69   unsigned char hash[base::kSHA1Length];
70   base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_),
71                       hash);
72   memcpy(&seed_, hash, sizeof(seed_));
73   return seed_;
74 }
75
76 MockQuicSessionOwner::MockQuicSessionOwner() {
77 }
78
79 MockQuicSessionOwner::~MockQuicSessionOwner() {
80 }
81
82 bool TestDecompressorVisitor::OnDecompressedData(StringPiece data) {
83   data.AppendToString(&data_);
84   return true;
85 }
86
87 void TestDecompressorVisitor::OnDecompressionError() {
88   error_ = true;
89 }
90
91 TestSession::TestSession(QuicConnection* connection,
92                          const QuicConfig& config,
93                          bool is_server)
94     : QuicSession(connection, config, is_server),
95       crypto_stream_(NULL) {
96 }
97
98 TestSession::~TestSession() {}
99
100 void TestSession::SetCryptoStream(QuicCryptoStream* stream) {
101   crypto_stream_ = stream;
102 }
103
104 QuicCryptoStream* TestSession::GetCryptoStream() {
105   return crypto_stream_;
106 }
107
108 MockAckNotifierDelegate::MockAckNotifierDelegate() {
109 }
110
111 MockAckNotifierDelegate::~MockAckNotifierDelegate() {
112 }
113
114 MockPacketWriter::MockPacketWriter() {
115 }
116
117 MockPacketWriter::~MockPacketWriter() {
118 }
119
120 }  // namespace test
121 }  // namespace tools
122 }  // namespace net