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

Side by Side Diff: net/socket/socket_test_util.h

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, 7 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
« no previous file with comments | « net/socket/sequenced_socket_data_unittest.cc ('k') | net/socket/socket_test_util.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 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_ 5 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_
6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_ 6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_
7 7
8 #include <cstring> 8 #include <cstring>
9 #include <deque> 9 #include <deque>
10 #include <string> 10 #include <string>
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 191
192 virtual ~SocketDataProvider() {} 192 virtual ~SocketDataProvider() {}
193 193
194 // Returns the buffer and result code for the next simulated read. 194 // Returns the buffer and result code for the next simulated read.
195 // If the |MockRead.result| is ERR_IO_PENDING, it informs the caller 195 // If the |MockRead.result| is ERR_IO_PENDING, it informs the caller
196 // that it will be called via the AsyncSocket::OnReadComplete() 196 // that it will be called via the AsyncSocket::OnReadComplete()
197 // function at a later time. 197 // function at a later time.
198 virtual MockRead OnRead() = 0; 198 virtual MockRead OnRead() = 0;
199 virtual MockWriteResult OnWrite(const std::string& data) = 0; 199 virtual MockWriteResult OnWrite(const std::string& data) = 0;
200 virtual void Reset() = 0; 200 virtual void Reset() = 0;
201 virtual bool AllReadDataConsumed() const = 0;
202 virtual bool AllWriteDataConsumed() const = 0;
201 203
202 // Accessor for the socket which is using the SocketDataProvider. 204 // Accessor for the socket which is using the SocketDataProvider.
203 AsyncSocket* socket() { return socket_; } 205 AsyncSocket* socket() { return socket_; }
204 void set_socket(AsyncSocket* socket) { socket_ = socket; } 206 void set_socket(AsyncSocket* socket) { socket_ = socket; }
205 207
206 MockConnect connect_data() const { return connect_; } 208 MockConnect connect_data() const { return connect_; }
207 void set_connect_data(const MockConnect& connect) { connect_ = connect; } 209 void set_connect_data(const MockConnect& connect) { connect_ = connect; }
208 210
209 private: 211 private:
210 MockConnect connect_; 212 MockConnect connect_;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 const MockWrite& AdvanceWrite(); 253 const MockWrite& AdvanceWrite();
252 254
253 // Resets the read and write indexes to 0. 255 // Resets the read and write indexes to 0.
254 void Reset(); 256 void Reset();
255 257
256 // Returns true if |data| is valid data for the next write. In order 258 // Returns true if |data| is valid data for the next write. In order
257 // to support short writes, the next write may be longer than |data| 259 // to support short writes, the next write may be longer than |data|
258 // in which case this method will still return true. 260 // in which case this method will still return true.
259 bool VerifyWriteData(const std::string& data); 261 bool VerifyWriteData(const std::string& data);
260 262
263 // Return true of all read data has been consumed.
ramant (doing other things) 2015/05/01 20:25:41 overly nit: "true of all" -> "true if all"?
Ryan Hamilton 2015/05/01 21:23:32 Done.
264 bool AllReadDataConsumed() const;
265
266 // Return true of all write data has been consumed.
ramant (doing other things) 2015/05/01 20:25:41 overly nit: "true of all" -> "true if all"?
Ryan Hamilton 2015/05/01 21:23:32 Done.
267 bool AllWriteDataConsumed() const;
268
261 size_t read_index() const { return read_index_; } 269 size_t read_index() const { return read_index_; }
262 size_t write_index() const { return write_index_; } 270 size_t write_index() const { return write_index_; }
263 size_t read_count() const { return read_count_; } 271 size_t read_count() const { return read_count_; }
264 size_t write_count() const { return write_count_; } 272 size_t write_count() const { return write_count_; }
265 273
266 bool at_read_eof() const { return read_index_ >= read_count_; }
267 bool at_write_eof() const { return write_index_ >= write_count_; }
268
269 private: 274 private:
270 MockRead* reads_; 275 MockRead* reads_;
271 size_t read_index_; 276 size_t read_index_;
272 size_t read_count_; 277 size_t read_count_;
273 MockWrite* writes_; 278 MockWrite* writes_;
274 size_t write_index_; 279 size_t write_index_;
275 size_t write_count_; 280 size_t write_count_;
276 281
277 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataHelper); 282 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataHelper);
278 }; 283 };
279 284
280 // SocketDataProvider which responds based on static tables of mock reads and 285 // SocketDataProvider which responds based on static tables of mock reads and
281 // writes. 286 // writes.
282 class StaticSocketDataProvider : public SocketDataProvider { 287 class StaticSocketDataProvider : public SocketDataProvider {
283 public: 288 public:
284 StaticSocketDataProvider(); 289 StaticSocketDataProvider();
285 StaticSocketDataProvider(MockRead* reads, 290 StaticSocketDataProvider(MockRead* reads,
286 size_t reads_count, 291 size_t reads_count,
287 MockWrite* writes, 292 MockWrite* writes,
288 size_t writes_count); 293 size_t writes_count);
289 ~StaticSocketDataProvider() override; 294 ~StaticSocketDataProvider() override;
290 295
291 virtual void CompleteRead() {} 296 virtual void CompleteRead() {}
292 297
293 // SocketDataProvider implementation. 298 // SocketDataProvider implementation.
294 MockRead OnRead() override; 299 MockRead OnRead() override;
295 MockWriteResult OnWrite(const std::string& data) override; 300 MockWriteResult OnWrite(const std::string& data) override;
296 void Reset() override; 301 void Reset() override;
302 bool AllReadDataConsumed() const override;
303 bool AllWriteDataConsumed() const override;
297 304
298 size_t read_index() const { return helper_.read_index(); } 305 size_t read_index() const { return helper_.read_index(); }
299 size_t write_index() const { return helper_.write_index(); } 306 size_t write_index() const { return helper_.write_index(); }
300 size_t read_count() const { return helper_.read_count(); } 307 size_t read_count() const { return helper_.read_count(); }
301 size_t write_count() const { return helper_.write_count(); } 308 size_t write_count() const { return helper_.write_count(); }
302 309
303 bool at_read_eof() const { return helper_.at_read_eof(); }
304 bool at_write_eof() const { return helper_.at_write_eof(); }
305
306 protected: 310 protected:
307 StaticSocketDataHelper* helper() { return &helper_; } 311 StaticSocketDataHelper* helper() { return &helper_; }
308 312
309 private: 313 private:
310 StaticSocketDataHelper helper_; 314 StaticSocketDataHelper helper_;
311 315
312 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider); 316 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider);
313 }; 317 };
314 318
315 // SocketDataProvider which can make decisions about next mock reads based on 319 // SocketDataProvider which can make decisions about next mock reads based on
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 size_t reads_count, 496 size_t reads_count,
493 MockWrite* writes, 497 MockWrite* writes,
494 size_t writes_count); 498 size_t writes_count);
495 499
496 ~SequencedSocketData() override; 500 ~SequencedSocketData() override;
497 501
498 // SocketDataProviderBase implementation. 502 // SocketDataProviderBase implementation.
499 MockRead OnRead() override; 503 MockRead OnRead() override;
500 MockWriteResult OnWrite(const std::string& data) override; 504 MockWriteResult OnWrite(const std::string& data) override;
501 void Reset() override; 505 void Reset() override;
502 506 bool AllReadDataConsumed() const override;
503 // Returns true if all data has been read. 507 bool AllWriteDataConsumed() const override;
504 bool at_read_eof() const;
505
506 // Returns true if all data has been written.
507 bool at_write_eof() const;
508 508
509 private: 509 private:
510 // Defines the state for the read or write path. 510 // Defines the state for the read or write path.
511 enum IoState { 511 enum IoState {
512 IDLE, // No async operation is in progress. 512 IDLE, // No async operation is in progress.
513 PENDING, // An async operation in waiting for another opteration to 513 PENDING, // An async operation in waiting for another opteration to
514 // complete. 514 // complete.
515 COMPLETING, // A task has been posted to complet an async operation. 515 COMPLETING, // A task has been posted to complet an async operation.
516 }; 516 };
517 void OnReadComplete(); 517 void OnReadComplete();
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 1378
1379 extern const char kSOCKS5OkRequest[]; 1379 extern const char kSOCKS5OkRequest[];
1380 extern const int kSOCKS5OkRequestLength; 1380 extern const int kSOCKS5OkRequestLength;
1381 1381
1382 extern const char kSOCKS5OkResponse[]; 1382 extern const char kSOCKS5OkResponse[];
1383 extern const int kSOCKS5OkResponseLength; 1383 extern const int kSOCKS5OkResponseLength;
1384 1384
1385 } // namespace net 1385 } // namespace net
1386 1386
1387 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1387 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/socket/sequenced_socket_data_unittest.cc ('k') | net/socket/socket_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698