diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 01:11:44 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 01:11:44 +0000 |
commit | bc6a901f7d54c1307fcffc82181aedcf694470f7 (patch) | |
tree | b24e0d6fb40364b695d95291cd4bf0f134f47afa /base/file_util_unittest.cc | |
parent | 3c5edd42af2fab481784f122d00d75a2c28661b7 (diff) | |
download | chromium_src-bc6a901f7d54c1307fcffc82181aedcf694470f7.zip chromium_src-bc6a901f7d54c1307fcffc82181aedcf694470f7.tar.gz chromium_src-bc6a901f7d54c1307fcffc82181aedcf694470f7.tar.bz2 |
More CopyDirectory tests and fixes
BUG=themes stopped working on Linux and Mac
TEST=unittests
Review URL: http://codereview.chromium.org/269083
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29076 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_unittest.cc')
-rw-r--r-- | base/file_util_unittest.cc | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index 6ac55f6..cde98a0 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -380,6 +380,63 @@ TEST_F(FileUtilTest, Delete) { 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 @@ TEST_F(FileUtilTest, CopyDirectoryExists) { 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 = |