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 <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 const MockRead& StaticSocketDataHelper::AdvanceRead() { | 194 const MockRead& StaticSocketDataHelper::AdvanceRead() { |
| 195 CHECK(!AllReadDataConsumed()); | 195 CHECK(!AllReadDataConsumed()); |
| 196 return reads_[read_index_++]; | 196 return reads_[read_index_++]; |
| 197 } | 197 } |
| 198 | 198 |
| 199 const MockWrite& StaticSocketDataHelper::AdvanceWrite() { | 199 const MockWrite& StaticSocketDataHelper::AdvanceWrite() { |
| 200 CHECK(!AllWriteDataConsumed()); | 200 CHECK(!AllWriteDataConsumed()); |
| 201 return writes_[write_index_++]; | 201 return writes_[write_index_++]; |
| 202 } | 202 } |
| 203 | 203 |
| 204 void StaticSocketDataHelper::Reset() { | |
| 205 read_index_ = 0; | |
| 206 write_index_ = 0; | |
| 207 } | |
|
mmenke
2016/10/14 14:57:39
If this isn't being used, should be just remove it
davidben
2016/10/14 16:32:37
Seems to be called in initialization. I was just r
mmenke
2016/10/14 16:45:32
Oops, didn't notice that you moved it, as opposed
| |
| 208 | |
| 204 bool StaticSocketDataHelper::VerifyWriteData(const std::string& data) { | 209 bool StaticSocketDataHelper::VerifyWriteData(const std::string& data) { |
| 205 CHECK(!AllWriteDataConsumed()); | 210 CHECK(!AllWriteDataConsumed()); |
| 206 // Check that what the actual data matches the expectations. | 211 // Check that the actual data matches the expectations, skipping over any |
| 207 const MockWrite& next_write = PeekWrite(); | 212 // pause events. |
| 213 const MockWrite& next_write = PeekRealWrite(); | |
| 208 if (!next_write.data) | 214 if (!next_write.data) |
| 209 return true; | 215 return true; |
| 210 | 216 |
| 211 // Note: Partial writes are supported here. If the expected data | 217 // Note: Partial writes are supported here. If the expected data |
| 212 // is a match, but shorter than the write actually written, that is legal. | 218 // is a match, but shorter than the write actually written, that is legal. |
| 213 // Example: | 219 // Example: |
| 214 // Application writes "foobarbaz" (9 bytes) | 220 // Application writes "foobarbaz" (9 bytes) |
| 215 // Expected write was "foo" (3 bytes) | 221 // Expected write was "foo" (3 bytes) |
| 216 // This is a success, and the function returns true. | 222 // This is a success, and the function returns true. |
| 217 std::string expected_data(next_write.data, next_write.data_len); | 223 std::string expected_data(next_write.data, next_write.data_len); |
| 218 std::string actual_data(data.substr(0, next_write.data_len)); | 224 std::string actual_data(data.substr(0, next_write.data_len)); |
| 219 EXPECT_GE(data.length(), expected_data.length()); | 225 EXPECT_GE(data.length(), expected_data.length()); |
| 220 EXPECT_EQ(expected_data, actual_data); | 226 EXPECT_EQ(expected_data, actual_data); |
| 221 return expected_data == actual_data; | 227 return expected_data == actual_data; |
| 222 } | 228 } |
| 223 | 229 |
| 224 void StaticSocketDataHelper::Reset() { | 230 const MockWrite& StaticSocketDataHelper::PeekRealWrite() const { |
| 225 read_index_ = 0; | 231 for (size_t i = write_index_; i < write_count_; i++) { |
| 226 write_index_ = 0; | 232 if (writes_[i].mode != ASYNC || writes_[i].result != ERR_IO_PENDING) |
| 233 return writes_[i]; | |
| 234 } | |
| 235 | |
| 236 CHECK(0) << "No write data available."; | |
|
mmenke
2016/10/14 14:57:39
nit: CHECK(false) is more common.
davidben
2016/10/14 16:32:37
Done. C habits. :-)
| |
| 237 return writes_[0]; // Avoid warning about unreachable missing return. | |
| 227 } | 238 } |
| 228 | 239 |
| 229 StaticSocketDataProvider::StaticSocketDataProvider() | 240 StaticSocketDataProvider::StaticSocketDataProvider() |
| 230 : StaticSocketDataProvider(nullptr, 0, nullptr, 0) { | 241 : StaticSocketDataProvider(nullptr, 0, nullptr, 0) { |
| 231 } | 242 } |
| 232 | 243 |
| 233 StaticSocketDataProvider::StaticSocketDataProvider(MockRead* reads, | 244 StaticSocketDataProvider::StaticSocketDataProvider(MockRead* reads, |
| 234 size_t reads_count, | 245 size_t reads_count, |
| 235 MockWrite* writes, | 246 MockWrite* writes, |
| 236 size_t writes_count) | 247 size_t writes_count) |
| (...skipping 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1733 } | 1744 } |
| 1734 | 1745 |
| 1735 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size) { | 1746 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size) { |
| 1736 int64_t total = 0; | 1747 int64_t total = 0; |
| 1737 for (const MockWrite* write = writes; write != writes + writes_size; ++write) | 1748 for (const MockWrite* write = writes; write != writes + writes_size; ++write) |
| 1738 total += write->data_len; | 1749 total += write->data_len; |
| 1739 return total; | 1750 return total; |
| 1740 } | 1751 } |
| 1741 | 1752 |
| 1742 } // namespace net | 1753 } // namespace net |
| OLD | NEW |