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

Unified Diff: net/socket/socket_test_util.h

Issue 582020: Add bounds checking to StaticSocketDataProvider, to make tests more reliable (Closed)
Patch Set: Created 10 years, 10 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
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | net/socket/socket_test_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/socket_test_util.h
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index 90b40191225473aac1bf12d354090286ab60748f..5e1fe65ceb02de3672bc6832c13a5a46b353dd51 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -121,28 +121,33 @@ class SocketDataProvider {
// writes.
class StaticSocketDataProvider : public SocketDataProvider {
public:
- StaticSocketDataProvider() : reads_(NULL), read_index_(0),
- writes_(NULL), write_index_(0) {}
- StaticSocketDataProvider(MockRead* r, MockWrite* w) : reads_(r),
- read_index_(0), writes_(w), write_index_(0) {}
+ StaticSocketDataProvider() : reads_(NULL), read_index_(0), read_count_(0),
+ writes_(NULL), write_index_(0), write_count_(0) {}
+ StaticSocketDataProvider(MockRead* reads, size_t reads_count,
+ MockWrite* writes, size_t writes_count)
+ : reads_(reads),
+ read_index_(0),
+ read_count_(reads_count),
+ writes_(writes),
+ write_index_(0),
+ write_count_(writes_count) {
+ }
// SocketDataProvider methods:
virtual MockRead GetNextRead();
virtual MockWriteResult OnWrite(const std::string& data);
virtual void Reset();
- // If the test wishes to verify that all data is consumed, it can include
- // a EOF MockRead or MockWrite, which is a zero-length Read or Write.
- // The test can then call at_read_eof() or at_write_eof() to verify that
- // all data has been consumed.
- bool at_read_eof() const { return reads_[read_index_].data_len == 0; }
- bool at_write_eof() const { return writes_[write_index_].data_len == 0; }
+ bool at_read_eof() const { return read_index_ >= read_count_; }
+ bool at_write_eof() const { return write_index_ >= write_count_; }
private:
MockRead* reads_;
- int read_index_;
+ size_t read_index_;
+ size_t read_count_;
MockWrite* writes_;
- int write_index_;
+ size_t write_index_;
+ size_t write_count_;
DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider);
};
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | net/socket/socket_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698