Index: base/platform_file_unittest.cc |
diff --git a/base/platform_file_unittest.cc b/base/platform_file_unittest.cc |
index 748387610f0436ca3ee90147e81dd3cc2482e114..761653e27bed5291d932d9d3c5d43bebff3dcbec 100644 |
--- a/base/platform_file_unittest.cc |
+++ b/base/platform_file_unittest.cc |
@@ -211,6 +211,58 @@ 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("append_file"); |
+ base::PlatformFile file = base::CreatePlatformFile( |
+ file_path, |
+ base::PLATFORM_FILE_CREATE | |
+ base::PLATFORM_FILE_APPEND, |
jar (doing other things)
2013/06/04 23:31:50
nit: This should fit nicely (and more readably) on
|
+ 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); |
jar (doing other things)
2013/06/04 23:31:50
nit: I can see this odd style used elsewhere in th
|
+ 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 |
jar (doing other things)
2013/06/04 23:31:50
nit: Periods at end of sentences.
|
+ 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()); |