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

Side by Side Diff: net/socket/deterministic_socket_data_unittest.cc

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/http/http_proxy_client_socket_pool_unittest.cc ('k') | net/socket/socket_test_util.h » ('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 #include "net/socket/socket_test_util.h" 5 #include "net/socket/socket_test_util.h"
6 6
7 #include "testing/platform_test.h" 7 #include "testing/platform_test.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 //----------------------------------------------------------------------------- 10 //-----------------------------------------------------------------------------
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 memcpy(buf->data(), data, len); 158 memcpy(buf->data(), data, len);
159 159
160 // Issue the read, which will complete asynchronously 160 // Issue the read, which will complete asynchronously
161 ASSERT_EQ(rv, sock_->Write(buf, len, write_callback_.callback())); 161 ASSERT_EQ(rv, sock_->Write(buf, len, write_callback_.callback()));
162 } 162 }
163 163
164 // ----------- Read 164 // ----------- Read
165 165
166 TEST_F(DeterministicSocketDataTest, SingleSyncReadWhileStopped) { 166 TEST_F(DeterministicSocketDataTest, SingleSyncReadWhileStopped) {
167 MockRead reads[] = { 167 MockRead reads[] = {
168 MockRead(false, kMsg1, kLen1, 0), // Sync Read 168 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
169 MockRead(false, 0, 1), // EOF 169 MockRead(SYNCHRONOUS, 0, 1), // EOF
170 }; 170 };
171 171
172 Initialize(reads, arraysize(reads), NULL, 0); 172 Initialize(reads, arraysize(reads), NULL, 0);
173 173
174 data_->SetStopped(true); 174 data_->SetStopped(true);
175 AssertReadReturns(kMsg1, kLen1, ERR_UNEXPECTED); 175 AssertReadReturns(kMsg1, kLen1, ERR_UNEXPECTED);
176 } 176 }
177 177
178 TEST_F(DeterministicSocketDataTest, SingleSyncReadTooEarly) { 178 TEST_F(DeterministicSocketDataTest, SingleSyncReadTooEarly) {
179 MockRead reads[] = { 179 MockRead reads[] = {
180 MockRead(false, kMsg1, kLen1, 1), // Sync Read 180 MockRead(SYNCHRONOUS, kMsg1, kLen1, 1), // Sync Read
181 MockRead(false, 0, 2), // EOF 181 MockRead(SYNCHRONOUS, 0, 2), // EOF
182 }; 182 };
183 183
184 Initialize(reads, arraysize(reads), NULL, 0); 184 Initialize(reads, arraysize(reads), NULL, 0);
185 185
186 data_->StopAfter(2); 186 data_->StopAfter(2);
187 ASSERT_FALSE(data_->stopped()); 187 ASSERT_FALSE(data_->stopped());
188 AssertReadReturns(kMsg1, kLen1, ERR_UNEXPECTED); 188 AssertReadReturns(kMsg1, kLen1, ERR_UNEXPECTED);
189 } 189 }
190 190
191 TEST_F(DeterministicSocketDataTest, SingleSyncRead) { 191 TEST_F(DeterministicSocketDataTest, SingleSyncRead) {
192 MockRead reads[] = { 192 MockRead reads[] = {
193 MockRead(false, kMsg1, kLen1, 0), // Sync Read 193 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
194 MockRead(false, 0, 1), // EOF 194 MockRead(SYNCHRONOUS, 0, 1), // EOF
195 }; 195 };
196 196
197 Initialize(reads, arraysize(reads), NULL, 0); 197 Initialize(reads, arraysize(reads), NULL, 0);
198 // Make sure we don't stop before we've read all the data 198 // Make sure we don't stop before we've read all the data
199 data_->StopAfter(1); 199 data_->StopAfter(1);
200 AssertSyncReadEquals(kMsg1, kLen1); 200 AssertSyncReadEquals(kMsg1, kLen1);
201 } 201 }
202 202
203 TEST_F(DeterministicSocketDataTest, MultipleSyncReads) { 203 TEST_F(DeterministicSocketDataTest, MultipleSyncReads) {
204 MockRead reads[] = { 204 MockRead reads[] = {
205 MockRead(false, kMsg1, kLen1, 0), // Sync Read 205 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
206 MockRead(false, kMsg2, kLen2, 1), // Sync Read 206 MockRead(SYNCHRONOUS, kMsg2, kLen2, 1), // Sync Read
207 MockRead(false, kMsg3, kLen3, 2), // Sync Read 207 MockRead(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Read
208 MockRead(false, kMsg3, kLen3, 3), // Sync Read 208 MockRead(SYNCHRONOUS, kMsg3, kLen3, 3), // Sync Read
209 MockRead(false, kMsg2, kLen2, 4), // Sync Read 209 MockRead(SYNCHRONOUS, kMsg2, kLen2, 4), // Sync Read
210 MockRead(false, kMsg3, kLen3, 5), // Sync Read 210 MockRead(SYNCHRONOUS, kMsg3, kLen3, 5), // Sync Read
211 MockRead(false, kMsg1, kLen1, 6), // Sync Read 211 MockRead(SYNCHRONOUS, kMsg1, kLen1, 6), // Sync Read
212 MockRead(false, 0, 7), // EOF 212 MockRead(SYNCHRONOUS, 0, 7), // EOF
213 }; 213 };
214 214
215 Initialize(reads, arraysize(reads), NULL, 0); 215 Initialize(reads, arraysize(reads), NULL, 0);
216 216
217 // Make sure we don't stop before we've read all the data 217 // Make sure we don't stop before we've read all the data
218 data_->StopAfter(10); 218 data_->StopAfter(10);
219 AssertSyncReadEquals(kMsg1, kLen1); 219 AssertSyncReadEquals(kMsg1, kLen1);
220 AssertSyncReadEquals(kMsg2, kLen2); 220 AssertSyncReadEquals(kMsg2, kLen2);
221 AssertSyncReadEquals(kMsg3, kLen3); 221 AssertSyncReadEquals(kMsg3, kLen3);
222 AssertSyncReadEquals(kMsg3, kLen3); 222 AssertSyncReadEquals(kMsg3, kLen3);
223 AssertSyncReadEquals(kMsg2, kLen2); 223 AssertSyncReadEquals(kMsg2, kLen2);
224 AssertSyncReadEquals(kMsg3, kLen3); 224 AssertSyncReadEquals(kMsg3, kLen3);
225 AssertSyncReadEquals(kMsg1, kLen1); 225 AssertSyncReadEquals(kMsg1, kLen1);
226 } 226 }
227 227
228 TEST_F(DeterministicSocketDataTest, SingleAsyncRead) { 228 TEST_F(DeterministicSocketDataTest, SingleAsyncRead) {
229 MockRead reads[] = { 229 MockRead reads[] = {
230 MockRead(true, kMsg1, kLen1, 0), // Async Read 230 MockRead(ASYNC, kMsg1, kLen1, 0), // Async Read
231 MockRead(false, 0, 1), // EOF 231 MockRead(SYNCHRONOUS, 0, 1), // EOF
232 }; 232 };
233 233
234 Initialize(reads, arraysize(reads), NULL, 0); 234 Initialize(reads, arraysize(reads), NULL, 0);
235 235
236 AssertAsyncReadEquals(kMsg1, kLen1); 236 AssertAsyncReadEquals(kMsg1, kLen1);
237 } 237 }
238 238
239 TEST_F(DeterministicSocketDataTest, MultipleAsyncReads) { 239 TEST_F(DeterministicSocketDataTest, MultipleAsyncReads) {
240 MockRead reads[] = { 240 MockRead reads[] = {
241 MockRead(true, kMsg1, kLen1, 0), // Async Read 241 MockRead(ASYNC, kMsg1, kLen1, 0), // Async Read
242 MockRead(true, kMsg2, kLen2, 1), // Async Read 242 MockRead(ASYNC, kMsg2, kLen2, 1), // Async Read
243 MockRead(true, kMsg3, kLen3, 2), // Async Read 243 MockRead(ASYNC, kMsg3, kLen3, 2), // Async Read
244 MockRead(true, kMsg3, kLen3, 3), // Async Read 244 MockRead(ASYNC, kMsg3, kLen3, 3), // Async Read
245 MockRead(true, kMsg2, kLen2, 4), // Async Read 245 MockRead(ASYNC, kMsg2, kLen2, 4), // Async Read
246 MockRead(true, kMsg3, kLen3, 5), // Async Read 246 MockRead(ASYNC, kMsg3, kLen3, 5), // Async Read
247 MockRead(true, kMsg1, kLen1, 6), // Async Read 247 MockRead(ASYNC, kMsg1, kLen1, 6), // Async Read
248 MockRead(false, 0, 7), // EOF 248 MockRead(SYNCHRONOUS, 0, 7), // EOF
249 }; 249 };
250 250
251 Initialize(reads, arraysize(reads), NULL, 0); 251 Initialize(reads, arraysize(reads), NULL, 0);
252 252
253 AssertAsyncReadEquals(kMsg1, kLen1); 253 AssertAsyncReadEquals(kMsg1, kLen1);
254 AssertAsyncReadEquals(kMsg2, kLen2); 254 AssertAsyncReadEquals(kMsg2, kLen2);
255 AssertAsyncReadEquals(kMsg3, kLen3); 255 AssertAsyncReadEquals(kMsg3, kLen3);
256 AssertAsyncReadEquals(kMsg3, kLen3); 256 AssertAsyncReadEquals(kMsg3, kLen3);
257 AssertAsyncReadEquals(kMsg2, kLen2); 257 AssertAsyncReadEquals(kMsg2, kLen2);
258 AssertAsyncReadEquals(kMsg3, kLen3); 258 AssertAsyncReadEquals(kMsg3, kLen3);
259 AssertAsyncReadEquals(kMsg1, kLen1); 259 AssertAsyncReadEquals(kMsg1, kLen1);
260 } 260 }
261 261
262 TEST_F(DeterministicSocketDataTest, MixedReads) { 262 TEST_F(DeterministicSocketDataTest, MixedReads) {
263 MockRead reads[] = { 263 MockRead reads[] = {
264 MockRead(false, kMsg1, kLen1, 0), // Sync Read 264 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
265 MockRead(true, kMsg2, kLen2, 1), // Async Read 265 MockRead(ASYNC, kMsg2, kLen2, 1), // Async Read
266 MockRead(false, kMsg3, kLen3, 2), // Sync Read 266 MockRead(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Read
267 MockRead(true, kMsg3, kLen3, 3), // Async Read 267 MockRead(ASYNC, kMsg3, kLen3, 3), // Async Read
268 MockRead(false, kMsg2, kLen2, 4), // Sync Read 268 MockRead(SYNCHRONOUS, kMsg2, kLen2, 4), // Sync Read
269 MockRead(true, kMsg3, kLen3, 5), // Async Read 269 MockRead(ASYNC, kMsg3, kLen3, 5), // Async Read
270 MockRead(false, kMsg1, kLen1, 6), // Sync Read 270 MockRead(SYNCHRONOUS, kMsg1, kLen1, 6), // Sync Read
271 MockRead(false, 0, 7), // EOF 271 MockRead(SYNCHRONOUS, 0, 7), // EOF
272 }; 272 };
273 273
274 Initialize(reads, arraysize(reads), NULL, 0); 274 Initialize(reads, arraysize(reads), NULL, 0);
275 275
276 data_->StopAfter(1); 276 data_->StopAfter(1);
277 AssertSyncReadEquals(kMsg1, kLen1); 277 AssertSyncReadEquals(kMsg1, kLen1);
278 AssertAsyncReadEquals(kMsg2, kLen2); 278 AssertAsyncReadEquals(kMsg2, kLen2);
279 data_->StopAfter(1); 279 data_->StopAfter(1);
280 AssertSyncReadEquals(kMsg3, kLen3); 280 AssertSyncReadEquals(kMsg3, kLen3);
281 AssertAsyncReadEquals(kMsg3, kLen3); 281 AssertAsyncReadEquals(kMsg3, kLen3);
282 data_->StopAfter(1); 282 data_->StopAfter(1);
283 AssertSyncReadEquals(kMsg2, kLen2); 283 AssertSyncReadEquals(kMsg2, kLen2);
284 AssertAsyncReadEquals(kMsg3, kLen3); 284 AssertAsyncReadEquals(kMsg3, kLen3);
285 data_->StopAfter(1); 285 data_->StopAfter(1);
286 AssertSyncReadEquals(kMsg1, kLen1); 286 AssertSyncReadEquals(kMsg1, kLen1);
287 } 287 }
288 288
289 // ----------- Write 289 // ----------- Write
290 290
291 TEST_F(DeterministicSocketDataTest, SingleSyncWriteWhileStopped) { 291 TEST_F(DeterministicSocketDataTest, SingleSyncWriteWhileStopped) {
292 MockWrite writes[] = { 292 MockWrite writes[] = {
293 MockWrite(false, kMsg1, kLen1, 0), // Sync Read 293 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
294 }; 294 };
295 295
296 Initialize(NULL, 0, writes, arraysize(writes)); 296 Initialize(NULL, 0, writes, arraysize(writes));
297 297
298 data_->SetStopped(true); 298 data_->SetStopped(true);
299 AssertWriteReturns(kMsg1, kLen1, ERR_UNEXPECTED); 299 AssertWriteReturns(kMsg1, kLen1, ERR_UNEXPECTED);
300 } 300 }
301 301
302 TEST_F(DeterministicSocketDataTest, SingleSyncWriteTooEarly) { 302 TEST_F(DeterministicSocketDataTest, SingleSyncWriteTooEarly) {
303 MockWrite writes[] = { 303 MockWrite writes[] = {
304 MockWrite(false, kMsg1, kLen1, 1), // Sync Write 304 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 1), // Sync Write
305 }; 305 };
306 306
307 Initialize(NULL, 0, writes, arraysize(writes)); 307 Initialize(NULL, 0, writes, arraysize(writes));
308 308
309 data_->StopAfter(2); 309 data_->StopAfter(2);
310 ASSERT_FALSE(data_->stopped()); 310 ASSERT_FALSE(data_->stopped());
311 AssertWriteReturns(kMsg1, kLen1, ERR_UNEXPECTED); 311 AssertWriteReturns(kMsg1, kLen1, ERR_UNEXPECTED);
312 } 312 }
313 313
314 TEST_F(DeterministicSocketDataTest, SingleSyncWrite) { 314 TEST_F(DeterministicSocketDataTest, SingleSyncWrite) {
315 MockWrite writes[] = { 315 MockWrite writes[] = {
316 MockWrite(false, kMsg1, kLen1, 0), // Sync Write 316 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Write
317 }; 317 };
318 318
319 Initialize(NULL, 0, writes, arraysize(writes)); 319 Initialize(NULL, 0, writes, arraysize(writes));
320 320
321 // Make sure we don't stop before we've read all the data 321 // Make sure we don't stop before we've read all the data
322 data_->StopAfter(1); 322 data_->StopAfter(1);
323 AssertSyncWriteEquals(kMsg1, kLen1); 323 AssertSyncWriteEquals(kMsg1, kLen1);
324 } 324 }
325 325
326 TEST_F(DeterministicSocketDataTest, MultipleSyncWrites) { 326 TEST_F(DeterministicSocketDataTest, MultipleSyncWrites) {
327 MockWrite writes[] = { 327 MockWrite writes[] = {
328 MockWrite(false, kMsg1, kLen1, 0), // Sync Write 328 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Write
329 MockWrite(false, kMsg2, kLen2, 1), // Sync Write 329 MockWrite(SYNCHRONOUS, kMsg2, kLen2, 1), // Sync Write
330 MockWrite(false, kMsg3, kLen3, 2), // Sync Write 330 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Write
331 MockWrite(false, kMsg3, kLen3, 3), // Sync Write 331 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 3), // Sync Write
332 MockWrite(false, kMsg2, kLen2, 4), // Sync Write 332 MockWrite(SYNCHRONOUS, kMsg2, kLen2, 4), // Sync Write
333 MockWrite(false, kMsg3, kLen3, 5), // Sync Write 333 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 5), // Sync Write
334 MockWrite(false, kMsg1, kLen1, 6), // Sync Write 334 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 6), // Sync Write
335 }; 335 };
336 336
337 Initialize(NULL, 0, writes, arraysize(writes)); 337 Initialize(NULL, 0, writes, arraysize(writes));
338 338
339 // Make sure we don't stop before we've read all the data 339 // Make sure we don't stop before we've read all the data
340 data_->StopAfter(10); 340 data_->StopAfter(10);
341 AssertSyncWriteEquals(kMsg1, kLen1); 341 AssertSyncWriteEquals(kMsg1, kLen1);
342 AssertSyncWriteEquals(kMsg2, kLen2); 342 AssertSyncWriteEquals(kMsg2, kLen2);
343 AssertSyncWriteEquals(kMsg3, kLen3); 343 AssertSyncWriteEquals(kMsg3, kLen3);
344 AssertSyncWriteEquals(kMsg3, kLen3); 344 AssertSyncWriteEquals(kMsg3, kLen3);
345 AssertSyncWriteEquals(kMsg2, kLen2); 345 AssertSyncWriteEquals(kMsg2, kLen2);
346 AssertSyncWriteEquals(kMsg3, kLen3); 346 AssertSyncWriteEquals(kMsg3, kLen3);
347 AssertSyncWriteEquals(kMsg1, kLen1); 347 AssertSyncWriteEquals(kMsg1, kLen1);
348 } 348 }
349 349
350 TEST_F(DeterministicSocketDataTest, SingleAsyncWrite) { 350 TEST_F(DeterministicSocketDataTest, SingleAsyncWrite) {
351 MockWrite writes[] = { 351 MockWrite writes[] = {
352 MockWrite(true, kMsg1, kLen1, 0), // Async Write 352 MockWrite(ASYNC, kMsg1, kLen1, 0), // Async Write
353 }; 353 };
354 354
355 Initialize(NULL, 0, writes, arraysize(writes)); 355 Initialize(NULL, 0, writes, arraysize(writes));
356 356
357 AssertAsyncWriteEquals(kMsg1, kLen1); 357 AssertAsyncWriteEquals(kMsg1, kLen1);
358 } 358 }
359 359
360 TEST_F(DeterministicSocketDataTest, MultipleAsyncWrites) { 360 TEST_F(DeterministicSocketDataTest, MultipleAsyncWrites) {
361 MockWrite writes[] = { 361 MockWrite writes[] = {
362 MockWrite(true, kMsg1, kLen1, 0), // Async Write 362 MockWrite(ASYNC, kMsg1, kLen1, 0), // Async Write
363 MockWrite(true, kMsg2, kLen2, 1), // Async Write 363 MockWrite(ASYNC, kMsg2, kLen2, 1), // Async Write
364 MockWrite(true, kMsg3, kLen3, 2), // Async Write 364 MockWrite(ASYNC, kMsg3, kLen3, 2), // Async Write
365 MockWrite(true, kMsg3, kLen3, 3), // Async Write 365 MockWrite(ASYNC, kMsg3, kLen3, 3), // Async Write
366 MockWrite(true, kMsg2, kLen2, 4), // Async Write 366 MockWrite(ASYNC, kMsg2, kLen2, 4), // Async Write
367 MockWrite(true, kMsg3, kLen3, 5), // Async Write 367 MockWrite(ASYNC, kMsg3, kLen3, 5), // Async Write
368 MockWrite(true, kMsg1, kLen1, 6), // Async Write 368 MockWrite(ASYNC, kMsg1, kLen1, 6), // Async Write
369 }; 369 };
370 370
371 Initialize(NULL, 0, writes, arraysize(writes)); 371 Initialize(NULL, 0, writes, arraysize(writes));
372 372
373 AssertAsyncWriteEquals(kMsg1, kLen1); 373 AssertAsyncWriteEquals(kMsg1, kLen1);
374 AssertAsyncWriteEquals(kMsg2, kLen2); 374 AssertAsyncWriteEquals(kMsg2, kLen2);
375 AssertAsyncWriteEquals(kMsg3, kLen3); 375 AssertAsyncWriteEquals(kMsg3, kLen3);
376 AssertAsyncWriteEquals(kMsg3, kLen3); 376 AssertAsyncWriteEquals(kMsg3, kLen3);
377 AssertAsyncWriteEquals(kMsg2, kLen2); 377 AssertAsyncWriteEquals(kMsg2, kLen2);
378 AssertAsyncWriteEquals(kMsg3, kLen3); 378 AssertAsyncWriteEquals(kMsg3, kLen3);
379 AssertAsyncWriteEquals(kMsg1, kLen1); 379 AssertAsyncWriteEquals(kMsg1, kLen1);
380 } 380 }
381 381
382 TEST_F(DeterministicSocketDataTest, MixedWrites) { 382 TEST_F(DeterministicSocketDataTest, MixedWrites) {
383 MockWrite writes[] = { 383 MockWrite writes[] = {
384 MockWrite(false, kMsg1, kLen1, 0), // Sync Write 384 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Write
385 MockWrite(true, kMsg2, kLen2, 1), // Async Write 385 MockWrite(ASYNC, kMsg2, kLen2, 1), // Async Write
386 MockWrite(false, kMsg3, kLen3, 2), // Sync Write 386 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Write
387 MockWrite(true, kMsg3, kLen3, 3), // Async Write 387 MockWrite(ASYNC, kMsg3, kLen3, 3), // Async Write
388 MockWrite(false, kMsg2, kLen2, 4), // Sync Write 388 MockWrite(SYNCHRONOUS, kMsg2, kLen2, 4), // Sync Write
389 MockWrite(true, kMsg3, kLen3, 5), // Async Write 389 MockWrite(ASYNC, kMsg3, kLen3, 5), // Async Write
390 MockWrite(false, kMsg1, kLen1, 6), // Sync Write 390 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 6), // Sync Write
391 }; 391 };
392 392
393 Initialize(NULL, 0, writes, arraysize(writes)); 393 Initialize(NULL, 0, writes, arraysize(writes));
394 394
395 data_->StopAfter(1); 395 data_->StopAfter(1);
396 AssertSyncWriteEquals(kMsg1, kLen1); 396 AssertSyncWriteEquals(kMsg1, kLen1);
397 AssertAsyncWriteEquals(kMsg2, kLen2); 397 AssertAsyncWriteEquals(kMsg2, kLen2);
398 data_->StopAfter(1); 398 data_->StopAfter(1);
399 AssertSyncWriteEquals(kMsg3, kLen3); 399 AssertSyncWriteEquals(kMsg3, kLen3);
400 AssertAsyncWriteEquals(kMsg3, kLen3); 400 AssertAsyncWriteEquals(kMsg3, kLen3);
401 data_->StopAfter(1); 401 data_->StopAfter(1);
402 AssertSyncWriteEquals(kMsg2, kLen2); 402 AssertSyncWriteEquals(kMsg2, kLen2);
403 AssertAsyncWriteEquals(kMsg3, kLen3); 403 AssertAsyncWriteEquals(kMsg3, kLen3);
404 data_->StopAfter(1); 404 data_->StopAfter(1);
405 AssertSyncWriteEquals(kMsg1, kLen1); 405 AssertSyncWriteEquals(kMsg1, kLen1);
406 } 406 }
407 407
408 // ----------- Mixed Reads and Writes 408 // ----------- Mixed Reads and Writes
409 409
410 TEST_F(DeterministicSocketDataTest, MixedSyncOperations) { 410 TEST_F(DeterministicSocketDataTest, MixedSyncOperations) {
411 MockRead reads[] = { 411 MockRead reads[] = {
412 MockRead(false, kMsg1, kLen1, 0), // Sync Read 412 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
413 MockRead(false, kMsg2, kLen2, 3), // Sync Read 413 MockRead(SYNCHRONOUS, kMsg2, kLen2, 3), // Sync Read
414 MockRead(false, 0, 4), // EOF 414 MockRead(SYNCHRONOUS, 0, 4), // EOF
415 }; 415 };
416 416
417 MockWrite writes[] = { 417 MockWrite writes[] = {
418 MockWrite(false, kMsg2, kLen2, 1), // Sync Write 418 MockWrite(SYNCHRONOUS, kMsg2, kLen2, 1), // Sync Write
419 MockWrite(false, kMsg3, kLen3, 2), // Sync Write 419 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Write
420 }; 420 };
421 421
422 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 422 Initialize(reads, arraysize(reads), writes, arraysize(writes));
423 423
424 // Make sure we don't stop before we've read/written everything 424 // Make sure we don't stop before we've read/written everything
425 data_->StopAfter(10); 425 data_->StopAfter(10);
426 AssertSyncReadEquals(kMsg1, kLen1); 426 AssertSyncReadEquals(kMsg1, kLen1);
427 AssertSyncWriteEquals(kMsg2, kLen2); 427 AssertSyncWriteEquals(kMsg2, kLen2);
428 AssertSyncWriteEquals(kMsg3, kLen3); 428 AssertSyncWriteEquals(kMsg3, kLen3);
429 AssertSyncReadEquals(kMsg2, kLen2); 429 AssertSyncReadEquals(kMsg2, kLen2);
430 } 430 }
431 431
432 TEST_F(DeterministicSocketDataTest, MixedAsyncOperations) { 432 TEST_F(DeterministicSocketDataTest, MixedAsyncOperations) {
433 MockRead reads[] = { 433 MockRead reads[] = {
434 MockRead(true, kMsg1, kLen1, 0), // Sync Read 434 MockRead(ASYNC, kMsg1, kLen1, 0), // Sync Read
435 MockRead(true, kMsg2, kLen2, 3), // Sync Read 435 MockRead(ASYNC, kMsg2, kLen2, 3), // Sync Read
436 MockRead(true, 0, 4), // EOF 436 MockRead(ASYNC, 0, 4), // EOF
437 }; 437 };
438 438
439 MockWrite writes[] = { 439 MockWrite writes[] = {
440 MockWrite(true, kMsg2, kLen2, 1), // Sync Write 440 MockWrite(ASYNC, kMsg2, kLen2, 1), // Sync Write
441 MockWrite(true, kMsg3, kLen3, 2), // Sync Write 441 MockWrite(ASYNC, kMsg3, kLen3, 2), // Sync Write
442 }; 442 };
443 443
444 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 444 Initialize(reads, arraysize(reads), writes, arraysize(writes));
445 445
446 AssertAsyncReadEquals(kMsg1, kLen1); 446 AssertAsyncReadEquals(kMsg1, kLen1);
447 AssertAsyncWriteEquals(kMsg2, kLen2); 447 AssertAsyncWriteEquals(kMsg2, kLen2);
448 AssertAsyncWriteEquals(kMsg3, kLen3); 448 AssertAsyncWriteEquals(kMsg3, kLen3);
449 AssertAsyncReadEquals(kMsg2, kLen2); 449 AssertAsyncReadEquals(kMsg2, kLen2);
450 } 450 }
451 451
452 TEST_F(DeterministicSocketDataTest, InterleavedAsyncOperations) { 452 TEST_F(DeterministicSocketDataTest, InterleavedAsyncOperations) {
453 // Order of completion is read, write, write, read 453 // Order of completion is read, write, write, read
454 MockRead reads[] = { 454 MockRead reads[] = {
455 MockRead(true, kMsg1, kLen1, 0), // Async Read 455 MockRead(ASYNC, kMsg1, kLen1, 0), // Async Read
456 MockRead(true, kMsg2, kLen2, 3), // Async Read 456 MockRead(ASYNC, kMsg2, kLen2, 3), // Async Read
457 MockRead(true, 0, 4), // EOF 457 MockRead(ASYNC, 0, 4), // EOF
458 }; 458 };
459 459
460 MockWrite writes[] = { 460 MockWrite writes[] = {
461 MockWrite(true, kMsg2, kLen2, 1), // Async Write 461 MockWrite(ASYNC, kMsg2, kLen2, 1), // Async Write
462 MockWrite(true, kMsg3, kLen3, 2), // Async Write 462 MockWrite(ASYNC, kMsg3, kLen3, 2), // Async Write
463 }; 463 };
464 464
465 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 465 Initialize(reads, arraysize(reads), writes, arraysize(writes));
466 466
467 // Issue the write, which will block until the read completes 467 // Issue the write, which will block until the read completes
468 AssertWriteReturns(kMsg2, kLen2, ERR_IO_PENDING); 468 AssertWriteReturns(kMsg2, kLen2, ERR_IO_PENDING);
469 469
470 // Issue the read which will return first 470 // Issue the read which will return first
471 AssertReadReturns(kMsg1, kLen1, ERR_IO_PENDING); 471 AssertReadReturns(kMsg1, kLen1, ERR_IO_PENDING);
472 472
(...skipping 15 matching lines...) Expand all
488 ASSERT_EQ(kLen3, write_callback_.WaitForResult()); 488 ASSERT_EQ(kLen3, write_callback_.WaitForResult());
489 489
490 data_->RunFor(1); 490 data_->RunFor(1);
491 ASSERT_EQ(kLen2, read_callback_.WaitForResult()); 491 ASSERT_EQ(kLen2, read_callback_.WaitForResult());
492 AssertReadBufferEquals(kMsg2, kLen2); 492 AssertReadBufferEquals(kMsg2, kLen2);
493 } 493 }
494 494
495 TEST_F(DeterministicSocketDataTest, InterleavedMixedOperations) { 495 TEST_F(DeterministicSocketDataTest, InterleavedMixedOperations) {
496 // Order of completion is read, write, write, read 496 // Order of completion is read, write, write, read
497 MockRead reads[] = { 497 MockRead reads[] = {
498 MockRead(false, kMsg1, kLen1, 0), // Sync Read 498 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
499 MockRead(true, kMsg2, kLen2, 3), // Async Read 499 MockRead(ASYNC, kMsg2, kLen2, 3), // Async Read
500 MockRead(false, 0, 4), // EOF 500 MockRead(SYNCHRONOUS, 0, 4), // EOF
501 }; 501 };
502 502
503 MockWrite writes[] = { 503 MockWrite writes[] = {
504 MockWrite(true, kMsg2, kLen2, 1), // Async Write 504 MockWrite(ASYNC, kMsg2, kLen2, 1), // Async Write
505 MockWrite(false, kMsg3, kLen3, 2), // Sync Write 505 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Write
506 }; 506 };
507 507
508 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 508 Initialize(reads, arraysize(reads), writes, arraysize(writes));
509 509
510 // Issue the write, which will block until the read completes 510 // Issue the write, which will block until the read completes
511 AssertWriteReturns(kMsg2, kLen2, ERR_IO_PENDING); 511 AssertWriteReturns(kMsg2, kLen2, ERR_IO_PENDING);
512 512
513 // Issue the writes which will complete immediately 513 // Issue the writes which will complete immediately
514 data_->StopAfter(1); 514 data_->StopAfter(1);
515 AssertSyncReadEquals(kMsg1, kLen1); 515 AssertSyncReadEquals(kMsg1, kLen1);
516 516
517 data_->RunFor(1); 517 data_->RunFor(1);
518 ASSERT_EQ(kLen2, write_callback_.WaitForResult()); 518 ASSERT_EQ(kLen2, write_callback_.WaitForResult());
519 519
520 // Issue the read, which will block until the write completes 520 // Issue the read, which will block until the write completes
521 AssertReadReturns(kMsg2, kLen2, ERR_IO_PENDING); 521 AssertReadReturns(kMsg2, kLen2, ERR_IO_PENDING);
522 522
523 // Issue the writes which will complete immediately 523 // Issue the writes which will complete immediately
524 data_->StopAfter(1); 524 data_->StopAfter(1);
525 AssertSyncWriteEquals(kMsg3, kLen3); 525 AssertSyncWriteEquals(kMsg3, kLen3);
526 526
527 data_->RunFor(1); 527 data_->RunFor(1);
528 ASSERT_EQ(kLen2, read_callback_.WaitForResult()); 528 ASSERT_EQ(kLen2, read_callback_.WaitForResult());
529 AssertReadBufferEquals(kMsg2, kLen2); 529 AssertReadBufferEquals(kMsg2, kLen2);
530 } 530 }
531 531
532 } // namespace net 532 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_proxy_client_socket_pool_unittest.cc ('k') | net/socket/socket_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698