summaryrefslogtreecommitdiffstats
path: root/net/socket/socket_test_util.cc
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-24 04:12:55 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-24 04:12:55 +0000
commita81e294b0466f102ef592fd940f19441ef1cb980 (patch)
treee3120f7b9b1d3d06f708f36c2d3ec6a20b79e0a0 /net/socket/socket_test_util.cc
parent3c317d4a7e1266bdbfed832e04d06eb859704624 (diff)
downloadchromium_src-a81e294b0466f102ef592fd940f19441ef1cb980.zip
chromium_src-a81e294b0466f102ef592fd940f19441ef1cb980.tar.gz
chromium_src-a81e294b0466f102ef592fd940f19441ef1cb980.tar.bz2
Add a feature to the MockSocket so that it can support simulation
of partial writes. For example, suppose the application under test is doing a write such as: Write("foobar", 6); // 6 bytes Normally you could test this with MockWrite(true, "foobar", 6); Now you can also test this with: WriteList { MockWrite(true, "foo", 3); MockWrite(true, "bar", 3); } BUG=none TEST=this is the test! Review URL: http://codereview.chromium.org/437031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32913 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/socket_test_util.cc')
-rw-r--r--net/socket/socket_test_util.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc
index 18ece28..f44d0cd 100644
--- a/net/socket/socket_test_util.cc
+++ b/net/socket/socket_test_util.cc
@@ -298,9 +298,17 @@ MockWriteResult StaticSocketDataProvider::OnWrite(const std::string& data) {
net::MockWrite* w = &writes_[write_index_++];
int result = w->result;
if (w->data) {
+ // Note - we can simulate a partial write here. If the expected data
+ // is a match, but shorter than the write actually written, that is legal.
+ // Example:
+ // Application writes "foobarbaz" (9 bytes)
+ // Expected write was "foo" (3 bytes)
+ // This is a success, and we return 3 to the application.
std::string expected_data(w->data, w->data_len);
- EXPECT_EQ(expected_data, data);
- if (expected_data != data)
+ EXPECT_GE(data.length(), expected_data.length());
+ std::string actual_data(data.substr(0, w->data_len));
+ EXPECT_EQ(expected_data, actual_data);
+ if (expected_data != actual_data)
return MockWriteResult(false, net::ERR_UNEXPECTED);
if (result == net::OK)
result = w->data_len;