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