| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <winioctl.h> | 9 #include <winioctl.h> |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 // Test recursive case, create a new file | 685 // Test recursive case, create a new file |
| 686 file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); | 686 file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); |
| 687 CreateTextFile(file_name, bogus_content); | 687 CreateTextFile(file_name, bogus_content); |
| 688 ASSERT_TRUE(file_util::PathExists(file_name)); | 688 ASSERT_TRUE(file_util::PathExists(file_name)); |
| 689 | 689 |
| 690 // Make sure it's deleted | 690 // Make sure it's deleted |
| 691 EXPECT_TRUE(file_util::Delete(file_name, true)); | 691 EXPECT_TRUE(file_util::Delete(file_name, true)); |
| 692 EXPECT_FALSE(file_util::PathExists(file_name)); | 692 EXPECT_FALSE(file_util::PathExists(file_name)); |
| 693 } | 693 } |
| 694 | 694 |
| 695 #if defined(OS_WIN) | |
| 696 // Tests that the Delete function works for wild cards, especially | |
| 697 // with the recursion flag. Also coincidentally tests PathExists. | |
| 698 // TODO(erikkay): see if anyone's actually using this feature of the API | |
| 699 TEST_F(FileUtilTest, DeleteWildCard) { | |
| 700 // Create a file and a directory | |
| 701 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); | |
| 702 CreateTextFile(file_name, bogus_content); | |
| 703 ASSERT_TRUE(file_util::PathExists(file_name)); | |
| 704 | |
| 705 FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir")); | |
| 706 file_util::CreateDirectory(subdir_path); | |
| 707 ASSERT_TRUE(file_util::PathExists(subdir_path)); | |
| 708 | |
| 709 // Create the wildcard path | |
| 710 FilePath directory_contents = temp_dir_.path(); | |
| 711 directory_contents = directory_contents.Append(FPL("*")); | |
| 712 | |
| 713 // Delete non-recursively and check that only the file is deleted | |
| 714 EXPECT_TRUE(file_util::Delete(directory_contents, false)); | |
| 715 EXPECT_FALSE(file_util::PathExists(file_name)); | |
| 716 EXPECT_TRUE(file_util::PathExists(subdir_path)); | |
| 717 | |
| 718 // Delete recursively and make sure all contents are deleted | |
| 719 EXPECT_TRUE(file_util::Delete(directory_contents, true)); | |
| 720 EXPECT_FALSE(file_util::PathExists(file_name)); | |
| 721 EXPECT_FALSE(file_util::PathExists(subdir_path)); | |
| 722 } | |
| 723 | |
| 724 // TODO(erikkay): see if anyone's actually using this feature of the API | |
| 725 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { | |
| 726 // Create a file and a directory | |
| 727 FilePath subdir_path = | |
| 728 temp_dir_.path().Append(FPL("DeleteNonExistantWildCard")); | |
| 729 file_util::CreateDirectory(subdir_path); | |
| 730 ASSERT_TRUE(file_util::PathExists(subdir_path)); | |
| 731 | |
| 732 // Create the wildcard path | |
| 733 FilePath directory_contents = subdir_path; | |
| 734 directory_contents = directory_contents.Append(FPL("*")); | |
| 735 | |
| 736 // Delete non-recursively and check nothing got deleted | |
| 737 EXPECT_TRUE(file_util::Delete(directory_contents, false)); | |
| 738 EXPECT_TRUE(file_util::PathExists(subdir_path)); | |
| 739 | |
| 740 // Delete recursively and check nothing got deleted | |
| 741 EXPECT_TRUE(file_util::Delete(directory_contents, true)); | |
| 742 EXPECT_TRUE(file_util::PathExists(subdir_path)); | |
| 743 } | |
| 744 #endif | |
| 745 | |
| 746 // Tests non-recursive Delete() for a directory. | 695 // Tests non-recursive Delete() for a directory. |
| 747 TEST_F(FileUtilTest, DeleteDirNonRecursive) { | 696 TEST_F(FileUtilTest, DeleteDirNonRecursive) { |
| 748 // Create a subdirectory and put a file and two directories inside. | 697 // Create a subdirectory and put a file and two directories inside. |
| 749 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); | 698 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); |
| 750 file_util::CreateDirectory(test_subdir); | 699 file_util::CreateDirectory(test_subdir); |
| 751 ASSERT_TRUE(file_util::PathExists(test_subdir)); | 700 ASSERT_TRUE(file_util::PathExists(test_subdir)); |
| 752 | 701 |
| 753 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); | 702 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); |
| 754 CreateTextFile(file_name, bogus_content); | 703 CreateTextFile(file_name, bogus_content); |
| 755 ASSERT_TRUE(file_util::PathExists(file_name)); | 704 ASSERT_TRUE(file_util::PathExists(file_name)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 781 ASSERT_TRUE(file_util::PathExists(test_subdir)); | 730 ASSERT_TRUE(file_util::PathExists(test_subdir)); |
| 782 | 731 |
| 783 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); | 732 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); |
| 784 CreateTextFile(file_name, bogus_content); | 733 CreateTextFile(file_name, bogus_content); |
| 785 ASSERT_TRUE(file_util::PathExists(file_name)); | 734 ASSERT_TRUE(file_util::PathExists(file_name)); |
| 786 | 735 |
| 787 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 736 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
| 788 file_util::CreateDirectory(subdir_path1); | 737 file_util::CreateDirectory(subdir_path1); |
| 789 ASSERT_TRUE(file_util::PathExists(subdir_path1)); | 738 ASSERT_TRUE(file_util::PathExists(subdir_path1)); |
| 790 | 739 |
| 740 FilePath sub_subdir_path1 = subdir_path1.Append(FPL("TestSubSubDir1")); |
| 741 file_util::CreateDirectory(sub_subdir_path1); |
| 742 ASSERT_TRUE(file_util::PathExists(sub_subdir_path1)); |
| 743 |
| 744 FilePath subdir_file_name = |
| 745 sub_subdir_path1.Append(FPL("DeleteDirRecursiveSubDir.txt")); |
| 746 CreateTextFile(subdir_file_name, bogus_content); |
| 747 ASSERT_TRUE(file_util::PathExists(subdir_file_name)); |
| 748 |
| 791 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 749 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
| 792 file_util::CreateDirectory(subdir_path2); | 750 file_util::CreateDirectory(subdir_path2); |
| 793 ASSERT_TRUE(file_util::PathExists(subdir_path2)); | 751 ASSERT_TRUE(file_util::PathExists(subdir_path2)); |
| 794 | 752 |
| 795 // Delete recursively and check that the empty dir got deleted | 753 // Delete recursively and check that the empty dir got deleted |
| 796 EXPECT_TRUE(file_util::Delete(subdir_path2, true)); | 754 EXPECT_TRUE(file_util::Delete(subdir_path2, true)); |
| 797 EXPECT_FALSE(file_util::PathExists(subdir_path2)); | 755 EXPECT_FALSE(file_util::PathExists(subdir_path2)); |
| 798 | 756 |
| 799 // Delete recursively and check that everything got deleted | 757 // Delete recursively and check that everything got deleted |
| 800 EXPECT_TRUE(file_util::Delete(test_subdir, true)); | 758 EXPECT_TRUE(file_util::Delete(test_subdir, true)); |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1827 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); | 1785 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); |
| 1828 | 1786 |
| 1829 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 1787 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
| 1830 std::string bar("baz"); | 1788 std::string bar("baz"); |
| 1831 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); | 1789 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); |
| 1832 | 1790 |
| 1833 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); | 1791 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); |
| 1834 } | 1792 } |
| 1835 | 1793 |
| 1836 } // namespace | 1794 } // namespace |
| OLD | NEW |