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 #include "ppapi/tests/test_file_io.h" | 5 #include "ppapi/tests/test_file_io.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <stdio.h> |
9 #include <string.h> | 10 #include <string.h> |
10 #include <sys/stat.h> | 11 #include <sys/stat.h> |
11 #include <sys/types.h> | 12 #include <sys/types.h> |
12 | 13 |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "ppapi/c/dev/ppb_testing_dev.h" | 16 #include "ppapi/c/dev/ppb_testing_dev.h" |
16 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
17 #include "ppapi/c/ppb_file_io.h" | 18 #include "ppapi/c/ppb_file_io.h" |
18 #include "ppapi/c/private/pp_file_handle.h" | 19 #include "ppapi/c/private/pp_file_handle.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 ASSERT_EQ(PP_OK, rv); | 408 ASSERT_EQ(PP_OK, rv); |
408 ASSERT_EQ(std::string("testtesttest\0\0\0\0", 16), read_buffer); | 409 ASSERT_EQ(std::string("testtesttest\0\0\0\0", 16), read_buffer); |
409 | 410 |
410 // Read from the middle of the file. | 411 // Read from the middle of the file. |
411 read_buffer.clear(); | 412 read_buffer.clear(); |
412 rv = ReadEntireFile(instance_->pp_instance(), &file_io, 4, &read_buffer, | 413 rv = ReadEntireFile(instance_->pp_instance(), &file_io, 4, &read_buffer, |
413 callback_type()); | 414 callback_type()); |
414 ASSERT_EQ(PP_OK, rv); | 415 ASSERT_EQ(PP_OK, rv); |
415 ASSERT_EQ(std::string("testtest\0\0\0\0", 12), read_buffer); | 416 ASSERT_EQ(std::string("testtest\0\0\0\0", 12), read_buffer); |
416 | 417 |
| 418 // Append to the end of the file. |
| 419 pp::FileIO file_io2(instance_); |
| 420 callback.WaitForResult(file_io2.Open(file_ref, |
| 421 PP_FILEOPENFLAG_CREATE | |
| 422 PP_FILEOPENFLAG_READ | |
| 423 PP_FILEOPENFLAG_APPEND, |
| 424 callback.GetCallback())); |
| 425 rv = WriteEntireBuffer(instance_->pp_instance(), &file_io2, 0, "appended", |
| 426 callback_type()); |
| 427 ASSERT_EQ(PP_OK, rv); |
| 428 read_buffer.clear(); |
| 429 rv = ReadEntireFile(instance_->pp_instance(), &file_io2, 0, &read_buffer, |
| 430 callback_type()); |
| 431 ASSERT_EQ(PP_OK, rv); |
| 432 ASSERT_EQ(std::string("testtesttest\0\0\0\0appended", 24), read_buffer); |
| 433 |
417 PASS(); | 434 PASS(); |
418 } | 435 } |
419 | 436 |
420 // This is basically a copy of TestReadWriteSetLength, but with the new Read | 437 // This is basically a copy of TestReadWriteSetLength, but with the new Read |
421 // API. With this test case, we can make sure the two Read's have the same | 438 // API. With this test case, we can make sure the two Read's have the same |
422 // behavior. | 439 // behavior. |
423 std::string TestFileIO::TestReadToArrayWriteSetLength() { | 440 std::string TestFileIO::TestReadToArrayWriteSetLength() { |
424 if (callback_type() == PP_BLOCKING) { | 441 if (callback_type() == PP_BLOCKING) { |
425 // This test does not make sense for blocking callbacks. | 442 // This test does not make sense for blocking callbacks. |
426 PASS(); | 443 PASS(); |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 if ((invalid_combination && callback.result() == PP_OK) || | 1405 if ((invalid_combination && callback.result() == PP_OK) || |
1389 (!invalid_combination && | 1406 (!invalid_combination && |
1390 ((callback.result() == PP_OK) != create_if_doesnt_exist))) { | 1407 ((callback.result() == PP_OK) != create_if_doesnt_exist))) { |
1391 return ReportOpenError(open_flags); | 1408 return ReportOpenError(open_flags); |
1392 } | 1409 } |
1393 | 1410 |
1394 return std::string(); | 1411 return std::string(); |
1395 } | 1412 } |
1396 | 1413 |
1397 // TODO(viettrungluu): Test Close(). crbug.com/69457 | 1414 // TODO(viettrungluu): Test Close(). crbug.com/69457 |
OLD | NEW |