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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/file_stream_posix.cc ('k') | net/base/file_stream_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/platform_file.h" 7 #include "base/platform_file.h"
8 #include "net/base/file_stream.h" 8 #include "net/base/file_stream.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/base/test_completion_callback.h" 10 #include "net/base/test_completion_callback.h"
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 399
400 rv = stream.Write(kTestData, kTestDataSize, NULL); 400 rv = stream.Write(kTestData, kTestDataSize, NULL);
401 EXPECT_EQ(kTestDataSize, rv); 401 EXPECT_EQ(kTestDataSize, rv);
402 stream.Close(); 402 stream.Close();
403 403
404 ok = file_util::GetFileSize(temp_file_path(), &file_size); 404 ok = file_util::GetFileSize(temp_file_path(), &file_size);
405 EXPECT_TRUE(ok); 405 EXPECT_TRUE(ok);
406 EXPECT_EQ(kTestDataSize * 2, file_size); 406 EXPECT_EQ(kTestDataSize * 2, file_size);
407 } 407 }
408 408
409 // Tests truncating a file.
410 TEST_F(FileStreamTest, Truncate) {
411 int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE;
412
413 net::FileStream write_stream;
414 ASSERT_EQ(net::OK, write_stream.Open(temp_file_path(), flags));
415
416 // Write some data to the file.
417 const char test_data[] = "0123456789";
418 write_stream.Write(test_data, arraysize(test_data), NULL);
419
420 // Truncate the file.
421 ASSERT_EQ(4, write_stream.Truncate(4));
422
423 // Write again.
424 write_stream.Write(test_data, 4, NULL);
425
426 // Close the stream.
427 write_stream.Close();
428
429 // Read in the contents and make sure we get back what we expected.
430 std::string read_contents;
431 file_util::ReadFileToString(temp_file_path(), &read_contents);
432
433 ASSERT_TRUE(read_contents == "01230123");
434 }
435
409 // TODO(erikkay): more READ_WRITE tests? 436 // TODO(erikkay): more READ_WRITE tests?
OLDNEW
« 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