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

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: Fix rebase problem. 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
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/spdy/spdy_network_transaction_spdy2_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 443
444 DeterministicSocketData::DeterministicSocketData(MockRead* reads, 444 DeterministicSocketData::DeterministicSocketData(MockRead* reads,
445 size_t reads_count, MockWrite* writes, size_t writes_count) 445 size_t reads_count, MockWrite* writes, size_t writes_count)
446 : StaticSocketDataProvider(reads, reads_count, writes, writes_count), 446 : StaticSocketDataProvider(reads, reads_count, writes, writes_count),
447 sequence_number_(0), 447 sequence_number_(0),
448 current_read_(), 448 current_read_(),
449 current_write_(), 449 current_write_(),
450 stopping_sequence_number_(0), 450 stopping_sequence_number_(0),
451 stopped_(false), 451 stopped_(false),
452 print_debug_(false) { 452 print_debug_(false) {
453 VerifyCorrectSequenceNumbers(reads, reads_count, writes, writes_count);
453 } 454 }
454 455
455 DeterministicSocketData::~DeterministicSocketData() {} 456 DeterministicSocketData::~DeterministicSocketData() {}
456 457
457 void DeterministicSocketData::Run() { 458 void DeterministicSocketData::Run() {
458 SetStopped(false); 459 SetStopped(false);
459 int counter = 0; 460 int counter = 0;
460 // Continue to consume data until all data has run out, or the stopped_ flag 461 // 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 462 // has been set. Consuming data requires two separate operations -- running
462 // the tasks in the message loop, and explicitly invoking the read/write 463 // the tasks in the message loop, and explicitly invoking the read/write
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 } 597 }
597 598
598 void DeterministicSocketData::NextStep() { 599 void DeterministicSocketData::NextStep() {
599 // Invariant: Can never move *past* the stopping step. 600 // Invariant: Can never move *past* the stopping step.
600 DCHECK_LT(sequence_number_, stopping_sequence_number_); 601 DCHECK_LT(sequence_number_, stopping_sequence_number_);
601 sequence_number_++; 602 sequence_number_++;
602 if (sequence_number_ == stopping_sequence_number_) 603 if (sequence_number_ == stopping_sequence_number_)
603 SetStopped(true); 604 SetStopped(true);
604 } 605 }
605 606
607 void DeterministicSocketData::VerifyCorrectSequenceNumbers(
608 MockRead* reads, size_t reads_count,
609 MockWrite* writes, size_t writes_count) {
610 size_t read = 0;
611 size_t write = 0;
612 int expected = 0;
613 while (read < reads_count || write < writes_count) {
614 // Check to see that we have a read or write at the expected
615 // state.
616 if (read < reads_count && reads[read].sequence_number == expected) {
617 ++read;
618 ++expected;
619 continue;
620 }
621 if (write < writes_count && writes[write].sequence_number == expected) {
622 ++write;
623 ++expected;
624 continue;
625 }
626 NOTREACHED() << "Missing sequence number: " << expected;
627 return;
628 }
629 DCHECK_EQ(read, reads_count);
630 DCHECK_EQ(write, writes_count);
631 }
632
606 MockClientSocketFactory::MockClientSocketFactory() {} 633 MockClientSocketFactory::MockClientSocketFactory() {}
607 634
608 MockClientSocketFactory::~MockClientSocketFactory() {} 635 MockClientSocketFactory::~MockClientSocketFactory() {}
609 636
610 void MockClientSocketFactory::AddSocketDataProvider( 637 void MockClientSocketFactory::AddSocketDataProvider(
611 SocketDataProvider* data) { 638 SocketDataProvider* data) {
612 mock_data_.Add(data); 639 mock_data_.Add(data);
613 } 640 }
614 641
615 void MockClientSocketFactory::AddSSLSocketDataProvider( 642 void MockClientSocketFactory::AddSSLSocketDataProvider(
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 1683
1657 const char kSOCKS5OkRequest[] = 1684 const char kSOCKS5OkRequest[] =
1658 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; 1685 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 };
1659 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); 1686 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest);
1660 1687
1661 const char kSOCKS5OkResponse[] = 1688 const char kSOCKS5OkResponse[] =
1662 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; 1689 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
1663 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); 1690 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse);
1664 1691
1665 } // namespace net 1692 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/spdy/spdy_network_transaction_spdy2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698