OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "ppapi/tests/test_file_io.h" | 5 #include "ppapi/tests/test_file_io.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 TestCompletionCallback callback; | 94 TestCompletionCallback callback; |
95 | 95 |
96 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 96 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
97 pp::FileRef_Dev file_ref(file_system, "/file_open"); | 97 pp::FileRef_Dev file_ref(file_system, "/file_open"); |
98 int32_t rv = file_system.Open(1024, callback); | 98 int32_t rv = file_system.Open(1024, callback); |
99 if (rv == PP_ERROR_WOULDBLOCK) | 99 if (rv == PP_ERROR_WOULDBLOCK) |
100 rv = callback.WaitForResult(); | 100 rv = callback.WaitForResult(); |
101 if (rv != PP_OK) | 101 if (rv != PP_OK) |
102 return ReportError("FileSystem::Open", rv); | 102 return ReportError("FileSystem::Open", rv); |
103 | 103 |
104 pp::FileIO_Dev file_io; | 104 pp::FileIO_Dev file_io(instance_); |
105 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback); | 105 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback); |
106 if (rv == PP_ERROR_WOULDBLOCK) | 106 if (rv == PP_ERROR_WOULDBLOCK) |
107 rv = callback.WaitForResult(); | 107 rv = callback.WaitForResult(); |
108 if (rv != PP_OK) | 108 if (rv != PP_OK) |
109 return ReportError("FileIO::Open", rv); | 109 return ReportError("FileIO::Open", rv); |
110 | 110 |
111 // Try opening a file that doesn't exist. | 111 // Try opening a file that doesn't exist. |
112 pp::FileRef_Dev nonexistent_file_ref(file_system, "/nonexistent_file"); | 112 pp::FileRef_Dev nonexistent_file_ref(file_system, "/nonexistent_file"); |
113 pp::FileIO_Dev nonexistent_file_io; | 113 pp::FileIO_Dev nonexistent_file_io(instance_); |
114 rv = nonexistent_file_io.Open( | 114 rv = nonexistent_file_io.Open( |
115 nonexistent_file_ref, PP_FILEOPENFLAG_READ, callback); | 115 nonexistent_file_ref, PP_FILEOPENFLAG_READ, callback); |
116 if (rv == PP_ERROR_WOULDBLOCK) | 116 if (rv == PP_ERROR_WOULDBLOCK) |
117 rv = callback.WaitForResult(); | 117 rv = callback.WaitForResult(); |
118 if (rv != PP_ERROR_FILENOTFOUND) | 118 if (rv != PP_ERROR_FILENOTFOUND) |
119 return ReportError("FileIO::Open", rv); | 119 return ReportError("FileIO::Open", rv); |
120 | 120 |
121 PASS(); | 121 PASS(); |
122 } | 122 } |
123 | 123 |
124 std::string TestFileIO::TestReadWriteSetLength() { | 124 std::string TestFileIO::TestReadWriteSetLength() { |
125 TestCompletionCallback callback; | 125 TestCompletionCallback callback; |
126 | 126 |
127 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 127 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
128 pp::FileRef_Dev file_ref(file_system, "/file_read_write_setlength"); | 128 pp::FileRef_Dev file_ref(file_system, "/file_read_write_setlength"); |
129 int32_t rv = file_system.Open(1024, callback); | 129 int32_t rv = file_system.Open(1024, callback); |
130 if (rv == PP_ERROR_WOULDBLOCK) | 130 if (rv == PP_ERROR_WOULDBLOCK) |
131 rv = callback.WaitForResult(); | 131 rv = callback.WaitForResult(); |
132 if (rv != PP_OK) | 132 if (rv != PP_OK) |
133 return ReportError("FileSystem::Open", rv); | 133 return ReportError("FileSystem::Open", rv); |
134 | 134 |
135 pp::FileIO_Dev file_io; | 135 pp::FileIO_Dev file_io(instance_); |
136 rv = file_io.Open(file_ref, | 136 rv = file_io.Open(file_ref, |
137 PP_FILEOPENFLAG_CREATE | | 137 PP_FILEOPENFLAG_CREATE | |
138 PP_FILEOPENFLAG_READ | | 138 PP_FILEOPENFLAG_READ | |
139 PP_FILEOPENFLAG_WRITE, | 139 PP_FILEOPENFLAG_WRITE, |
140 callback); | 140 callback); |
141 if (rv == PP_ERROR_WOULDBLOCK) | 141 if (rv == PP_ERROR_WOULDBLOCK) |
142 rv = callback.WaitForResult(); | 142 rv = callback.WaitForResult(); |
143 if (rv != PP_OK) | 143 if (rv != PP_OK) |
144 return ReportError("FileIO::Open", rv); | 144 return ReportError("FileIO::Open", rv); |
145 | 145 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 TestCompletionCallback callback; | 239 TestCompletionCallback callback; |
240 | 240 |
241 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 241 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
242 int32_t rv = file_system.Open(1024, callback); | 242 int32_t rv = file_system.Open(1024, callback); |
243 if (rv == PP_ERROR_WOULDBLOCK) | 243 if (rv == PP_ERROR_WOULDBLOCK) |
244 rv = callback.WaitForResult(); | 244 rv = callback.WaitForResult(); |
245 if (rv != PP_OK) | 245 if (rv != PP_OK) |
246 return ReportError("FileSystem::Open", rv); | 246 return ReportError("FileSystem::Open", rv); |
247 | 247 |
248 pp::FileRef_Dev file_ref(file_system, "/file_touch"); | 248 pp::FileRef_Dev file_ref(file_system, "/file_touch"); |
249 pp::FileIO_Dev file_io; | 249 pp::FileIO_Dev file_io(instance_); |
250 rv = file_io.Open(file_ref, | 250 rv = file_io.Open(file_ref, |
251 PP_FILEOPENFLAG_CREATE | PP_FILEOPENFLAG_WRITE, | 251 PP_FILEOPENFLAG_CREATE | PP_FILEOPENFLAG_WRITE, |
252 callback); | 252 callback); |
253 if (rv == PP_ERROR_WOULDBLOCK) | 253 if (rv == PP_ERROR_WOULDBLOCK) |
254 rv = callback.WaitForResult(); | 254 rv = callback.WaitForResult(); |
255 if (rv != PP_OK) | 255 if (rv != PP_OK) |
256 return ReportError("FileIO::Open", rv); | 256 return ReportError("FileIO::Open", rv); |
257 | 257 |
258 // Write some data to have a non-zero file size. | 258 // Write some data to have a non-zero file size. |
259 rv = file_io.Write(0, "test", 4, callback); | 259 rv = file_io.Write(0, "test", 4, callback); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 302 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
303 pp::FileRef_Dev file_ref(file_system, "/file_abort_calls"); | 303 pp::FileRef_Dev file_ref(file_system, "/file_abort_calls"); |
304 int32_t rv = file_system.Open(1024, callback); | 304 int32_t rv = file_system.Open(1024, callback); |
305 if (rv == PP_ERROR_WOULDBLOCK) | 305 if (rv == PP_ERROR_WOULDBLOCK) |
306 rv = callback.WaitForResult(); | 306 rv = callback.WaitForResult(); |
307 if (rv != PP_OK) | 307 if (rv != PP_OK) |
308 return ReportError("FileSystem::Open", rv); | 308 return ReportError("FileSystem::Open", rv); |
309 | 309 |
310 // First, create a file which to do ops on. | 310 // First, create a file which to do ops on. |
311 { | 311 { |
312 pp::FileIO_Dev file_io; | 312 pp::FileIO_Dev file_io(instance_); |
313 rv = file_io.Open(file_ref, | 313 rv = file_io.Open(file_ref, |
314 PP_FILEOPENFLAG_CREATE | PP_FILEOPENFLAG_WRITE, | 314 PP_FILEOPENFLAG_CREATE | PP_FILEOPENFLAG_WRITE, |
315 callback); | 315 callback); |
316 if (rv == PP_ERROR_WOULDBLOCK) | 316 if (rv == PP_ERROR_WOULDBLOCK) |
317 rv = callback.WaitForResult(); | 317 rv = callback.WaitForResult(); |
318 if (rv != PP_OK) | 318 if (rv != PP_OK) |
319 return ReportError("FileIO::Open", rv); | 319 return ReportError("FileIO::Open", rv); |
320 | 320 |
321 // N.B.: Should write at least 3 bytes. | 321 // N.B.: Should write at least 3 bytes. |
322 rv = WriteEntireBuffer(&file_io, 0, "foobarbazquux"); | 322 rv = WriteEntireBuffer(&file_io, 0, "foobarbazquux"); |
323 if (rv != PP_OK) | 323 if (rv != PP_OK) |
324 return ReportError("FileIO::Write", rv); | 324 return ReportError("FileIO::Write", rv); |
325 } | 325 } |
326 | 326 |
327 // Abort |Open()|. | 327 // Abort |Open()|. |
328 { | 328 { |
329 callback.reset_run_count(); | 329 callback.reset_run_count(); |
330 rv = pp::FileIO_Dev().Open(file_ref, PP_FILEOPENFLAG_READ, callback); | 330 rv = pp::FileIO_Dev(instance_).Open(file_ref, PP_FILEOPENFLAG_READ, callback ); |
darin (slow to review)
2011/02/03 21:05:38
nit: 80 char line length
| |
331 if (callback.run_count() > 0) | 331 if (callback.run_count() > 0) |
332 return "FileIO::Open ran callback synchronously."; | 332 return "FileIO::Open ran callback synchronously."; |
333 if (rv == PP_ERROR_WOULDBLOCK) { | 333 if (rv == PP_ERROR_WOULDBLOCK) { |
334 rv = callback.WaitForResult(); | 334 rv = callback.WaitForResult(); |
335 if (rv != PP_ERROR_ABORTED) | 335 if (rv != PP_ERROR_ABORTED) |
336 return "FileIO::Open not aborted."; | 336 return "FileIO::Open not aborted."; |
337 } else if (rv != PP_OK) { | 337 } else if (rv != PP_OK) { |
338 return ReportError("FileIO::Open", rv); | 338 return ReportError("FileIO::Open", rv); |
339 } | 339 } |
340 } | 340 } |
341 | 341 |
342 // Abort |Query()|. | 342 // Abort |Query()|. |
343 { | 343 { |
344 PP_FileInfo_Dev info = { 0 }; | 344 PP_FileInfo_Dev info = { 0 }; |
345 { | 345 { |
346 pp::FileIO_Dev file_io; | 346 pp::FileIO_Dev file_io(instance_); |
347 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback); | 347 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback); |
348 if (rv == PP_ERROR_WOULDBLOCK) | 348 if (rv == PP_ERROR_WOULDBLOCK) |
349 rv = callback.WaitForResult(); | 349 rv = callback.WaitForResult(); |
350 if (rv != PP_OK) | 350 if (rv != PP_OK) |
351 return ReportError("FileIO::Open", rv); | 351 return ReportError("FileIO::Open", rv); |
352 | 352 |
353 callback.reset_run_count(); | 353 callback.reset_run_count(); |
354 rv = file_io.Query(&info, callback); | 354 rv = file_io.Query(&info, callback); |
355 } // Destroy |file_io|. | 355 } // Destroy |file_io|. |
356 if (rv == PP_ERROR_WOULDBLOCK) { | 356 if (rv == PP_ERROR_WOULDBLOCK) { |
357 // Save a copy and make sure |info| doesn't get written to. | 357 // Save a copy and make sure |info| doesn't get written to. |
358 PP_FileInfo_Dev info_copy; | 358 PP_FileInfo_Dev info_copy; |
359 memcpy(&info_copy, &info, sizeof(info)); | 359 memcpy(&info_copy, &info, sizeof(info)); |
360 rv = callback.WaitForResult(); | 360 rv = callback.WaitForResult(); |
361 if (rv != PP_ERROR_ABORTED) | 361 if (rv != PP_ERROR_ABORTED) |
362 return "FileIO::Query not aborted."; | 362 return "FileIO::Query not aborted."; |
363 if (memcmp(&info_copy, &info, sizeof(info)) != 0) | 363 if (memcmp(&info_copy, &info, sizeof(info)) != 0) |
364 return "FileIO::Query wrote data after resource destruction."; | 364 return "FileIO::Query wrote data after resource destruction."; |
365 } else if (rv != PP_OK) { | 365 } else if (rv != PP_OK) { |
366 return ReportError("FileIO::Query", rv); | 366 return ReportError("FileIO::Query", rv); |
367 } | 367 } |
368 } | 368 } |
369 | 369 |
370 // Abort |Touch()|. | 370 // Abort |Touch()|. |
371 { | 371 { |
372 { | 372 { |
373 pp::FileIO_Dev file_io; | 373 pp::FileIO_Dev file_io(instance_); |
374 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_WRITE, callback); | 374 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_WRITE, callback); |
375 if (rv == PP_ERROR_WOULDBLOCK) | 375 if (rv == PP_ERROR_WOULDBLOCK) |
376 rv = callback.WaitForResult(); | 376 rv = callback.WaitForResult(); |
377 if (rv != PP_OK) | 377 if (rv != PP_OK) |
378 return ReportError("FileIO::Open", rv); | 378 return ReportError("FileIO::Open", rv); |
379 | 379 |
380 callback.reset_run_count(); | 380 callback.reset_run_count(); |
381 rv = file_io.Touch(0, 0, callback); | 381 rv = file_io.Touch(0, 0, callback); |
382 } // Destroy |file_io|. | 382 } // Destroy |file_io|. |
383 if (rv == PP_ERROR_WOULDBLOCK) { | 383 if (rv == PP_ERROR_WOULDBLOCK) { |
384 rv = callback.WaitForResult(); | 384 rv = callback.WaitForResult(); |
385 if (rv != PP_ERROR_ABORTED) | 385 if (rv != PP_ERROR_ABORTED) |
386 return "FileIO::Touch not aborted."; | 386 return "FileIO::Touch not aborted."; |
387 } else if (rv != PP_OK) { | 387 } else if (rv != PP_OK) { |
388 return ReportError("FileIO::Touch", rv); | 388 return ReportError("FileIO::Touch", rv); |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 // Abort |Read()|. | 392 // Abort |Read()|. |
393 { | 393 { |
394 char buf[3] = { 0 }; | 394 char buf[3] = { 0 }; |
395 { | 395 { |
396 pp::FileIO_Dev file_io; | 396 pp::FileIO_Dev file_io(instance_); |
397 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback); | 397 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback); |
398 if (rv == PP_ERROR_WOULDBLOCK) | 398 if (rv == PP_ERROR_WOULDBLOCK) |
399 rv = callback.WaitForResult(); | 399 rv = callback.WaitForResult(); |
400 if (rv != PP_OK) | 400 if (rv != PP_OK) |
401 return ReportError("FileIO::Open", rv); | 401 return ReportError("FileIO::Open", rv); |
402 | 402 |
403 callback.reset_run_count(); | 403 callback.reset_run_count(); |
404 rv = file_io.Read(0, buf, sizeof(buf), callback); | 404 rv = file_io.Read(0, buf, sizeof(buf), callback); |
405 } // Destroy |file_io|. | 405 } // Destroy |file_io|. |
406 if (rv == PP_ERROR_WOULDBLOCK) { | 406 if (rv == PP_ERROR_WOULDBLOCK) { |
407 // Save a copy and make sure |buf| doesn't get written to. | 407 // Save a copy and make sure |buf| doesn't get written to. |
408 char buf_copy[3]; | 408 char buf_copy[3]; |
409 memcpy(&buf_copy, &buf, sizeof(buf)); | 409 memcpy(&buf_copy, &buf, sizeof(buf)); |
410 rv = callback.WaitForResult(); | 410 rv = callback.WaitForResult(); |
411 if (rv != PP_ERROR_ABORTED) | 411 if (rv != PP_ERROR_ABORTED) |
412 return "FileIO::Read not aborted."; | 412 return "FileIO::Read not aborted."; |
413 if (memcmp(&buf_copy, &buf, sizeof(buf)) != 0) | 413 if (memcmp(&buf_copy, &buf, sizeof(buf)) != 0) |
414 return "FileIO::Read wrote data after resource destruction."; | 414 return "FileIO::Read wrote data after resource destruction."; |
415 } else if (rv != PP_OK) { | 415 } else if (rv != PP_OK) { |
416 return ReportError("FileIO::Read", rv); | 416 return ReportError("FileIO::Read", rv); |
417 } | 417 } |
418 } | 418 } |
419 | 419 |
420 // Abort |Write()|. | 420 // Abort |Write()|. |
421 { | 421 { |
422 char buf[3] = { 0 }; | 422 char buf[3] = { 0 }; |
423 { | 423 { |
424 pp::FileIO_Dev file_io; | 424 pp::FileIO_Dev file_io(instance_); |
425 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback); | 425 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback); |
426 if (rv == PP_ERROR_WOULDBLOCK) | 426 if (rv == PP_ERROR_WOULDBLOCK) |
427 rv = callback.WaitForResult(); | 427 rv = callback.WaitForResult(); |
428 if (rv != PP_OK) | 428 if (rv != PP_OK) |
429 return ReportError("FileIO::Open", rv); | 429 return ReportError("FileIO::Open", rv); |
430 | 430 |
431 callback.reset_run_count(); | 431 callback.reset_run_count(); |
432 rv = file_io.Write(0, buf, sizeof(buf), callback); | 432 rv = file_io.Write(0, buf, sizeof(buf), callback); |
433 } // Destroy |file_io|. | 433 } // Destroy |file_io|. |
434 if (rv == PP_ERROR_WOULDBLOCK) { | 434 if (rv == PP_ERROR_WOULDBLOCK) { |
435 rv = callback.WaitForResult(); | 435 rv = callback.WaitForResult(); |
436 if (rv != PP_ERROR_ABORTED) | 436 if (rv != PP_ERROR_ABORTED) |
437 return "FileIO::Write not aborted."; | 437 return "FileIO::Write not aborted."; |
438 } else if (rv != PP_OK) { | 438 } else if (rv != PP_OK) { |
439 return ReportError("FileIO::Write", rv); | 439 return ReportError("FileIO::Write", rv); |
440 } | 440 } |
441 } | 441 } |
442 | 442 |
443 // Abort |SetLength()|. | 443 // Abort |SetLength()|. |
444 { | 444 { |
445 { | 445 { |
446 pp::FileIO_Dev file_io; | 446 pp::FileIO_Dev file_io(instance_); |
447 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback); | 447 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback); |
448 if (rv == PP_ERROR_WOULDBLOCK) | 448 if (rv == PP_ERROR_WOULDBLOCK) |
449 rv = callback.WaitForResult(); | 449 rv = callback.WaitForResult(); |
450 if (rv != PP_OK) | 450 if (rv != PP_OK) |
451 return ReportError("FileIO::Open", rv); | 451 return ReportError("FileIO::Open", rv); |
452 | 452 |
453 callback.reset_run_count(); | 453 callback.reset_run_count(); |
454 rv = file_io.SetLength(3, callback); | 454 rv = file_io.SetLength(3, callback); |
455 } // Destroy |file_io|. | 455 } // Destroy |file_io|. |
456 if (rv == PP_ERROR_WOULDBLOCK) { | 456 if (rv == PP_ERROR_WOULDBLOCK) { |
457 rv = callback.WaitForResult(); | 457 rv = callback.WaitForResult(); |
458 if (rv != PP_ERROR_ABORTED) | 458 if (rv != PP_ERROR_ABORTED) |
459 return "FileIO::SetLength not aborted."; | 459 return "FileIO::SetLength not aborted."; |
460 } else if (rv != PP_OK) { | 460 } else if (rv != PP_OK) { |
461 return ReportError("FileIO::SetLength", rv); | 461 return ReportError("FileIO::SetLength", rv); |
462 } | 462 } |
463 } | 463 } |
464 | 464 |
465 // Abort |Flush()|. | 465 // Abort |Flush()|. |
466 { | 466 { |
467 { | 467 { |
468 pp::FileIO_Dev file_io; | 468 pp::FileIO_Dev file_io(instance_); |
469 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback); | 469 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback); |
470 if (rv == PP_ERROR_WOULDBLOCK) | 470 if (rv == PP_ERROR_WOULDBLOCK) |
471 rv = callback.WaitForResult(); | 471 rv = callback.WaitForResult(); |
472 if (rv != PP_OK) | 472 if (rv != PP_OK) |
473 return ReportError("FileIO::Open", rv); | 473 return ReportError("FileIO::Open", rv); |
474 | 474 |
475 callback.reset_run_count(); | 475 callback.reset_run_count(); |
476 rv = file_io.Flush(callback); | 476 rv = file_io.Flush(callback); |
477 } // Destroy |file_io|. | 477 } // Destroy |file_io|. |
478 if (rv == PP_ERROR_WOULDBLOCK) { | 478 if (rv == PP_ERROR_WOULDBLOCK) { |
479 rv = callback.WaitForResult(); | 479 rv = callback.WaitForResult(); |
480 if (rv != PP_ERROR_ABORTED) | 480 if (rv != PP_ERROR_ABORTED) |
481 return "FileIO::Flush not aborted."; | 481 return "FileIO::Flush not aborted."; |
482 } else if (rv != PP_OK) { | 482 } else if (rv != PP_OK) { |
483 return ReportError("FileIO::Flush", rv); | 483 return ReportError("FileIO::Flush", rv); |
484 } | 484 } |
485 } | 485 } |
486 | 486 |
487 // TODO(viettrungluu): Also test that Close() aborts callbacks. | 487 // TODO(viettrungluu): Also test that Close() aborts callbacks. |
488 // crbug.com/69457 | 488 // crbug.com/69457 |
489 | 489 |
490 PASS(); | 490 PASS(); |
491 } | 491 } |
492 | 492 |
493 // TODO(viettrungluu): Test Close(). crbug.com/69457 | 493 // TODO(viettrungluu): Test Close(). crbug.com/69457 |
OLD | NEW |