| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 std::wstring file_name_from(dir_name_from); | 510 std::wstring file_name_from(dir_name_from); |
| 511 file_util::AppendToPath(&file_name_from, L"Copy_Test_File.txt"); | 511 file_util::AppendToPath(&file_name_from, L"Copy_Test_File.txt"); |
| 512 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); | 512 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); |
| 513 CreateTextFile(file_name_from, file_contents); | 513 CreateTextFile(file_name_from, file_contents); |
| 514 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 514 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 515 | 515 |
| 516 // Copy the file. | 516 // Copy the file. |
| 517 std::wstring dest_file(dir_name_from); | 517 std::wstring dest_file(dir_name_from); |
| 518 file_util::AppendToPath(&dest_file, L"DestFile.txt"); | 518 file_util::AppendToPath(&dest_file, L"DestFile.txt"); |
| 519 ASSERT_TRUE(file_util::CopyFile(file_name_from, dest_file)); | 519 ASSERT_TRUE(file_util::CopyFile(file_name_from, dest_file)); |
| 520 | 520 |
| 521 // Copy the file to another location using '..' in the path. | 521 // Copy the file to another location using '..' in the path. |
| 522 std::wstring dest_file2(dir_name_from); | 522 std::wstring dest_file2(dir_name_from); |
| 523 file_util::AppendToPath(&dest_file2, L".."); | 523 file_util::AppendToPath(&dest_file2, L".."); |
| 524 file_util::AppendToPath(&dest_file2, L"DestFile.txt"); | 524 file_util::AppendToPath(&dest_file2, L"DestFile.txt"); |
| 525 ASSERT_TRUE(file_util::CopyFile(file_name_from, dest_file2)); | 525 ASSERT_TRUE(file_util::CopyFile(file_name_from, dest_file2)); |
| 526 std::wstring dest_file2_test(dir_name_from); | 526 std::wstring dest_file2_test(dir_name_from); |
| 527 file_util::UpOneDirectory(&dest_file2_test); | 527 file_util::UpOneDirectory(&dest_file2_test); |
| 528 file_util::AppendToPath(&dest_file2_test, L"DestFile.txt"); | 528 file_util::AppendToPath(&dest_file2_test, L"DestFile.txt"); |
| 529 | 529 |
| 530 // Check everything has been copied. | 530 // Check everything has been copied. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 | 690 |
| 691 DeleteFile(target_file.c_str()); | 691 DeleteFile(target_file.c_str()); |
| 692 DeleteFile(link_file.c_str()); | 692 DeleteFile(link_file.c_str()); |
| 693 CoUninitialize(); | 693 CoUninitialize(); |
| 694 } | 694 } |
| 695 #endif | 695 #endif |
| 696 | 696 |
| 697 TEST_F(FileUtilTest, CreateTemporaryFileNameTest) { | 697 TEST_F(FileUtilTest, CreateTemporaryFileNameTest) { |
| 698 std::wstring temp_file; | 698 std::wstring temp_file; |
| 699 file_util::CreateTemporaryFileName(&temp_file); | 699 file_util::CreateTemporaryFileName(&temp_file); |
| 700 EXPECT_EQ(file_util::PathExists(temp_file), true); | 700 EXPECT_TRUE(file_util::PathExists(temp_file)); |
| 701 EXPECT_EQ(file_util::Delete(temp_file, false), true); | 701 EXPECT_TRUE(file_util::Delete(temp_file, false)); |
| 702 } | 702 } |
| 703 | 703 |
| 704 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { | 704 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { |
| 705 std::wstring temp_dir; | 705 std::wstring temp_dir; |
| 706 file_util::CreateNewTempDirectory(std::wstring(), &temp_dir); | 706 file_util::CreateNewTempDirectory(std::wstring(), &temp_dir); |
| 707 EXPECT_EQ(file_util::PathExists(temp_dir), true); | 707 EXPECT_TRUE(file_util::PathExists(temp_dir)); |
| 708 EXPECT_EQ(file_util::Delete(temp_dir, false), true); | 708 EXPECT_TRUE(file_util::Delete(temp_dir, false)); |
| 709 } | 709 } |
| 710 | 710 |
| 711 TEST_F(FileUtilTest, CreateDirectoryTest) { | 711 TEST_F(FileUtilTest, CreateDirectoryTest) { |
| 712 std::wstring test_root = test_dir_; | 712 std::wstring test_root = test_dir_; |
| 713 file_util::AppendToPath(&test_root, L"create_directory_test"); | 713 file_util::AppendToPath(&test_root, L"create_directory_test"); |
| 714 std::wstring test_path(test_root); | 714 std::wstring test_path(test_root); |
| 715 #if defined(OS_WIN) | 715 #if defined(OS_WIN) |
| 716 file_util::AppendToPath(&test_path, L"dir\\tree\\likely\\doesnt\\exist\\"); | 716 file_util::AppendToPath(&test_path, L"dir\\tree\\likely\\doesnt\\exist\\"); |
| 717 #elif defined(OS_POSIX) | 717 #elif defined(OS_POSIX) |
| 718 file_util::AppendToPath(&test_path, L"dir/tree/likely/doesnt/exist/"); | 718 file_util::AppendToPath(&test_path, L"dir/tree/likely/doesnt/exist/"); |
| 719 #endif | 719 #endif |
| 720 | 720 |
| 721 EXPECT_EQ(file_util::PathExists(test_path), false); | 721 EXPECT_FALSE(file_util::PathExists(test_path)); |
| 722 EXPECT_EQ(file_util::CreateDirectory(test_path), true); | 722 EXPECT_TRUE(file_util::CreateDirectory(test_path)); |
| 723 EXPECT_EQ(file_util::PathExists(test_path), true); | 723 EXPECT_TRUE(file_util::PathExists(test_path)); |
| 724 EXPECT_EQ(file_util::Delete(test_root, true), true); | 724 // CreateDirectory returns true if the DirectoryExists returns true. |
| 725 EXPECT_EQ(file_util::PathExists(test_root), false); | 725 EXPECT_TRUE(file_util::CreateDirectory(test_path)); |
| 726 EXPECT_EQ(file_util::PathExists(test_path), false); | 726 |
| 727 // Doesn't work to create it on top of a non-dir |
| 728 file_util::AppendToPath(&test_path, L"foobar.txt"); |
| 729 EXPECT_FALSE(file_util::PathExists(test_path)); |
| 730 CreateTextFile(test_path, L"test file"); |
| 731 EXPECT_TRUE(file_util::PathExists(test_path)); |
| 732 EXPECT_FALSE(file_util::CreateDirectory(test_path)); |
| 733 |
| 734 EXPECT_TRUE(file_util::Delete(test_root, true)); |
| 735 EXPECT_FALSE(file_util::PathExists(test_root)); |
| 736 EXPECT_FALSE(file_util::PathExists(test_path)); |
| 737 } |
| 738 |
| 739 TEST_F(FileUtilTest, DetectDirectoryTest) { |
| 740 // Check a directory |
| 741 std::wstring test_root = test_dir_; |
| 742 file_util::AppendToPath(&test_root, L"detect_directory_test"); |
| 743 EXPECT_FALSE(file_util::PathExists(test_root)); |
| 744 EXPECT_TRUE(file_util::CreateDirectory(test_root)); |
| 745 EXPECT_TRUE(file_util::PathExists(test_root)); |
| 746 EXPECT_TRUE(file_util::DirectoryExists(test_root)); |
| 747 |
| 748 // Check a file |
| 749 std::wstring test_path(test_root); |
| 750 file_util::AppendToPath(&test_path, L"foobar.txt"); |
| 751 EXPECT_FALSE(file_util::PathExists(test_path)); |
| 752 CreateTextFile(test_path, L"test file"); |
| 753 EXPECT_TRUE(file_util::PathExists(test_path)); |
| 754 EXPECT_FALSE(file_util::DirectoryExists(test_path)); |
| 755 EXPECT_TRUE(file_util::Delete(test_path, false)); |
| 756 |
| 757 EXPECT_TRUE(file_util::Delete(test_root, true)); |
| 727 } | 758 } |
| 728 | 759 |
| 729 static const struct goodbad_pair { | 760 static const struct goodbad_pair { |
| 730 std::wstring bad_name; | 761 std::wstring bad_name; |
| 731 std::wstring good_name; | 762 std::wstring good_name; |
| 732 } kIllegalCharacterCases[] = { | 763 } kIllegalCharacterCases[] = { |
| 733 {L"bad*file:name?.jpg", L"bad-file-name-.jpg"}, | 764 {L"bad*file:name?.jpg", L"bad-file-name-.jpg"}, |
| 734 {L"**********::::.txt", L"--------------.txt"}, | 765 {L"**********::::.txt", L"--------------.txt"}, |
| 735 // We can't use UCNs (universal character names) for C0/C1 characters and | 766 // We can't use UCNs (universal character names) for C0/C1 characters and |
| 736 // U+007F, but \x escape is interpreted by MSVC and gcc as we intend. | 767 // U+007F, but \x escape is interpreted by MSVC and gcc as we intend. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 | 912 |
| 882 // Make sure the destructor closes the find handle while in the middle of a | 913 // Make sure the destructor closes the find handle while in the middle of a |
| 883 // query to allow TearDown to delete the directory. | 914 // query to allow TearDown to delete the directory. |
| 884 file_util::FileEnumerator f6(test_dir_, true, | 915 file_util::FileEnumerator f6(test_dir_, true, |
| 885 file_util::FileEnumerator::FILES_AND_DIRECTORIES); | 916 file_util::FileEnumerator::FILES_AND_DIRECTORIES); |
| 886 EXPECT_FALSE(f6.Next().empty()); // Should have found something | 917 EXPECT_FALSE(f6.Next().empty()); // Should have found something |
| 887 // (we don't care what). | 918 // (we don't care what). |
| 888 } | 919 } |
| 889 | 920 |
| 890 } // namespace | 921 } // namespace |
| OLD | NEW |