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

Side by Side Diff: net/socket/socket_test_util.cc

Issue 10795012: Modify DeterministicSocketData to verify that the sequence number of reads and writes start at zero… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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/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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 MockWrite* writes, 156 MockWrite* writes,
157 size_t writes_count) 157 size_t writes_count)
158 : reads_(reads), 158 : reads_(reads),
159 read_index_(0), 159 read_index_(0),
160 read_count_(reads_count), 160 read_count_(reads_count),
161 writes_(writes), 161 writes_(writes),
162 write_index_(0), 162 write_index_(0),
163 write_count_(writes_count) { 163 write_count_(writes_count) {
164 } 164 }
165 165
166 StaticSocketDataProvider::StaticSocketDataProvider(
167 bool verify_sequence_numbers,
168 MockRead* reads,
169 size_t reads_count,
170 MockWrite* writes,
171 size_t writes_count)
172 : reads_(reads),
173 read_index_(0),
174 read_count_(reads_count),
175 writes_(writes),
176 write_index_(0),
177 write_count_(writes_count) {
178 if (verify_sequence_numbers)
179 VerifyCorrectSequenceNumbers();
180 }
181
166 StaticSocketDataProvider::~StaticSocketDataProvider() {} 182 StaticSocketDataProvider::~StaticSocketDataProvider() {}
167 183
168 const MockRead& StaticSocketDataProvider::PeekRead() const { 184 const MockRead& StaticSocketDataProvider::PeekRead() const {
169 DCHECK(!at_read_eof()); 185 DCHECK(!at_read_eof());
170 return reads_[read_index_]; 186 return reads_[read_index_];
171 } 187 }
172 188
173 const MockWrite& StaticSocketDataProvider::PeekWrite() const { 189 const MockWrite& StaticSocketDataProvider::PeekWrite() const {
174 DCHECK(!at_write_eof()); 190 DCHECK(!at_write_eof());
175 return writes_[write_index_]; 191 return writes_[write_index_];
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 result = w->data_len; 236 result = w->data_len;
221 } 237 }
222 return MockWriteResult(w->mode, result); 238 return MockWriteResult(w->mode, result);
223 } 239 }
224 240
225 void StaticSocketDataProvider::Reset() { 241 void StaticSocketDataProvider::Reset() {
226 read_index_ = 0; 242 read_index_ = 0;
227 write_index_ = 0; 243 write_index_ = 0;
228 } 244 }
229 245
246 void StaticSocketDataProvider::VerifyCorrectSequenceNumbers() {
247 size_t read = 0;
248 size_t write = 0;
249 int expected = 0;
250 while (read < read_count_ || write < write_count_) {
251 // Check to see that we have a read or write at the expected
252 // state.
253 if (read < read_count_ && reads_[read].sequence_number == expected) {
254 ++read;
255 ++expected;
256 continue;
257 }
258 if (write < write_count_ && writes_[write].sequence_number == expected) {
259 ++write;
260 ++expected;
261 continue;
262 }
263 EXPECT_TRUE(false) << "Missing sequence number: " << expected;
264 return;
265 }
266 EXPECT_EQ(read, read_count_);
267 EXPECT_EQ(write, write_count_);
Ryan Sleevi 2012/07/18 18:02:13 Rather than EXPECT_TRUE(false) [which is really AD
Ryan Hamilton 2012/07/18 18:45:06 Done. Fair enough. Using EXPECT happened to be s
268 }
269
230 DynamicSocketDataProvider::DynamicSocketDataProvider() 270 DynamicSocketDataProvider::DynamicSocketDataProvider()
231 : short_read_limit_(0), 271 : short_read_limit_(0),
232 allow_unconsumed_reads_(false) { 272 allow_unconsumed_reads_(false) {
233 } 273 }
234 274
235 DynamicSocketDataProvider::~DynamicSocketDataProvider() {} 275 DynamicSocketDataProvider::~DynamicSocketDataProvider() {}
236 276
237 MockRead DynamicSocketDataProvider::GetNextRead() { 277 MockRead DynamicSocketDataProvider::GetNextRead() {
238 if (reads_.empty()) 278 if (reads_.empty())
239 return MockRead(SYNCHRONOUS, ERR_UNEXPECTED); 279 return MockRead(SYNCHRONOUS, ERR_UNEXPECTED);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 if (socket() && blocked_) { 476 if (socket() && blocked_) {
437 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_; 477 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_;
438 socket()->OnReadComplete(GetNextRead()); 478 socket()->OnReadComplete(GetNextRead());
439 } 479 }
440 } 480 }
441 481
442 OrderedSocketData::~OrderedSocketData() {} 482 OrderedSocketData::~OrderedSocketData() {}
443 483
444 DeterministicSocketData::DeterministicSocketData(MockRead* reads, 484 DeterministicSocketData::DeterministicSocketData(MockRead* reads,
445 size_t reads_count, MockWrite* writes, size_t writes_count) 485 size_t reads_count, MockWrite* writes, size_t writes_count)
446 : StaticSocketDataProvider(reads, reads_count, writes, writes_count), 486 : StaticSocketDataProvider(true, reads, reads_count, writes, writes_count),
447 sequence_number_(0), 487 sequence_number_(0),
448 current_read_(), 488 current_read_(),
449 current_write_(), 489 current_write_(),
450 stopping_sequence_number_(0), 490 stopping_sequence_number_(0),
451 stopped_(false), 491 stopped_(false),
452 print_debug_(false) { 492 print_debug_(false) {
453 } 493 }
454 494
455 DeterministicSocketData::~DeterministicSocketData() {} 495 DeterministicSocketData::~DeterministicSocketData() {}
456 496
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 1683
1644 const char kSOCKS5OkRequest[] = 1684 const char kSOCKS5OkRequest[] =
1645 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; 1685 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 };
1646 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); 1686 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest);
1647 1687
1648 const char kSOCKS5OkResponse[] = 1688 const char kSOCKS5OkResponse[] =
1649 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; 1689 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
1650 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); 1690 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse);
1651 1691
1652 } // namespace net 1692 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698