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

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
« no previous file with comments | « net/socket/deterministic_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 #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 io_mode, int r) : mode(io_mode), 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 io_mode, int result) : mode(io_mode), result(result),
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 io_mode, int result, int seq) : mode(io_mode),
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 io_mode, const char* data) : mode(io_mode), 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 io_mode, const char* data, int data_len) : mode(io_mode),
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 io_mode, int seq, const char* data) : mode(io_mode),
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 io_mode, const char* data, int data_len, int seq) :
111 result(0), data(data), data_len(data_len), sequence_number(seq), 112 mode(io_mode), 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 io_mode, int result)
136 : mode(io_mode),
137 result(result) {}
135 138
136 bool async; 139 IoMode mode;
137 int result; 140 int result;
138 }; 141 };
139 142
140 // The SocketDataProvider is an interface used by the MockClientSocket 143 // The SocketDataProvider is an interface used by the MockClientSocket
141 // for getting data about individual reads and writes on the socket. 144 // for getting data about individual reads and writes on the socket.
142 class SocketDataProvider { 145 class SocketDataProvider {
143 public: 146 public:
144 SocketDataProvider() : socket_(NULL) {} 147 SocketDataProvider() : socket_(NULL) {}
145 148
146 virtual ~SocketDataProvider() {} 149 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 259 // If true, we'll not require the client to consume all data before we
257 // mock the next read. 260 // mock the next read.
258 bool allow_unconsumed_reads_; 261 bool allow_unconsumed_reads_;
259 262
260 DISALLOW_COPY_AND_ASSIGN(DynamicSocketDataProvider); 263 DISALLOW_COPY_AND_ASSIGN(DynamicSocketDataProvider);
261 }; 264 };
262 265
263 // SSLSocketDataProviders only need to keep track of the return code from calls 266 // SSLSocketDataProviders only need to keep track of the return code from calls
264 // to Connect(). 267 // to Connect().
265 struct SSLSocketDataProvider { 268 struct SSLSocketDataProvider {
266 SSLSocketDataProvider(bool async, int result); 269 SSLSocketDataProvider(IoMode mode, int result);
267 ~SSLSocketDataProvider(); 270 ~SSLSocketDataProvider();
268 271
269 void SetNextProto(SSLClientSocket::NextProto proto); 272 void SetNextProto(SSLClientSocket::NextProto proto);
270 273
271 MockConnect connect; 274 MockConnect connect;
272 SSLClientSocket::NextProtoStatus next_proto_status; 275 SSLClientSocket::NextProtoStatus next_proto_status;
273 std::string next_proto; 276 std::string next_proto;
274 std::string server_protos; 277 std::string server_protos;
275 bool was_npn_negotiated; 278 bool was_npn_negotiated;
276 SSLClientSocket::NextProto protocol_negotiated; 279 SSLClientSocket::NextProto protocol_negotiated;
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 1042
1040 extern const char kSOCKS5OkRequest[]; 1043 extern const char kSOCKS5OkRequest[];
1041 extern const int kSOCKS5OkRequestLength; 1044 extern const int kSOCKS5OkRequestLength;
1042 1045
1043 extern const char kSOCKS5OkResponse[]; 1046 extern const char kSOCKS5OkResponse[];
1044 extern const int kSOCKS5OkResponseLength; 1047 extern const int kSOCKS5OkResponseLength;
1045 1048
1046 } // namespace net 1049 } // namespace net
1047 1050
1048 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1051 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/socket/deterministic_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