| Index: base/platform_file_unittest.cc
|
| diff --git a/base/platform_file_unittest.cc b/base/platform_file_unittest.cc
|
| index 748387610f0436ca3ee90147e81dd3cc2482e114..203e28446c217cb28072ae1fbcd8402126bf2439 100644
|
| --- a/base/platform_file_unittest.cc
|
| +++ b/base/platform_file_unittest.cc
|
| @@ -211,6 +211,59 @@ TEST(PlatformFile, ReadWritePlatformFile) {
|
| base::ClosePlatformFile(file);
|
| }
|
|
|
| +TEST(PlatformFile, AppendPlatformFile) {
|
| + base::ScopedTempDir temp_dir;
|
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| + FilePath file_path = temp_dir.path().AppendASCII("read_write_file");
|
| + base::PlatformFile file = base::CreatePlatformFile(
|
| + file_path,
|
| + base::PLATFORM_FILE_CREATE |
|
| + base::PLATFORM_FILE_READ |
|
| + base::PLATFORM_FILE_WRITE,
|
| + NULL, NULL);
|
| + EXPECT_NE(base::kInvalidPlatformFileValue, file);
|
| +
|
| + char data_to_write[] = "test";
|
| + const int kTestDataSize = 4;
|
| +
|
| + // Write 0 bytes to the file.
|
| + int bytes_written = WriteFully(file, 0, data_to_write, 0);
|
| + EXPECT_EQ(0, bytes_written);
|
| +
|
| + // Write "test" to the file.
|
| + bytes_written = WriteFully(file, 0, data_to_write, kTestDataSize);
|
| + EXPECT_EQ(kTestDataSize, bytes_written);
|
| +
|
| + base::ClosePlatformFile(file);
|
| + file = base::CreatePlatformFile(
|
| + file_path,
|
| + base::PLATFORM_FILE_OPEN |
|
| + base::PLATFORM_FILE_READ |
|
| + base::PLATFORM_FILE_APPEND,
|
| + NULL, NULL);
|
| + EXPECT_NE(base::kInvalidPlatformFileValue, file);
|
| + if (file == base::kInvalidPlatformFileValue) {
|
| + printf("errno: %d\n", errno);
|
| + }
|
| +
|
| + char append_data_to_write[] = "78";
|
| + const int kAppendDataSize = 2;
|
| +
|
| + // Append "test" to the file.
|
| + bytes_written = WriteFully(file, 0, append_data_to_write, kAppendDataSize);
|
| + EXPECT_EQ(2, bytes_written);
|
| +
|
| + // Read the entire file
|
| + char data_read_1[32];
|
| + int bytes_read = ReadFully(file, 0, data_read_1,
|
| + kTestDataSize + kAppendDataSize);
|
| + EXPECT_EQ(6, bytes_read);
|
| +
|
| + // Close the file handle to allow the temp directory to be deleted.
|
| + base::ClosePlatformFile(file);
|
| +}
|
| +
|
| +
|
| TEST(PlatformFile, TruncatePlatformFile) {
|
| base::ScopedTempDir temp_dir;
|
| ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
|
|