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

Unified Diff: base/platform_file_unittest.cc

Issue 15861011: Add an "append flag" to base::PlatformFile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary braces Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
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());

Powered by Google App Engine
This is Rietveld 408576698