AppendToFile implementation.
DevTools wants to save very big files like HeapSnapshots.
It is not possible at the moment because the file can be about ~6Gb.
BUG=none
TEST=FileUtilTest.AppendToFile
Review URL: http://codereview.chromium.org/10263003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134492 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: 891128f4847bfb32e10604ced9a3b93c0272a80d
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 30db82c..ea8918b 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -1790,6 +1790,34 @@
// (we don't care what).
}
+TEST_F(FileUtilTest, AppendToFile) {
+ FilePath data_dir =
+ temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest"));
+
+ // Create a fresh, empty copy of this directory.
+ if (file_util::PathExists(data_dir)) {
+ ASSERT_TRUE(file_util::Delete(data_dir, true));
+ }
+ ASSERT_TRUE(file_util::CreateDirectory(data_dir));
+
+ // Create a fresh, empty copy of this directory.
+ if (file_util::PathExists(data_dir)) {
+ ASSERT_TRUE(file_util::Delete(data_dir, true));
+ }
+ ASSERT_TRUE(file_util::CreateDirectory(data_dir));
+ FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt")));
+
+ std::string data("hello");
+ EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length()));
+ EXPECT_EQ(static_cast<int>(data.length()),
+ file_util::WriteFile(foobar, data.c_str(), data.length()));
+ EXPECT_EQ(static_cast<int>(data.length()),
+ file_util::AppendToFile(foobar, data.c_str(), data.length()));
+
+ const std::wstring read_content = ReadTextFile(foobar);
+ EXPECT_EQ(L"hellohello", read_content);
+}
+
TEST_F(FileUtilTest, Contains) {
FilePath data_dir =
temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest"));