Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/socket/socket_test_util.h" | 5 #include "net/socket/socket_test_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 result = w->data_len; | 220 result = w->data_len; |
| 221 } | 221 } |
| 222 return MockWriteResult(w->mode, result); | 222 return MockWriteResult(w->mode, result); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void StaticSocketDataProvider::Reset() { | 225 void StaticSocketDataProvider::Reset() { |
| 226 read_index_ = 0; | 226 read_index_ = 0; |
| 227 write_index_ = 0; | 227 write_index_ = 0; |
| 228 } | 228 } |
| 229 | 229 |
| 230 void StaticSocketDataProvider::VerifyCorrectSequenceNumbers() { | |
| 231 size_t read = 0; | |
| 232 size_t write = 0; | |
| 233 int expected = 0; | |
| 234 while (read < read_count_ || write < write_count_) { | |
| 235 // Check to see that we have a read or write at the expected | |
| 236 // state. | |
| 237 if (read < read_count_ && reads_[read].sequence_number == expected) { | |
| 238 ++read; | |
| 239 ++expected; | |
| 240 continue; | |
| 241 } | |
| 242 if (write < write_count_ && writes_[write].sequence_number == expected) { | |
| 243 ++write; | |
| 244 ++expected; | |
| 245 continue; | |
| 246 } | |
| 247 NOTREACHED() << "Missing sequence number: " << expected; | |
| 248 return; | |
| 249 } | |
| 250 DCHECK_EQ(read, read_count_); | |
| 251 DCHECK_EQ(write, write_count_); | |
| 252 } | |
| 253 | |
| 230 DynamicSocketDataProvider::DynamicSocketDataProvider() | 254 DynamicSocketDataProvider::DynamicSocketDataProvider() |
| 231 : short_read_limit_(0), | 255 : short_read_limit_(0), |
| 232 allow_unconsumed_reads_(false) { | 256 allow_unconsumed_reads_(false) { |
| 233 } | 257 } |
| 234 | 258 |
| 235 DynamicSocketDataProvider::~DynamicSocketDataProvider() {} | 259 DynamicSocketDataProvider::~DynamicSocketDataProvider() {} |
| 236 | 260 |
| 237 MockRead DynamicSocketDataProvider::GetNextRead() { | 261 MockRead DynamicSocketDataProvider::GetNextRead() { |
| 238 if (reads_.empty()) | 262 if (reads_.empty()) |
| 239 return MockRead(SYNCHRONOUS, ERR_UNEXPECTED); | 263 return MockRead(SYNCHRONOUS, ERR_UNEXPECTED); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 | 467 |
| 444 DeterministicSocketData::DeterministicSocketData(MockRead* reads, | 468 DeterministicSocketData::DeterministicSocketData(MockRead* reads, |
| 445 size_t reads_count, MockWrite* writes, size_t writes_count) | 469 size_t reads_count, MockWrite* writes, size_t writes_count) |
| 446 : StaticSocketDataProvider(reads, reads_count, writes, writes_count), | 470 : StaticSocketDataProvider(reads, reads_count, writes, writes_count), |
| 447 sequence_number_(0), | 471 sequence_number_(0), |
| 448 current_read_(), | 472 current_read_(), |
| 449 current_write_(), | 473 current_write_(), |
| 450 stopping_sequence_number_(0), | 474 stopping_sequence_number_(0), |
| 451 stopped_(false), | 475 stopped_(false), |
| 452 print_debug_(false) { | 476 print_debug_(false) { |
| 477 VerifyCorrectSequenceNumbers(); | |
|
Ryan Sleevi
2012/07/18 19:14:01
You have access to |reads|, |read_count|, |writes|
Ryan Hamilton
2012/07/18 21:58:20
*facepalm* Duh! Obviously :>
Thanks. Done.
| |
| 453 } | 478 } |
| 454 | 479 |
| 455 DeterministicSocketData::~DeterministicSocketData() {} | 480 DeterministicSocketData::~DeterministicSocketData() {} |
| 456 | 481 |
| 457 void DeterministicSocketData::Run() { | 482 void DeterministicSocketData::Run() { |
| 458 SetStopped(false); | 483 SetStopped(false); |
| 459 int counter = 0; | 484 int counter = 0; |
| 460 // Continue to consume data until all data has run out, or the stopped_ flag | 485 // Continue to consume data until all data has run out, or the stopped_ flag |
| 461 // has been set. Consuming data requires two separate operations -- running | 486 // has been set. Consuming data requires two separate operations -- running |
| 462 // the tasks in the message loop, and explicitly invoking the read/write | 487 // the tasks in the message loop, and explicitly invoking the read/write |
| (...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1643 | 1668 |
| 1644 const char kSOCKS5OkRequest[] = | 1669 const char kSOCKS5OkRequest[] = |
| 1645 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; | 1670 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; |
| 1646 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); | 1671 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); |
| 1647 | 1672 |
| 1648 const char kSOCKS5OkResponse[] = | 1673 const char kSOCKS5OkResponse[] = |
| 1649 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | 1674 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 1650 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); | 1675 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); |
| 1651 | 1676 |
| 1652 } // namespace net | 1677 } // namespace net |
| OLD | NEW |