OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_PROTOCOL_CONNECTION_TESTER_H_ |
| 6 #define REMOTING_PROTOCOL_CONNECTION_TESTER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 |
| 12 class MessageLoop; |
| 13 |
| 14 namespace net { |
| 15 class DrainableIOBuffer; |
| 16 class GrowableIOBuffer; |
| 17 class IOBuffer; |
| 18 class Socket; |
| 19 class StreamSocket; |
| 20 } // namespace net |
| 21 |
| 22 namespace remoting { |
| 23 namespace protocol { |
| 24 |
| 25 // This class is used by unit tests to verify that a connection |
| 26 // between two sockets works properly, i.e. data is delivered from one |
| 27 // end to the other. |
| 28 class StreamConnectionTester { |
| 29 public: |
| 30 StreamConnectionTester(net::StreamSocket* client_socket, |
| 31 net::StreamSocket* host_socket, |
| 32 int message_size, |
| 33 int message_count); |
| 34 ~StreamConnectionTester(); |
| 35 |
| 36 void Start(); |
| 37 void CheckResults(); |
| 38 |
| 39 protected: |
| 40 void Done(); |
| 41 void InitBuffers(); |
| 42 void DoWrite(); |
| 43 void OnWritten(int result); |
| 44 void HandleWriteResult(int result); |
| 45 void DoRead(); |
| 46 void OnRead(int result); |
| 47 void HandleReadResult(int result); |
| 48 |
| 49 private: |
| 50 MessageLoop* message_loop_; |
| 51 net::StreamSocket* host_socket_; |
| 52 net::StreamSocket* client_socket_; |
| 53 int message_size_; |
| 54 int message_count_; |
| 55 int test_data_size_; |
| 56 bool done_; |
| 57 |
| 58 scoped_refptr<net::DrainableIOBuffer> output_buffer_; |
| 59 scoped_refptr<net::GrowableIOBuffer> input_buffer_; |
| 60 |
| 61 int write_errors_; |
| 62 int read_errors_; |
| 63 }; |
| 64 |
| 65 class DatagramConnectionTester { |
| 66 public: |
| 67 DatagramConnectionTester(net::Socket* client_socket, |
| 68 net::Socket* host_socket, |
| 69 int message_size, |
| 70 int message_count, |
| 71 int delay_ms); |
| 72 ~DatagramConnectionTester() ; |
| 73 |
| 74 void Start(); |
| 75 void CheckResults(); |
| 76 |
| 77 private: |
| 78 void Done(); |
| 79 void DoWrite(); |
| 80 void OnWritten(int result); |
| 81 void HandleWriteResult(int result); |
| 82 void DoRead(); |
| 83 void OnRead(int result); |
| 84 void HandleReadResult(int result); |
| 85 |
| 86 MessageLoop* message_loop_; |
| 87 net::Socket* host_socket_; |
| 88 net::Socket* client_socket_; |
| 89 int message_size_; |
| 90 int message_count_; |
| 91 int delay_ms_; |
| 92 bool done_; |
| 93 |
| 94 std::vector<scoped_refptr<net::IOBuffer> > sent_packets_; |
| 95 scoped_refptr<net::IOBuffer> read_buffer_; |
| 96 |
| 97 int write_errors_; |
| 98 int read_errors_; |
| 99 int packets_sent_; |
| 100 int packets_received_; |
| 101 int bad_packets_received_; |
| 102 }; |
| 103 |
| 104 } // namespace protocol |
| 105 } // namespace remoting |
| 106 |
| 107 #endif // REMOTING_PROTOCOL_CONNECTION_TESTER_H_ |
OLD | NEW |