| 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 #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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 273 |
| 274 // StaticSocketDataHelper manages a list of reads and writes. | 274 // StaticSocketDataHelper manages a list of reads and writes. |
| 275 class StaticSocketDataHelper { | 275 class StaticSocketDataHelper { |
| 276 public: | 276 public: |
| 277 StaticSocketDataHelper(MockRead* reads, | 277 StaticSocketDataHelper(MockRead* reads, |
| 278 size_t reads_count, | 278 size_t reads_count, |
| 279 MockWrite* writes, | 279 MockWrite* writes, |
| 280 size_t writes_count); | 280 size_t writes_count); |
| 281 ~StaticSocketDataHelper(); | 281 ~StaticSocketDataHelper(); |
| 282 | 282 |
| 283 // These functions get access to the next available read and write data, | 283 // These functions get access to the next available read and write data. They |
| 284 // or null if there is no more data available. | 284 // CHECK fail if there is no data available. |
| 285 const MockRead& PeekRead() const; | 285 const MockRead& PeekRead() const; |
| 286 const MockWrite& PeekWrite() const; | 286 const MockWrite& PeekWrite() const; |
| 287 | 287 |
| 288 // Returns the current read or write , and then advances to the next one. | 288 // Returns the current read or write, and then advances to the next one. |
| 289 const MockRead& AdvanceRead(); | 289 const MockRead& AdvanceRead(); |
| 290 const MockWrite& AdvanceWrite(); | 290 const MockWrite& AdvanceWrite(); |
| 291 | 291 |
| 292 // Resets the read and write indexes to 0. | 292 // Resets the read and write indexes to 0. |
| 293 void Reset(); | 293 void Reset(); |
| 294 | 294 |
| 295 // Returns true if |data| is valid data for the next write. In order | 295 // Returns true if |data| is valid data for the next write. In order |
| 296 // to support short writes, the next write may be longer than |data| | 296 // to support short writes, the next write may be longer than |data| |
| 297 // in which case this method will still return true. | 297 // in which case this method will still return true. |
| 298 bool VerifyWriteData(const std::string& data); | 298 bool VerifyWriteData(const std::string& data); |
| 299 | 299 |
| 300 size_t read_index() const { return read_index_; } | 300 size_t read_index() const { return read_index_; } |
| 301 size_t write_index() const { return write_index_; } | 301 size_t write_index() const { return write_index_; } |
| 302 size_t read_count() const { return read_count_; } | 302 size_t read_count() const { return read_count_; } |
| 303 size_t write_count() const { return write_count_; } | 303 size_t write_count() const { return write_count_; } |
| 304 | 304 |
| 305 bool AllReadDataConsumed() const { return read_index_ >= read_count_; } | 305 bool AllReadDataConsumed() const { return read_index_ >= read_count_; } |
| 306 bool AllWriteDataConsumed() const { return write_index_ >= write_count_; } | 306 bool AllWriteDataConsumed() const { return write_index_ >= write_count_; } |
| 307 | 307 |
| 308 private: | 308 private: |
| 309 // Returns the next available read or write that is not a pause event. CHECK |
| 310 // fails if no data is available. |
| 311 const MockWrite& PeekRealWrite() const; |
| 312 |
| 309 MockRead* reads_; | 313 MockRead* reads_; |
| 310 size_t read_index_; | 314 size_t read_index_; |
| 311 size_t read_count_; | 315 size_t read_count_; |
| 312 MockWrite* writes_; | 316 MockWrite* writes_; |
| 313 size_t write_index_; | 317 size_t write_index_; |
| 314 size_t write_count_; | 318 size_t write_count_; |
| 315 | 319 |
| 316 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataHelper); | 320 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataHelper); |
| 317 }; | 321 }; |
| 318 | 322 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 void set_busy_before_sync_reads(bool busy_before_sync_reads) { | 429 void set_busy_before_sync_reads(bool busy_before_sync_reads) { |
| 426 busy_before_sync_reads_ = busy_before_sync_reads; | 430 busy_before_sync_reads_ = busy_before_sync_reads; |
| 427 } | 431 } |
| 428 | 432 |
| 429 private: | 433 private: |
| 430 // Defines the state for the read or write path. | 434 // Defines the state for the read or write path. |
| 431 enum IoState { | 435 enum IoState { |
| 432 IDLE, // No async operation is in progress. | 436 IDLE, // No async operation is in progress. |
| 433 PENDING, // An async operation in waiting for another opteration to | 437 PENDING, // An async operation in waiting for another opteration to |
| 434 // complete. | 438 // complete. |
| 435 COMPLETING, // A task has been posted to complet an async operation. | 439 COMPLETING, // A task has been posted to complete an async operation. |
| 436 PAUSED, // IO is paused until Resume() is called. | 440 PAUSED, // IO is paused until Resume() is called. |
| 437 }; | 441 }; |
| 438 | 442 |
| 439 // From SocketDataProvider: | 443 // From SocketDataProvider: |
| 440 void Reset() override; | 444 void Reset() override; |
| 441 | 445 |
| 442 void OnReadComplete(); | 446 void OnReadComplete(); |
| 443 void OnWriteComplete(); | 447 void OnWriteComplete(); |
| 444 | 448 |
| 445 void MaybePostReadCompleteTask(); | 449 void MaybePostReadCompleteTask(); |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 | 1015 |
| 1012 // Helper function to get the total data size of the MockReads in |reads|. | 1016 // Helper function to get the total data size of the MockReads in |reads|. |
| 1013 int64_t CountReadBytes(const MockRead reads[], size_t reads_size); | 1017 int64_t CountReadBytes(const MockRead reads[], size_t reads_size); |
| 1014 | 1018 |
| 1015 // Helper function to get the total data size of the MockWrites in |writes|. | 1019 // Helper function to get the total data size of the MockWrites in |writes|. |
| 1016 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size); | 1020 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size); |
| 1017 | 1021 |
| 1018 } // namespace net | 1022 } // namespace net |
| 1019 | 1023 |
| 1020 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1024 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |