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

Unified Diff: net/base/file_stream_unittest.cc

Issue 39301: Adds truncate to FileStream. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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
« no previous file with comments | « net/base/file_stream_posix.cc ('k') | net/base/file_stream_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/file_stream_unittest.cc
===================================================================
--- net/base/file_stream_unittest.cc (revision 11127)
+++ net/base/file_stream_unittest.cc (working copy)
@@ -406,4 +406,31 @@
EXPECT_EQ(kTestDataSize * 2, file_size);
}
+// Tests truncating a file.
+TEST_F(FileStreamTest, Truncate) {
+ int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE;
+
+ net::FileStream write_stream;
+ ASSERT_EQ(net::OK, write_stream.Open(temp_file_path(), flags));
+
+ // Write some data to the file.
+ const char test_data[] = "0123456789";
+ write_stream.Write(test_data, arraysize(test_data), NULL);
+
+ // Truncate the file.
+ ASSERT_EQ(4, write_stream.Truncate(4));
+
+ // Write again.
+ write_stream.Write(test_data, 4, NULL);
+
+ // Close the stream.
+ write_stream.Close();
+
+ // Read in the contents and make sure we get back what we expected.
+ std::string read_contents;
+ file_util::ReadFileToString(temp_file_path(), &read_contents);
+
+ ASSERT_TRUE(read_contents == "01230123");
+}
+
// TODO(erikkay): more READ_WRITE tests?
« no previous file with comments | « net/base/file_stream_posix.cc ('k') | net/base/file_stream_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698