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

Unified Diff: net/socket/socket_test_util.cc

Issue 1114383003: Add AllReadDataConsumed and AllWriteDataConsumed methods to SocketDataProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: net/socket/socket_test_util.cc
diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc
index cf033c245c3e86c8b5c427c2dc061e49172b7a3a..4df69d2fa1ccfe46bed35f6bf2e6e54d87fe2f47 100644
--- a/net/socket/socket_test_util.cc
+++ b/net/socket/socket_test_util.cc
@@ -156,27 +156,27 @@ StaticSocketDataHelper::~StaticSocketDataHelper() {
}
const MockRead& StaticSocketDataHelper::PeekRead() const {
- CHECK(!at_read_eof());
+ CHECK(!AllReadDataConsumed());
return reads_[read_index_];
}
const MockWrite& StaticSocketDataHelper::PeekWrite() const {
- CHECK(!at_write_eof());
+ CHECK(!AllWriteDataConsumed());
return writes_[write_index_];
}
const MockRead& StaticSocketDataHelper::AdvanceRead() {
- CHECK(!at_read_eof());
+ CHECK(!AllReadDataConsumed());
return reads_[read_index_++];
}
const MockWrite& StaticSocketDataHelper::AdvanceWrite() {
- CHECK(!at_write_eof());
+ CHECK(!AllWriteDataConsumed());
return writes_[write_index_++];
}
bool StaticSocketDataHelper::VerifyWriteData(const std::string& data) {
- CHECK(!at_write_eof());
+ CHECK(!AllWriteDataConsumed());
// Check that what the actual data matches the expectations.
const MockWrite& next_write = PeekWrite();
if (!next_write.data)
@@ -195,6 +195,14 @@ bool StaticSocketDataHelper::VerifyWriteData(const std::string& data) {
return expected_data == actual_data;
}
+bool StaticSocketDataHelper::AllReadDataConsumed() const {
+ return read_index_ >= read_count_;
+}
+
+bool StaticSocketDataHelper::AllWriteDataConsumed() const {
+ return write_index_ >= write_count_;
+}
+
void StaticSocketDataHelper::Reset() {
read_index_ = 0;
write_index_ = 0;
@@ -215,7 +223,7 @@ StaticSocketDataProvider::~StaticSocketDataProvider() {
}
MockRead StaticSocketDataProvider::OnRead() {
- CHECK(!helper_.at_read_eof());
+ CHECK(!helper_.AllReadDataConsumed());
return helper_.AdvanceRead();
}
@@ -224,8 +232,8 @@ MockWriteResult StaticSocketDataProvider::OnWrite(const std::string& data) {
// Not using mock writes; succeed synchronously.
return MockWriteResult(SYNCHRONOUS, data.length());
}
- EXPECT_FALSE(helper_.at_write_eof());
- if (helper_.at_write_eof()) {
+ EXPECT_FALSE(helper_.AllWriteDataConsumed());
+ if (helper_.AllWriteDataConsumed()) {
// Show what the extra write actually consists of.
EXPECT_EQ("<unexpected write>", data);
return MockWriteResult(SYNCHRONOUS, ERR_UNEXPECTED);
@@ -248,6 +256,14 @@ void StaticSocketDataProvider::Reset() {
helper_.Reset();
}
+bool StaticSocketDataProvider::AllReadDataConsumed() const {
+ return helper_.AllReadDataConsumed();
+}
+
+bool StaticSocketDataProvider::AllWriteDataConsumed() const {
+ return helper_.AllWriteDataConsumed();
+}
+
DynamicSocketDataProvider::DynamicSocketDataProvider()
: short_read_limit_(0),
allow_unconsumed_reads_(false) {
@@ -508,7 +524,7 @@ SequencedSocketData::SequencedSocketData(const MockConnect& connect,
MockRead SequencedSocketData::OnRead() {
CHECK_EQ(IDLE, read_state_);
- CHECK(!helper_.at_read_eof());
+ CHECK(!helper_.AllReadDataConsumed());
NET_TRACE(1, " *** ") << "sequence_number: " << sequence_number_;
const MockRead& next_read = helper_.PeekRead();
@@ -520,7 +536,7 @@ MockRead SequencedSocketData::OnRead() {
NET_TRACE(1, " *** ") << "Hanging read";
helper_.AdvanceRead();
++sequence_number_;
- CHECK(helper_.at_read_eof());
+ CHECK(helper_.AllReadDataConsumed());
return MockRead(SYNCHRONOUS, ERR_IO_PENDING);
}
@@ -552,7 +568,7 @@ MockRead SequencedSocketData::OnRead() {
MockWriteResult SequencedSocketData::OnWrite(const std::string& data) {
CHECK_EQ(IDLE, write_state_);
- CHECK(!helper_.at_write_eof());
+ CHECK(!helper_.AllWriteDataConsumed());
NET_TRACE(1, " *** ") << "sequence_number: " << sequence_number_;
const MockWrite& next_write = helper_.PeekWrite();
@@ -600,12 +616,12 @@ void SequencedSocketData::Reset() {
weak_factory_.InvalidateWeakPtrs();
}
-bool SequencedSocketData::at_read_eof() const {
- return helper_.at_read_eof();
+bool SequencedSocketData::AllReadDataConsumed() const {
+ return helper_.AllReadDataConsumed();
}
-bool SequencedSocketData::at_write_eof() const {
- return helper_.at_read_eof();
+bool SequencedSocketData::AllWriteDataConsumed() const {
+ return helper_.AllWriteDataConsumed();
}
void SequencedSocketData::MaybePostReadCompleteTask() {
@@ -725,7 +741,7 @@ void DeterministicSocketData::Run() {
// the tasks in the message loop, and explicitly invoking the read/write
// callbacks (simulating network I/O). We check our conditions between each,
// since they can change in either.
- while ((!at_write_eof() || !at_read_eof()) && !stopped()) {
+ while ((!AllWriteDataConsumed() || !AllReadDataConsumed()) && !stopped()) {
if (counter % 2 == 0)
base::RunLoop().RunUntilIdle();
if (counter % 2 == 1) {

Powered by Google App Engine
This is Rietveld 408576698