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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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
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 14 matching lines...) Expand all
25 using testing::_; 25 using testing::_;
26 using testing::AnyNumber; 26 using testing::AnyNumber;
27 27
28 namespace net { 28 namespace net {
29 namespace test { 29 namespace test {
30 namespace { 30 namespace {
31 31
32 // No-op alarm implementation used by MockHelper. 32 // No-op alarm implementation used by MockHelper.
33 class TestAlarm : public QuicAlarm { 33 class TestAlarm : public QuicAlarm {
34 public: 34 public:
35 explicit TestAlarm(QuicAlarm::Delegate* delegate) 35 explicit TestAlarm(QuicAlarm::Delegate* delegate) : QuicAlarm(delegate) {}
36 : QuicAlarm(delegate) {
37 }
38 36
39 virtual void SetImpl() OVERRIDE {} 37 virtual void SetImpl() OVERRIDE {}
40 virtual void CancelImpl() OVERRIDE {} 38 virtual void CancelImpl() OVERRIDE {}
41 }; 39 };
42 40
43 } // namespace 41 } // namespace
44 42
45 QuicAckFrame MakeAckFrame(QuicPacketSequenceNumber largest_observed, 43 QuicAckFrame MakeAckFrame(QuicPacketSequenceNumber largest_observed,
46 QuicPacketSequenceNumber least_unacked) { 44 QuicPacketSequenceNumber least_unacked) {
47 QuicAckFrame ack; 45 QuicAckFrame ack;
48 ack.received_info.largest_observed = largest_observed; 46 ack.received_info.largest_observed = largest_observed;
49 ack.received_info.entropy_hash = 0; 47 ack.received_info.entropy_hash = 0;
50 ack.sent_info.least_unacked = least_unacked; 48 ack.sent_info.least_unacked = least_unacked;
51 ack.sent_info.entropy_hash = 0; 49 ack.sent_info.entropy_hash = 0;
52 return ack; 50 return ack;
53 } 51 }
54 52
55 MockFramerVisitor::MockFramerVisitor() { 53 MockFramerVisitor::MockFramerVisitor() {
56 // By default, we want to accept packets. 54 // By default, we want to accept packets.
57 ON_CALL(*this, OnProtocolVersionMismatch(_)) 55 ON_CALL(*this, OnProtocolVersionMismatch(_))
58 .WillByDefault(testing::Return(false)); 56 .WillByDefault(testing::Return(false));
59 57
60 // By default, we want to accept packets. 58 // By default, we want to accept packets.
61 ON_CALL(*this, OnUnauthenticatedHeader(_)) 59 ON_CALL(*this, OnUnauthenticatedHeader(_))
62 .WillByDefault(testing::Return(true)); 60 .WillByDefault(testing::Return(true));
63 61
64 ON_CALL(*this, OnUnauthenticatedPublicHeader(_)) 62 ON_CALL(*this, OnUnauthenticatedPublicHeader(_))
65 .WillByDefault(testing::Return(true)); 63 .WillByDefault(testing::Return(true));
66 64
67 ON_CALL(*this, OnPacketHeader(_)) 65 ON_CALL(*this, OnPacketHeader(_)).WillByDefault(testing::Return(true));
68 .WillByDefault(testing::Return(true));
69 66
70 ON_CALL(*this, OnStreamFrame(_)) 67 ON_CALL(*this, OnStreamFrame(_)).WillByDefault(testing::Return(true));
71 .WillByDefault(testing::Return(true));
72 68
73 ON_CALL(*this, OnAckFrame(_)) 69 ON_CALL(*this, OnAckFrame(_)).WillByDefault(testing::Return(true));
74 .WillByDefault(testing::Return(true));
75 70
76 ON_CALL(*this, OnCongestionFeedbackFrame(_)) 71 ON_CALL(*this, OnCongestionFeedbackFrame(_))
77 .WillByDefault(testing::Return(true)); 72 .WillByDefault(testing::Return(true));
78 73
79 ON_CALL(*this, OnStopWaitingFrame(_)) 74 ON_CALL(*this, OnStopWaitingFrame(_)).WillByDefault(testing::Return(true));
80 .WillByDefault(testing::Return(true));
81 75
82 ON_CALL(*this, OnPingFrame(_)) 76 ON_CALL(*this, OnPingFrame(_)).WillByDefault(testing::Return(true));
83 .WillByDefault(testing::Return(true));
84 77
85 ON_CALL(*this, OnRstStreamFrame(_)) 78 ON_CALL(*this, OnRstStreamFrame(_)).WillByDefault(testing::Return(true));
86 .WillByDefault(testing::Return(true));
87 79
88 ON_CALL(*this, OnConnectionCloseFrame(_)) 80 ON_CALL(*this, OnConnectionCloseFrame(_))
89 .WillByDefault(testing::Return(true)); 81 .WillByDefault(testing::Return(true));
90 82
91 ON_CALL(*this, OnGoAwayFrame(_)) 83 ON_CALL(*this, OnGoAwayFrame(_)).WillByDefault(testing::Return(true));
92 .WillByDefault(testing::Return(true));
93 } 84 }
94 85
95 MockFramerVisitor::~MockFramerVisitor() { 86 MockFramerVisitor::~MockFramerVisitor() {
96 } 87 }
97 88
98 bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicVersion version) { 89 bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicVersion version) {
99 return false; 90 return false;
100 } 91 }
101 92
102 bool NoOpFramerVisitor::OnUnauthenticatedPublicHeader( 93 bool NoOpFramerVisitor::OnUnauthenticatedPublicHeader(
(...skipping 16 matching lines...) Expand all
119 110
120 bool NoOpFramerVisitor::OnAckFrame(const QuicAckFrame& frame) { 111 bool NoOpFramerVisitor::OnAckFrame(const QuicAckFrame& frame) {
121 return true; 112 return true;
122 } 113 }
123 114
124 bool NoOpFramerVisitor::OnCongestionFeedbackFrame( 115 bool NoOpFramerVisitor::OnCongestionFeedbackFrame(
125 const QuicCongestionFeedbackFrame& frame) { 116 const QuicCongestionFeedbackFrame& frame) {
126 return true; 117 return true;
127 } 118 }
128 119
129 bool NoOpFramerVisitor::OnStopWaitingFrame( 120 bool NoOpFramerVisitor::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) {
130 const QuicStopWaitingFrame& frame) {
131 return true; 121 return true;
132 } 122 }
133 123
134 bool NoOpFramerVisitor::OnPingFrame(const QuicPingFrame& frame) { 124 bool NoOpFramerVisitor::OnPingFrame(const QuicPingFrame& frame) {
135 return true; 125 return true;
136 } 126 }
137 127
138 bool NoOpFramerVisitor::OnRstStreamFrame( 128 bool NoOpFramerVisitor::OnRstStreamFrame(const QuicRstStreamFrame& frame) {
139 const QuicRstStreamFrame& frame) {
140 return true; 129 return true;
141 } 130 }
142 131
143 bool NoOpFramerVisitor::OnConnectionCloseFrame( 132 bool NoOpFramerVisitor::OnConnectionCloseFrame(
144 const QuicConnectionCloseFrame& frame) { 133 const QuicConnectionCloseFrame& frame) {
145 return true; 134 return true;
146 } 135 }
147 136
148 bool NoOpFramerVisitor::OnGoAwayFrame(const QuicGoAwayFrame& frame) { 137 bool NoOpFramerVisitor::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
149 return true; 138 return true;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 173
185 void MockHelper::AdvanceTime(QuicTime::Delta delta) { 174 void MockHelper::AdvanceTime(QuicTime::Delta delta) {
186 clock_.AdvanceTime(delta); 175 clock_.AdvanceTime(delta);
187 } 176 }
188 177
189 MockConnection::MockConnection(bool is_server) 178 MockConnection::MockConnection(bool is_server)
190 : QuicConnection(kTestConnectionId, 179 : QuicConnection(kTestConnectionId,
191 IPEndPoint(TestPeerIPAddress(), kTestPort), 180 IPEndPoint(TestPeerIPAddress(), kTestPort),
192 new testing::NiceMock<MockHelper>(), 181 new testing::NiceMock<MockHelper>(),
193 new testing::NiceMock<MockPacketWriter>(), 182 new testing::NiceMock<MockPacketWriter>(),
194 is_server, QuicSupportedVersions(), 183 is_server,
184 QuicSupportedVersions(),
195 kInitialFlowControlWindowForTest), 185 kInitialFlowControlWindowForTest),
196 writer_(QuicConnectionPeer::GetWriter(this)), 186 writer_(QuicConnectionPeer::GetWriter(this)),
197 helper_(helper()) { 187 helper_(helper()) {
198 } 188 }
199 189
200 MockConnection::MockConnection(IPEndPoint address, 190 MockConnection::MockConnection(IPEndPoint address, bool is_server)
201 bool is_server) 191 : QuicConnection(kTestConnectionId,
202 : QuicConnection(kTestConnectionId, address, 192 address,
203 new testing::NiceMock<MockHelper>(), 193 new testing::NiceMock<MockHelper>(),
204 new testing::NiceMock<MockPacketWriter>(), 194 new testing::NiceMock<MockPacketWriter>(),
205 is_server, QuicSupportedVersions(), 195 is_server,
196 QuicSupportedVersions(),
206 kInitialFlowControlWindowForTest), 197 kInitialFlowControlWindowForTest),
207 writer_(QuicConnectionPeer::GetWriter(this)), 198 writer_(QuicConnectionPeer::GetWriter(this)),
208 helper_(helper()) { 199 helper_(helper()) {
209 } 200 }
210 201
211 MockConnection::MockConnection(QuicConnectionId connection_id, 202 MockConnection::MockConnection(QuicConnectionId connection_id, bool is_server)
212 bool is_server)
213 : QuicConnection(connection_id, 203 : QuicConnection(connection_id,
214 IPEndPoint(TestPeerIPAddress(), kTestPort), 204 IPEndPoint(TestPeerIPAddress(), kTestPort),
215 new testing::NiceMock<MockHelper>(), 205 new testing::NiceMock<MockHelper>(),
216 new testing::NiceMock<MockPacketWriter>(), 206 new testing::NiceMock<MockPacketWriter>(),
217 is_server, QuicSupportedVersions(), 207 is_server,
208 QuicSupportedVersions(),
218 kInitialFlowControlWindowForTest), 209 kInitialFlowControlWindowForTest),
219 writer_(QuicConnectionPeer::GetWriter(this)), 210 writer_(QuicConnectionPeer::GetWriter(this)),
220 helper_(helper()) { 211 helper_(helper()) {
221 } 212 }
222 213
223 MockConnection::MockConnection(bool is_server, 214 MockConnection::MockConnection(bool is_server,
224 const QuicVersionVector& supported_versions) 215 const QuicVersionVector& supported_versions)
225 : QuicConnection(kTestConnectionId, 216 : QuicConnection(kTestConnectionId,
226 IPEndPoint(TestPeerIPAddress(), kTestPort), 217 IPEndPoint(TestPeerIPAddress(), kTestPort),
227 new testing::NiceMock<MockHelper>(), 218 new testing::NiceMock<MockHelper>(),
228 new testing::NiceMock<MockPacketWriter>(), 219 new testing::NiceMock<MockPacketWriter>(),
229 is_server, supported_versions, 220 is_server,
221 supported_versions,
230 kInitialFlowControlWindowForTest), 222 kInitialFlowControlWindowForTest),
231 writer_(QuicConnectionPeer::GetWriter(this)), 223 writer_(QuicConnectionPeer::GetWriter(this)),
232 helper_(helper()) { 224 helper_(helper()) {
233 } 225 }
234 226
235 MockConnection::~MockConnection() { 227 MockConnection::~MockConnection() {
236 } 228 }
237 229
238 void MockConnection::AdvanceTime(QuicTime::Delta delta) { 230 void MockConnection::AdvanceTime(QuicTime::Delta delta) {
239 static_cast<MockHelper*>(helper())->AdvanceTime(delta); 231 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
(...skipping 12 matching lines...) Expand all
252 PacketSavingConnection::~PacketSavingConnection() { 244 PacketSavingConnection::~PacketSavingConnection() {
253 STLDeleteElements(&packets_); 245 STLDeleteElements(&packets_);
254 STLDeleteElements(&encrypted_packets_); 246 STLDeleteElements(&encrypted_packets_);
255 } 247 }
256 248
257 bool PacketSavingConnection::SendOrQueuePacket( 249 bool PacketSavingConnection::SendOrQueuePacket(
258 EncryptionLevel level, 250 EncryptionLevel level,
259 const SerializedPacket& packet, 251 const SerializedPacket& packet,
260 TransmissionType transmission_type) { 252 TransmissionType transmission_type) {
261 packets_.push_back(packet.packet); 253 packets_.push_back(packet.packet);
262 QuicEncryptedPacket* encrypted = QuicConnectionPeer::GetFramer(this)-> 254 QuicEncryptedPacket* encrypted =
263 EncryptPacket(level, packet.sequence_number, *packet.packet); 255 QuicConnectionPeer::GetFramer(this)
256 ->EncryptPacket(level, packet.sequence_number, *packet.packet);
264 encrypted_packets_.push_back(encrypted); 257 encrypted_packets_.push_back(encrypted);
265 return true; 258 return true;
266 } 259 }
267 260
268 MockSession::MockSession(QuicConnection* connection) 261 MockSession::MockSession(QuicConnection* connection)
269 : QuicSession(connection, DefaultQuicConfig()) { 262 : QuicSession(connection, DefaultQuicConfig()) {
270 ON_CALL(*this, WritevData(_, _, _, _, _)) 263 ON_CALL(*this, WritevData(_, _, _, _, _))
271 .WillByDefault(testing::Return(QuicConsumedData(0, false))); 264 .WillByDefault(testing::Return(QuicConsumedData(0, false)));
272 } 265 }
273 266
274 MockSession::~MockSession() { 267 MockSession::~MockSession() {
275 } 268 }
276 269
277 TestSession::TestSession(QuicConnection* connection, 270 TestSession::TestSession(QuicConnection* connection, const QuicConfig& config)
278 const QuicConfig& config) 271 : QuicSession(connection, config), crypto_stream_(NULL) {
279 : QuicSession(connection, config),
280 crypto_stream_(NULL) {
281 } 272 }
282 273
283 TestSession::~TestSession() {} 274 TestSession::~TestSession() {
275 }
284 276
285 void TestSession::SetCryptoStream(QuicCryptoStream* stream) { 277 void TestSession::SetCryptoStream(QuicCryptoStream* stream) {
286 crypto_stream_ = stream; 278 crypto_stream_ = stream;
287 } 279 }
288 280
289 QuicCryptoStream* TestSession::GetCryptoStream() { 281 QuicCryptoStream* TestSession::GetCryptoStream() {
290 return crypto_stream_; 282 return crypto_stream_;
291 } 283 }
292 284
293 TestClientSession::TestClientSession(QuicConnection* connection, 285 TestClientSession::TestClientSession(QuicConnection* connection,
294 const QuicConfig& config) 286 const QuicConfig& config)
295 : QuicClientSessionBase(connection, config), 287 : QuicClientSessionBase(connection, config), crypto_stream_(NULL) {
296 crypto_stream_(NULL) { 288 EXPECT_CALL(*this, OnProofValid(_)).Times(AnyNumber());
297 EXPECT_CALL(*this, OnProofValid(_)).Times(AnyNumber());
298 } 289 }
299 290
300 TestClientSession::~TestClientSession() {} 291 TestClientSession::~TestClientSession() {
292 }
301 293
302 void TestClientSession::SetCryptoStream(QuicCryptoStream* stream) { 294 void TestClientSession::SetCryptoStream(QuicCryptoStream* stream) {
303 crypto_stream_ = stream; 295 crypto_stream_ = stream;
304 } 296 }
305 297
306 QuicCryptoStream* TestClientSession::GetCryptoStream() { 298 QuicCryptoStream* TestClientSession::GetCryptoStream() {
307 return crypto_stream_; 299 return crypto_stream_;
308 } 300 }
309 301
310 MockPacketWriter::MockPacketWriter() { 302 MockPacketWriter::MockPacketWriter() {
(...skipping 15 matching lines...) Expand all
326 } 318 }
327 319
328 MockAckNotifierDelegate::MockAckNotifierDelegate() { 320 MockAckNotifierDelegate::MockAckNotifierDelegate() {
329 } 321 }
330 322
331 MockAckNotifierDelegate::~MockAckNotifierDelegate() { 323 MockAckNotifierDelegate::~MockAckNotifierDelegate() {
332 } 324 }
333 325
334 namespace { 326 namespace {
335 327
336 string HexDumpWithMarks(const char* data, int length, 328 string HexDumpWithMarks(const char* data,
337 const bool* marks, int mark_length) { 329 int length,
330 const bool* marks,
331 int mark_length) {
338 static const char kHexChars[] = "0123456789abcdef"; 332 static const char kHexChars[] = "0123456789abcdef";
339 static const int kColumns = 4; 333 static const int kColumns = 4;
340 334
341 const int kSizeLimit = 1024; 335 const int kSizeLimit = 1024;
342 if (length > kSizeLimit || mark_length > kSizeLimit) { 336 if (length > kSizeLimit || mark_length > kSizeLimit) {
343 LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes."; 337 LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes.";
344 length = min(length, kSizeLimit); 338 length = min(length, kSizeLimit);
345 mark_length = min(mark_length, kSizeLimit); 339 mark_length = min(mark_length, kSizeLimit);
346 } 340 }
347 341
348 string hex; 342 string hex;
349 for (const char* row = data; length > 0; 343 for (const char* row = data; length > 0;
350 row += kColumns, length -= kColumns) { 344 row += kColumns, length -= kColumns) {
351 for (const char *p = row; p < row + 4; ++p) { 345 for (const char* p = row; p < row + 4; ++p) {
352 if (p < row + length) { 346 if (p < row + length) {
353 const bool mark = 347 const bool mark =
354 (marks && (p - data) < mark_length && marks[p - data]); 348 (marks && (p - data) < mark_length && marks[p - data]);
355 hex += mark ? '*' : ' '; 349 hex += mark ? '*' : ' ';
356 hex += kHexChars[(*p & 0xf0) >> 4]; 350 hex += kHexChars[(*p & 0xf0) >> 4];
357 hex += kHexChars[*p & 0x0f]; 351 hex += kHexChars[*p & 0x0f];
358 hex += mark ? '*' : ' '; 352 hex += mark ? '*' : ' ';
359 } else { 353 } else {
360 hex += " "; 354 hex += " ";
361 } 355 }
362 } 356 }
363 hex = hex + " "; 357 hex = hex + " ";
364 358
365 for (const char *p = row; p < row + 4 && p < row + length; ++p) 359 for (const char* p = row; p < row + 4 && p < row + length; ++p)
366 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.'; 360 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.';
367 361
368 hex = hex + '\n'; 362 hex = hex + '\n';
369 } 363 }
370 return hex; 364 return hex;
371 } 365 }
372 366
373 } // namespace 367 } // namespace
374 368
375 IPAddressNumber TestPeerIPAddress() { return Loopback4(); } 369 IPAddressNumber TestPeerIPAddress() {
370 return Loopback4();
371 }
376 372
377 QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); } 373 QuicVersion QuicVersionMax() {
374 return QuicSupportedVersions().front();
375 }
378 376
379 QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); } 377 QuicVersion QuicVersionMin() {
378 return QuicSupportedVersions().back();
379 }
380 380
381 IPAddressNumber Loopback4() { 381 IPAddressNumber Loopback4() {
382 IPAddressNumber addr; 382 IPAddressNumber addr;
383 CHECK(ParseIPLiteralToNumber("127.0.0.1", &addr)); 383 CHECK(ParseIPLiteralToNumber("127.0.0.1", &addr));
384 return addr; 384 return addr;
385 } 385 }
386 386
387 void GenerateBody(string* body, int length) { 387 void GenerateBody(string* body, int length) {
388 body->clear(); 388 body->clear();
389 body->reserve(length); 389 body->reserve(length);
(...skipping 21 matching lines...) Expand all
411 header.is_in_fec_group = NOT_IN_FEC_GROUP; 411 header.is_in_fec_group = NOT_IN_FEC_GROUP;
412 header.fec_group = 0; 412 header.fec_group = 0;
413 QuicStreamFrame stream_frame(1, false, 0, MakeIOVector(data)); 413 QuicStreamFrame stream_frame(1, false, 0, MakeIOVector(data));
414 QuicFrame frame(&stream_frame); 414 QuicFrame frame(&stream_frame);
415 QuicFrames frames; 415 QuicFrames frames;
416 frames.push_back(frame); 416 frames.push_back(frame);
417 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false); 417 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false);
418 scoped_ptr<QuicPacket> packet( 418 scoped_ptr<QuicPacket> packet(
419 framer.BuildUnsizedDataPacket(header, frames).packet); 419 framer.BuildUnsizedDataPacket(header, frames).packet);
420 EXPECT_TRUE(packet != NULL); 420 EXPECT_TRUE(packet != NULL);
421 QuicEncryptedPacket* encrypted = framer.EncryptPacket(ENCRYPTION_NONE, 421 QuicEncryptedPacket* encrypted =
422 sequence_number, 422 framer.EncryptPacket(ENCRYPTION_NONE, sequence_number, *packet);
423 *packet);
424 EXPECT_TRUE(encrypted != NULL); 423 EXPECT_TRUE(encrypted != NULL);
425 return encrypted; 424 return encrypted;
426 } 425 }
427 426
428 void CompareCharArraysWithHexError( 427 void CompareCharArraysWithHexError(const string& description,
429 const string& description, 428 const char* actual,
430 const char* actual, 429 const int actual_len,
431 const int actual_len, 430 const char* expected,
432 const char* expected, 431 const int expected_len) {
433 const int expected_len) {
434 EXPECT_EQ(actual_len, expected_len); 432 EXPECT_EQ(actual_len, expected_len);
435 const int min_len = min(actual_len, expected_len); 433 const int min_len = min(actual_len, expected_len);
436 const int max_len = max(actual_len, expected_len); 434 const int max_len = max(actual_len, expected_len);
437 scoped_ptr<bool[]> marks(new bool[max_len]); 435 scoped_ptr<bool[]> marks(new bool[max_len]);
438 bool identical = (actual_len == expected_len); 436 bool identical = (actual_len == expected_len);
439 for (int i = 0; i < min_len; ++i) { 437 for (int i = 0; i < min_len; ++i) {
440 if (actual[i] != expected[i]) { 438 if (actual[i] != expected[i]) {
441 marks[i] = true; 439 marks[i] = true;
442 identical = false; 440 identical = false;
443 } else { 441 } else {
444 marks[i] = false; 442 marks[i] = false;
445 } 443 }
446 } 444 }
447 for (int i = min_len; i < max_len; ++i) { 445 for (int i = min_len; i < max_len; ++i) {
448 marks[i] = true; 446 marks[i] = true;
449 } 447 }
450 if (identical) return; 448 if (identical)
451 ADD_FAILURE() 449 return;
452 << "Description:\n" 450 ADD_FAILURE() << "Description:\n" << description << "\n\nExpected:\n"
453 << description 451 << HexDumpWithMarks(
454 << "\n\nExpected:\n" 452 expected, expected_len, marks.get(), max_len)
455 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len) 453 << "\nActual:\n"
456 << "\nActual:\n" 454 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len);
457 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len);
458 } 455 }
459 456
460 bool DecodeHexString(const base::StringPiece& hex, std::string* bytes) { 457 bool DecodeHexString(const base::StringPiece& hex, std::string* bytes) {
461 bytes->clear(); 458 bytes->clear();
462 if (hex.empty()) 459 if (hex.empty())
463 return true; 460 return true;
464 std::vector<uint8> v; 461 std::vector<uint8> v;
465 if (!base::HexStringToBytes(hex.as_string(), &v)) 462 if (!base::HexStringToBytes(hex.as_string(), &v))
466 return false; 463 return false;
467 if (!v.empty()) 464 if (!v.empty())
(...skipping 12 matching lines...) Expand all
480 QuicPacketHeader header; 477 QuicPacketHeader header;
481 header.public_header.connection_id = connection_id; 478 header.public_header.connection_id = connection_id;
482 header.public_header.reset_flag = false; 479 header.public_header.reset_flag = false;
483 header.public_header.version_flag = should_include_version; 480 header.public_header.version_flag = should_include_version;
484 header.packet_sequence_number = 1; 481 header.packet_sequence_number = 1;
485 header.entropy_flag = false; 482 header.entropy_flag = false;
486 header.entropy_hash = 0; 483 header.entropy_hash = 0;
487 header.fec_flag = false; 484 header.fec_flag = false;
488 header.fec_group = 0; 485 header.fec_group = 0;
489 486
490 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0, 487 QuicStreamFrame stream_frame(
491 MakeIOVector(data->AsStringPiece())); 488 kCryptoStreamId, false, 0, MakeIOVector(data->AsStringPiece()));
492 489
493 QuicFrame frame(&stream_frame); 490 QuicFrame frame(&stream_frame);
494 QuicFrames frames; 491 QuicFrames frames;
495 frames.push_back(frame); 492 frames.push_back(frame);
496 return quic_framer.BuildUnsizedDataPacket(header, frames).packet; 493 return quic_framer.BuildUnsizedDataPacket(header, frames).packet;
497 } 494 }
498 495
499 QuicPacket* ConstructHandshakePacket(QuicConnectionId connection_id, 496 QuicPacket* ConstructHandshakePacket(QuicConnectionId connection_id,
500 QuicTag tag) { 497 QuicTag tag) {
501 CryptoHandshakeMessage message; 498 CryptoHandshakeMessage message;
502 message.set_tag(tag); 499 message.set_tag(tag);
503 return ConstructPacketFromHandshakeMessage(connection_id, message, false); 500 return ConstructPacketFromHandshakeMessage(connection_id, message, false);
504 } 501 }
505 502
506 size_t GetPacketLengthForOneStream( 503 size_t GetPacketLengthForOneStream(
507 QuicVersion version, 504 QuicVersion version,
508 bool include_version, 505 bool include_version,
509 QuicSequenceNumberLength sequence_number_length, 506 QuicSequenceNumberLength sequence_number_length,
510 InFecGroup is_in_fec_group, 507 InFecGroup is_in_fec_group,
511 size_t* payload_length) { 508 size_t* payload_length) {
512 *payload_length = 1; 509 *payload_length = 1;
513 const size_t stream_length = 510 const size_t stream_length =
514 NullEncrypter().GetCiphertextSize(*payload_length) + 511 NullEncrypter().GetCiphertextSize(*payload_length) +
515 QuicPacketCreator::StreamFramePacketOverhead( 512 QuicPacketCreator::StreamFramePacketOverhead(version,
516 version, PACKET_8BYTE_CONNECTION_ID, include_version, 513 PACKET_8BYTE_CONNECTION_ID,
517 sequence_number_length, is_in_fec_group); 514 include_version,
518 const size_t ack_length = NullEncrypter().GetCiphertextSize( 515 sequence_number_length,
519 QuicFramer::GetMinAckFrameSize( 516 is_in_fec_group);
517 const size_t ack_length =
518 NullEncrypter().GetCiphertextSize(QuicFramer::GetMinAckFrameSize(
520 version, sequence_number_length, PACKET_1BYTE_SEQUENCE_NUMBER)) + 519 version, sequence_number_length, PACKET_1BYTE_SEQUENCE_NUMBER)) +
521 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, include_version, 520 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
522 sequence_number_length, is_in_fec_group); 521 include_version,
522 sequence_number_length,
523 is_in_fec_group);
523 if (stream_length < ack_length) { 524 if (stream_length < ack_length) {
524 *payload_length = 1 + ack_length - stream_length; 525 *payload_length = 1 + ack_length - stream_length;
525 } 526 }
526 527
527 return NullEncrypter().GetCiphertextSize(*payload_length) + 528 return NullEncrypter().GetCiphertextSize(*payload_length) +
528 QuicPacketCreator::StreamFramePacketOverhead( 529 QuicPacketCreator::StreamFramePacketOverhead(
529 version, PACKET_8BYTE_CONNECTION_ID, include_version, 530 version,
530 sequence_number_length, is_in_fec_group); 531 PACKET_8BYTE_CONNECTION_ID,
532 include_version,
533 sequence_number_length,
534 is_in_fec_group);
531 } 535 }
532 536
533 TestEntropyCalculator::TestEntropyCalculator() { } 537 TestEntropyCalculator::TestEntropyCalculator() {
538 }
534 539
535 TestEntropyCalculator::~TestEntropyCalculator() { } 540 TestEntropyCalculator::~TestEntropyCalculator() {
541 }
536 542
537 QuicPacketEntropyHash TestEntropyCalculator::EntropyHash( 543 QuicPacketEntropyHash TestEntropyCalculator::EntropyHash(
538 QuicPacketSequenceNumber sequence_number) const { 544 QuicPacketSequenceNumber sequence_number) const {
539 return 1u; 545 return 1u;
540 } 546 }
541 547
542 MockEntropyCalculator::MockEntropyCalculator() { } 548 MockEntropyCalculator::MockEntropyCalculator() {
549 }
543 550
544 MockEntropyCalculator::~MockEntropyCalculator() { } 551 MockEntropyCalculator::~MockEntropyCalculator() {
552 }
545 553
546 QuicConfig DefaultQuicConfig() { 554 QuicConfig DefaultQuicConfig() {
547 QuicConfig config; 555 QuicConfig config;
548 config.SetDefaults(); 556 config.SetDefaults();
549 return config; 557 return config;
550 } 558 }
551 559
552 QuicVersionVector SupportedVersions(QuicVersion version) { 560 QuicVersionVector SupportedVersions(QuicVersion version) {
553 QuicVersionVector versions; 561 QuicVersionVector versions;
554 versions.push_back(version); 562 versions.push_back(version);
555 return versions; 563 return versions;
556 } 564 }
557 565
558 } // namespace test 566 } // namespace test
559 } // namespace net 567 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698