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

Unified Diff: base/file_util_unittest.cc

Issue 269083: More CopyDirectory tests and fixes... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | « base/file_util_posix.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_unittest.cc
===================================================================
--- base/file_util_unittest.cc (revision 28902)
+++ base/file_util_unittest.cc (working copy)
@@ -380,6 +380,63 @@
EXPECT_FALSE(file_util::PathExists(subdir_path));
}
+TEST_F(FileUtilTest, MoveFileNew) {
+ // Create a file
+ FilePath file_name_from =
+ test_dir_.Append(FILE_PATH_LITERAL("Move_Test_File.txt"));
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
+ ASSERT_TRUE(file_util::PathExists(file_name_from));
+
+ // The destination
+ FilePath file_name_to =
+ test_dir_.Append(FILE_PATH_LITERAL("Move_Test_File_Destination.txt"));
+ ASSERT_FALSE(file_util::PathExists(file_name_to));
+
+ EXPECT_TRUE(file_util::Move(file_name_from, file_name_to));
+
+ // Check everything has been moved.
+ EXPECT_FALSE(file_util::PathExists(file_name_from));
+ EXPECT_TRUE(file_util::PathExists(file_name_to));
+}
+
+TEST_F(FileUtilTest, MoveFileExists) {
+ // Create a file
+ FilePath file_name_from =
+ test_dir_.Append(FILE_PATH_LITERAL("Move_Test_File.txt"));
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
+ ASSERT_TRUE(file_util::PathExists(file_name_from));
+
+ // The destination name
+ FilePath file_name_to =
+ test_dir_.Append(FILE_PATH_LITERAL("Move_Test_File_Destination.txt"));
+ CreateTextFile(file_name_to, L"Old file content");
+ ASSERT_TRUE(file_util::PathExists(file_name_to));
+
+ EXPECT_TRUE(file_util::Move(file_name_from, file_name_to));
+
+ // Check everything has been moved.
+ EXPECT_FALSE(file_util::PathExists(file_name_from));
+ EXPECT_TRUE(file_util::PathExists(file_name_to));
+ EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to));
+}
+
+TEST_F(FileUtilTest, MoveFileDirExists) {
+ // Create a file
+ FilePath file_name_from =
+ test_dir_.Append(FILE_PATH_LITERAL("Move_Test_File.txt"));
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
+ ASSERT_TRUE(file_util::PathExists(file_name_from));
+
+ // The destination directory
+ FilePath dir_name_to =
+ test_dir_.Append(FILE_PATH_LITERAL("Destination"));
+ file_util::CreateDirectory(dir_name_to);
+ ASSERT_TRUE(file_util::PathExists(dir_name_to));
+
+ EXPECT_FALSE(file_util::Move(file_name_from, dir_name_to));
+}
+
+
TEST_F(FileUtilTest, MoveNew) {
// Create a directory
FilePath dir_name_from =
@@ -645,6 +702,65 @@
EXPECT_FALSE(file_util::PathExists(subdir_name_to));
}
+TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) {
+ // Create a file
+ FilePath file_name_from =
+ test_dir_.Append(FILE_PATH_LITERAL("Copy_Test_File.txt"));
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
+ ASSERT_TRUE(file_util::PathExists(file_name_from));
+
+ // The destination name
+ FilePath file_name_to =
+ test_dir_.Append(FILE_PATH_LITERAL("Copy_Test_File_Destination.txt"));
+ ASSERT_FALSE(file_util::PathExists(file_name_to));
+
+ EXPECT_TRUE(file_util::CopyDirectory(file_name_from, file_name_to, true));
+
+ // Check the has been copied
+ EXPECT_TRUE(file_util::PathExists(file_name_to));
+}
+
+TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) {
+ // Create a file
+ FilePath file_name_from =
+ test_dir_.Append(FILE_PATH_LITERAL("Copy_Test_File.txt"));
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
+ ASSERT_TRUE(file_util::PathExists(file_name_from));
+
+ // The destination name
+ FilePath file_name_to =
+ test_dir_.Append(FILE_PATH_LITERAL("Copy_Test_File_Destination.txt"));
+ CreateTextFile(file_name_to, L"Old file content");
+ ASSERT_TRUE(file_util::PathExists(file_name_to));
+
+ EXPECT_TRUE(file_util::CopyDirectory(file_name_from, file_name_to, true));
+
+ // Check the has been copied
+ EXPECT_TRUE(file_util::PathExists(file_name_to));
+ EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to));
+}
+
+TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) {
+ // Create a file
+ FilePath file_name_from =
+ test_dir_.Append(FILE_PATH_LITERAL("Copy_Test_File.txt"));
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
+ ASSERT_TRUE(file_util::PathExists(file_name_from));
+
+ // The destination
+ FilePath dir_name_to =
+ test_dir_.Append(FILE_PATH_LITERAL("Destination"));
+ file_util::CreateDirectory(dir_name_to);
+ ASSERT_TRUE(file_util::PathExists(dir_name_to));
+ FilePath file_name_to =
+ dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt"));
+
+ EXPECT_TRUE(file_util::CopyDirectory(file_name_from, dir_name_to, true));
+
+ // Check the has been copied
+ EXPECT_TRUE(file_util::PathExists(file_name_to));
+}
+
TEST_F(FileUtilTest, CopyFile) {
// Create a directory
FilePath dir_name_from =
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698