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

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

Issue 9425016: Change MockRead and MockWrite (et. al.) to take an IoMode enum, instead (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 8 years, 10 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 | Annotate | Revision Log
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 #pragma once 7 #pragma once
8 8
9 #include <cstring> 9 #include <cstring>
10 #include <deque> 10 #include <deque>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000, 46 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000,
47 }; 47 };
48 48
49 class AsyncSocket; 49 class AsyncSocket;
50 class MockClientSocket; 50 class MockClientSocket;
51 class OriginBoundCertService; 51 class OriginBoundCertService;
52 class SSLClientSocket; 52 class SSLClientSocket;
53 class SSLHostInfo; 53 class SSLHostInfo;
54 class StreamSocket; 54 class StreamSocket;
55 55
56 enum ConnectMode { 56 enum IoMode {
57 ASYNC, 57 ASYNC,
58 SYNCHRONOUS 58 SYNCHRONOUS
59 }; 59 };
60 60
61 struct MockConnect { 61 struct MockConnect {
62 // Asynchronous connection success. 62 // Asynchronous connection success.
63 MockConnect() : async(true), result(OK) { } 63 MockConnect() : mode(ASYNC), result(OK) { }
64 MockConnect(ConnectMode m, int r) : async(m == ASYNC), result(r) { } 64 MockConnect(IoMode m, int r) : mode(m), result(r) { }
65 65
66 bool async; 66 IoMode mode;
67 int result; 67 int result;
68 }; 68 };
69 69
70 struct MockRead { 70 struct MockRead {
71 // Flag to indicate that the message loop should be terminated. 71 // Flag to indicate that the message loop should be terminated.
72 enum { 72 enum {
73 STOPLOOP = 1 << 31 73 STOPLOOP = 1 << 31
74 }; 74 };
75 75
76 // Default 76 // Default
77 MockRead() : async(false), result(0), data(NULL), data_len(0), 77 MockRead() : mode(SYNCHRONOUS), result(0), data(NULL), data_len(0),
78 sequence_number(0), time_stamp(base::Time::Now()) {} 78 sequence_number(0), time_stamp(base::Time::Now()) {}
79 79
80 // Read failure (no data). 80 // Read failure (no data).
81 MockRead(bool async, int result) : async(async) , result(result), data(NULL), 81 MockRead(IoMode m, int result) : mode(m), result(result),
jar (doing other things) 2012/02/22 17:38:25 Style guide would probably argue against using "m"
Ryan Hamilton 2012/02/22 17:50:10 Done.
82 data_len(0), sequence_number(0), time_stamp(base::Time::Now()) { } 82 data(NULL), data_len(0), sequence_number(0),
83 time_stamp(base::Time::Now()) { }
83 84
84 // Read failure (no data), with sequence information. 85 // Read failure (no data), with sequence information.
85 MockRead(bool async, int result, int seq) : async(async) , result(result), 86 MockRead(IoMode m, int result, int seq) : mode(m),
86 data(NULL), data_len(0), sequence_number(seq), 87 result(result), data(NULL), data_len(0), sequence_number(seq),
87 time_stamp(base::Time::Now()) { } 88 time_stamp(base::Time::Now()) { }
88 89
89 // Asynchronous read success (inferred data length). 90 // Asynchronous read success (inferred data length).
90 explicit MockRead(const char* data) : async(true), result(0), data(data), 91 explicit MockRead(const char* data) : mode(ASYNC), result(0), data(data),
91 data_len(strlen(data)), sequence_number(0), 92 data_len(strlen(data)), sequence_number(0),
92 time_stamp(base::Time::Now()) { } 93 time_stamp(base::Time::Now()) { }
93 94
94 // Read success (inferred data length). 95 // Read success (inferred data length).
95 MockRead(bool async, const char* data) : async(async), result(0), data(data), 96 MockRead(IoMode m, const char* data) : mode(m), result(0),
96 data_len(strlen(data)), sequence_number(0), 97 data(data), data_len(strlen(data)), sequence_number(0),
97 time_stamp(base::Time::Now()) { } 98 time_stamp(base::Time::Now()) { }
98 99
99 // Read success. 100 // Read success.
100 MockRead(bool async, const char* data, int data_len) : async(async), 101 MockRead(IoMode m, const char* data, int data_len) : mode(m),
101 result(0), data(data), data_len(data_len), sequence_number(0), 102 result(0), data(data), data_len(data_len), sequence_number(0),
102 time_stamp(base::Time::Now()) { } 103 time_stamp(base::Time::Now()) { }
103 104
104 // Read success (inferred data length) with sequence information. 105 // Read success (inferred data length) with sequence information.
105 MockRead(bool async, int seq, const char* data) : async(async), 106 MockRead(IoMode m, int seq, const char* data) : mode(m),
106 result(0), data(data), data_len(strlen(data)), sequence_number(seq), 107 result(0), data(data), data_len(strlen(data)), sequence_number(seq),
107 time_stamp(base::Time::Now()) { } 108 time_stamp(base::Time::Now()) { }
108 109
109 // Read success with sequence information. 110 // Read success with sequence information.
110 MockRead(bool async, const char* data, int data_len, int seq) : async(async), 111 MockRead(IoMode m, const char* data, int data_len, int seq) :
111 result(0), data(data), data_len(data_len), sequence_number(seq), 112 mode(m), result(0), data(data), data_len(data_len),
112 time_stamp(base::Time::Now()) { } 113 sequence_number(seq), time_stamp(base::Time::Now()) { }
113 114
114 bool async; 115 IoMode mode;
115 int result; 116 int result;
116 const char* data; 117 const char* data;
117 int data_len; 118 int data_len;
118 119
119 // For OrderedSocketData, which only allows reads to occur in a particular 120 // For OrderedSocketData, which only allows reads to occur in a particular
120 // sequence. If a read occurs before the given |sequence_number| is reached, 121 // sequence. If a read occurs before the given |sequence_number| is reached,
121 // an ERR_IO_PENDING is returned. 122 // an ERR_IO_PENDING is returned.
122 int sequence_number; // The sequence number at which a read is allowed 123 int sequence_number; // The sequence number at which a read is allowed
123 // to occur. 124 // to occur.
124 base::Time time_stamp; // The time stamp at which the operation occurred. 125 base::Time time_stamp; // The time stamp at which the operation occurred.
125 }; 126 };
126 127
127 // MockWrite uses the same member fields as MockRead, but with different 128 // MockWrite uses the same member fields as MockRead, but with different
128 // meanings. The expected input to MockTCPClientSocket::Write() is given 129 // meanings. The expected input to MockTCPClientSocket::Write() is given
129 // by {data, data_len}, and the return value of Write() is controlled by 130 // by {data, data_len}, and the return value of Write() is controlled by
130 // {async, result}. 131 // {async, result}.
131 typedef MockRead MockWrite; 132 typedef MockRead MockWrite;
132 133
133 struct MockWriteResult { 134 struct MockWriteResult {
134 MockWriteResult(bool async, int result) : async(async), result(result) {} 135 MockWriteResult(IoMode m, int result) : mode(m), result(result) {}
135 136
136 bool async; 137 IoMode mode;
137 int result; 138 int result;
138 }; 139 };
139 140
140 // The SocketDataProvider is an interface used by the MockClientSocket 141 // The SocketDataProvider is an interface used by the MockClientSocket
141 // for getting data about individual reads and writes on the socket. 142 // for getting data about individual reads and writes on the socket.
142 class SocketDataProvider { 143 class SocketDataProvider {
143 public: 144 public:
144 SocketDataProvider() : socket_(NULL) {} 145 SocketDataProvider() : socket_(NULL) {}
145 146
146 virtual ~SocketDataProvider() {} 147 virtual ~SocketDataProvider() {}
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // If true, we'll not require the client to consume all data before we 257 // If true, we'll not require the client to consume all data before we
257 // mock the next read. 258 // mock the next read.
258 bool allow_unconsumed_reads_; 259 bool allow_unconsumed_reads_;
259 260
260 DISALLOW_COPY_AND_ASSIGN(DynamicSocketDataProvider); 261 DISALLOW_COPY_AND_ASSIGN(DynamicSocketDataProvider);
261 }; 262 };
262 263
263 // SSLSocketDataProviders only need to keep track of the return code from calls 264 // SSLSocketDataProviders only need to keep track of the return code from calls
264 // to Connect(). 265 // to Connect().
265 struct SSLSocketDataProvider { 266 struct SSLSocketDataProvider {
266 SSLSocketDataProvider(bool async, int result); 267 SSLSocketDataProvider(IoMode mode, int result);
267 ~SSLSocketDataProvider(); 268 ~SSLSocketDataProvider();
268 269
269 MockConnect connect; 270 MockConnect connect;
270 SSLClientSocket::NextProtoStatus next_proto_status; 271 SSLClientSocket::NextProtoStatus next_proto_status;
271 std::string next_proto; 272 std::string next_proto;
272 std::string server_protos; 273 std::string server_protos;
273 bool was_npn_negotiated; 274 bool was_npn_negotiated;
274 SSLClientSocket::NextProto protocol_negotiated; 275 SSLClientSocket::NextProto protocol_negotiated;
275 bool client_cert_sent; 276 bool client_cert_sent;
276 SSLCertRequestInfo* cert_request_info; 277 SSLCertRequestInfo* cert_request_info;
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 1038
1038 extern const char kSOCKS5OkRequest[]; 1039 extern const char kSOCKS5OkRequest[];
1039 extern const int kSOCKS5OkRequestLength; 1040 extern const int kSOCKS5OkRequestLength;
1040 1041
1041 extern const char kSOCKS5OkResponse[]; 1042 extern const char kSOCKS5OkResponse[];
1042 extern const int kSOCKS5OkResponseLength; 1043 extern const int kSOCKS5OkResponseLength;
1043 1044
1044 } // namespace net 1045 } // namespace net
1045 1046
1046 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1047 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698