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

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

Issue 1119803006: Revert of 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;
203 201
204 // Accessor for the socket which is using the SocketDataProvider. 202 // Accessor for the socket which is using the SocketDataProvider.
205 AsyncSocket* socket() { return socket_; } 203 AsyncSocket* socket() { return socket_; }
206 void set_socket(AsyncSocket* socket) { socket_ = socket; } 204 void set_socket(AsyncSocket* socket) { socket_ = socket; }
207 205
208 MockConnect connect_data() const { return connect_; } 206 MockConnect connect_data() const { return connect_; }
209 void set_connect_data(const MockConnect& connect) { connect_ = connect; } 207 void set_connect_data(const MockConnect& connect) { connect_ = connect; }
210 208
211 private: 209 private:
212 MockConnect connect_; 210 MockConnect connect_;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 const MockWrite& AdvanceWrite(); 251 const MockWrite& AdvanceWrite();
254 252
255 // Resets the read and write indexes to 0. 253 // Resets the read and write indexes to 0.
256 void Reset(); 254 void Reset();
257 255
258 // Returns true if |data| is valid data for the next write. In order 256 // Returns true if |data| is valid data for the next write. In order
259 // to support short writes, the next write may be longer than |data| 257 // to support short writes, the next write may be longer than |data|
260 // in which case this method will still return true. 258 // in which case this method will still return true.
261 bool VerifyWriteData(const std::string& data); 259 bool VerifyWriteData(const std::string& data);
262 260
263 // Return true if all read data has been consumed.
264 bool AllReadDataConsumed() const;
265
266 // Return true if all write data has been consumed.
267 bool AllWriteDataConsumed() const;
268
269 size_t read_index() const { return read_index_; } 261 size_t read_index() const { return read_index_; }
270 size_t write_index() const { return write_index_; } 262 size_t write_index() const { return write_index_; }
271 size_t read_count() const { return read_count_; } 263 size_t read_count() const { return read_count_; }
272 size_t write_count() const { return write_count_; } 264 size_t write_count() const { return write_count_; }
273 265
266 bool at_read_eof() const { return read_index_ >= read_count_; }
267 bool at_write_eof() const { return write_index_ >= write_count_; }
268
274 private: 269 private:
275 MockRead* reads_; 270 MockRead* reads_;
276 size_t read_index_; 271 size_t read_index_;
277 size_t read_count_; 272 size_t read_count_;
278 MockWrite* writes_; 273 MockWrite* writes_;
279 size_t write_index_; 274 size_t write_index_;
280 size_t write_count_; 275 size_t write_count_;
281 276
282 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataHelper); 277 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataHelper);
283 }; 278 };
284 279
285 // SocketDataProvider which responds based on static tables of mock reads and 280 // SocketDataProvider which responds based on static tables of mock reads and
286 // writes. 281 // writes.
287 class StaticSocketDataProvider : public SocketDataProvider { 282 class StaticSocketDataProvider : public SocketDataProvider {
288 public: 283 public:
289 StaticSocketDataProvider(); 284 StaticSocketDataProvider();
290 StaticSocketDataProvider(MockRead* reads, 285 StaticSocketDataProvider(MockRead* reads,
291 size_t reads_count, 286 size_t reads_count,
292 MockWrite* writes, 287 MockWrite* writes,
293 size_t writes_count); 288 size_t writes_count);
294 ~StaticSocketDataProvider() override; 289 ~StaticSocketDataProvider() override;
295 290
296 virtual void CompleteRead() {} 291 virtual void CompleteRead() {}
297 292
298 // SocketDataProvider implementation. 293 // SocketDataProvider implementation.
299 MockRead OnRead() override; 294 MockRead OnRead() override;
300 MockWriteResult OnWrite(const std::string& data) override; 295 MockWriteResult OnWrite(const std::string& data) override;
301 void Reset() override; 296 void Reset() override;
302 bool AllReadDataConsumed() const override;
303 bool AllWriteDataConsumed() const override;
304 297
305 size_t read_index() const { return helper_.read_index(); } 298 size_t read_index() const { return helper_.read_index(); }
306 size_t write_index() const { return helper_.write_index(); } 299 size_t write_index() const { return helper_.write_index(); }
307 size_t read_count() const { return helper_.read_count(); } 300 size_t read_count() const { return helper_.read_count(); }
308 size_t write_count() const { return helper_.write_count(); } 301 size_t write_count() const { return helper_.write_count(); }
309 302
303 bool at_read_eof() const { return helper_.at_read_eof(); }
304 bool at_write_eof() const { return helper_.at_write_eof(); }
305
310 protected: 306 protected:
311 StaticSocketDataHelper* helper() { return &helper_; } 307 StaticSocketDataHelper* helper() { return &helper_; }
312 308
313 private: 309 private:
314 StaticSocketDataHelper helper_; 310 StaticSocketDataHelper helper_;
315 311
316 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider); 312 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider);
317 }; 313 };
318 314
319 // SocketDataProvider which can make decisions about next mock reads based on 315 // SocketDataProvider which can make decisions about next mock reads based on
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 size_t reads_count, 492 size_t reads_count,
497 MockWrite* writes, 493 MockWrite* writes,
498 size_t writes_count); 494 size_t writes_count);
499 495
500 ~SequencedSocketData() override; 496 ~SequencedSocketData() override;
501 497
502 // SocketDataProviderBase implementation. 498 // SocketDataProviderBase implementation.
503 MockRead OnRead() override; 499 MockRead OnRead() override;
504 MockWriteResult OnWrite(const std::string& data) override; 500 MockWriteResult OnWrite(const std::string& data) override;
505 void Reset() override; 501 void Reset() override;
506 bool AllReadDataConsumed() const override; 502
507 bool AllWriteDataConsumed() const override; 503 // Returns true if all data has been read.
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