| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (!DeviceIoControl(source, FSCTL_DELETE_REPARSE_POINT, &data, 8, NULL, 0, | 105 if (!DeviceIoControl(source, FSCTL_DELETE_REPARSE_POINT, &data, 8, NULL, 0, |
| 106 &returned, NULL)) { | 106 &returned, NULL)) { |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 return true; | 109 return true; |
| 110 } | 110 } |
| 111 #endif | 111 #endif |
| 112 | 112 |
| 113 const wchar_t bogus_content[] = L"I'm cannon fodder."; | 113 const wchar_t bogus_content[] = L"I'm cannon fodder."; |
| 114 | 114 |
| 115 const file_util::FileEnumerator::FILE_TYPE FILES_AND_DIRECTORIES = | 115 const file_util::FileEnumerator::FileType FILES_AND_DIRECTORIES = |
| 116 static_cast<file_util::FileEnumerator::FILE_TYPE>( | 116 static_cast<file_util::FileEnumerator::FileType>( |
| 117 file_util::FileEnumerator::FILES | | 117 file_util::FileEnumerator::FILES | |
| 118 file_util::FileEnumerator::DIRECTORIES); | 118 file_util::FileEnumerator::DIRECTORIES); |
| 119 | 119 |
| 120 // file_util winds up using autoreleased objects on the Mac, so this needs | 120 // file_util winds up using autoreleased objects on the Mac, so this needs |
| 121 // to be a PlatformTest | 121 // to be a PlatformTest |
| 122 class FileUtilTest : public PlatformTest { | 122 class FileUtilTest : public PlatformTest { |
| 123 protected: | 123 protected: |
| 124 virtual void SetUp() { | 124 virtual void SetUp() { |
| 125 PlatformTest::SetUp(); | 125 PlatformTest::SetUp(); |
| 126 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 126 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| (...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1604 } | 1604 } |
| 1605 | 1605 |
| 1606 TEST_F(FileUtilTest, FileEnumeratorTest) { | 1606 TEST_F(FileUtilTest, FileEnumeratorTest) { |
| 1607 // Test an empty directory. | 1607 // Test an empty directory. |
| 1608 file_util::FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1608 file_util::FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
| 1609 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); | 1609 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); |
| 1610 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); | 1610 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); |
| 1611 | 1611 |
| 1612 // Test an empty directory, non-recursively, including "..". | 1612 // Test an empty directory, non-recursively, including "..". |
| 1613 file_util::FileEnumerator f0_dotdot(temp_dir_.path(), false, | 1613 file_util::FileEnumerator f0_dotdot(temp_dir_.path(), false, |
| 1614 static_cast<file_util::FileEnumerator::FILE_TYPE>( | 1614 static_cast<file_util::FileEnumerator::FileType>( |
| 1615 FILES_AND_DIRECTORIES | file_util::FileEnumerator::INCLUDE_DOT_DOT)); | 1615 FILES_AND_DIRECTORIES | file_util::FileEnumerator::INCLUDE_DOT_DOT)); |
| 1616 EXPECT_EQ(temp_dir_.path().Append(FILE_PATH_LITERAL("..")).value(), | 1616 EXPECT_EQ(temp_dir_.path().Append(FILE_PATH_LITERAL("..")).value(), |
| 1617 f0_dotdot.Next().value()); | 1617 f0_dotdot.Next().value()); |
| 1618 EXPECT_EQ(FILE_PATH_LITERAL(""), | 1618 EXPECT_EQ(FILE_PATH_LITERAL(""), |
| 1619 f0_dotdot.Next().value()); | 1619 f0_dotdot.Next().value()); |
| 1620 | 1620 |
| 1621 // create the directories | 1621 // create the directories |
| 1622 FilePath dir1 = temp_dir_.path().Append(FILE_PATH_LITERAL("dir1")); | 1622 FilePath dir1 = temp_dir_.path().Append(FILE_PATH_LITERAL("dir1")); |
| 1623 EXPECT_TRUE(file_util::CreateDirectory(dir1)); | 1623 EXPECT_TRUE(file_util::CreateDirectory(dir1)); |
| 1624 FilePath dir2 = temp_dir_.path().Append(FILE_PATH_LITERAL("dir2")); | 1624 FilePath dir2 = temp_dir_.path().Append(FILE_PATH_LITERAL("dir2")); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1662 file_util::FileEnumerator f2_non_recursive( | 1662 file_util::FileEnumerator f2_non_recursive( |
| 1663 temp_dir_.path(), false, file_util::FileEnumerator::DIRECTORIES); | 1663 temp_dir_.path(), false, file_util::FileEnumerator::DIRECTORIES); |
| 1664 FindResultCollector c2_non_recursive(f2_non_recursive); | 1664 FindResultCollector c2_non_recursive(f2_non_recursive); |
| 1665 EXPECT_TRUE(c2_non_recursive.HasFile(dir1)); | 1665 EXPECT_TRUE(c2_non_recursive.HasFile(dir1)); |
| 1666 EXPECT_TRUE(c2_non_recursive.HasFile(dir2)); | 1666 EXPECT_TRUE(c2_non_recursive.HasFile(dir2)); |
| 1667 EXPECT_EQ(c2_non_recursive.size(), 2); | 1667 EXPECT_EQ(c2_non_recursive.size(), 2); |
| 1668 | 1668 |
| 1669 // Only enumerate directories, non-recursively, including "..". | 1669 // Only enumerate directories, non-recursively, including "..". |
| 1670 file_util::FileEnumerator f2_dotdot( | 1670 file_util::FileEnumerator f2_dotdot( |
| 1671 temp_dir_.path(), false, | 1671 temp_dir_.path(), false, |
| 1672 static_cast<file_util::FileEnumerator::FILE_TYPE>( | 1672 static_cast<file_util::FileEnumerator::FileType>( |
| 1673 file_util::FileEnumerator::DIRECTORIES | | 1673 file_util::FileEnumerator::DIRECTORIES | |
| 1674 file_util::FileEnumerator::INCLUDE_DOT_DOT)); | 1674 file_util::FileEnumerator::INCLUDE_DOT_DOT)); |
| 1675 FindResultCollector c2_dotdot(f2_dotdot); | 1675 FindResultCollector c2_dotdot(f2_dotdot); |
| 1676 EXPECT_TRUE(c2_dotdot.HasFile(dir1)); | 1676 EXPECT_TRUE(c2_dotdot.HasFile(dir1)); |
| 1677 EXPECT_TRUE(c2_dotdot.HasFile(dir2)); | 1677 EXPECT_TRUE(c2_dotdot.HasFile(dir2)); |
| 1678 EXPECT_TRUE(c2_dotdot.HasFile( | 1678 EXPECT_TRUE(c2_dotdot.HasFile( |
| 1679 temp_dir_.path().Append(FILE_PATH_LITERAL("..")))); | 1679 temp_dir_.path().Append(FILE_PATH_LITERAL("..")))); |
| 1680 EXPECT_EQ(c2_dotdot.size(), 3); | 1680 EXPECT_EQ(c2_dotdot.size(), 3); |
| 1681 | 1681 |
| 1682 // Enumerate files and directories. | 1682 // Enumerate files and directories. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1807 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); | 1807 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); |
| 1808 | 1808 |
| 1809 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 1809 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
| 1810 std::string bar("baz"); | 1810 std::string bar("baz"); |
| 1811 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); | 1811 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); |
| 1812 | 1812 |
| 1813 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); | 1813 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); |
| 1814 } | 1814 } |
| 1815 | 1815 |
| 1816 } // namespace | 1816 } // namespace |
| OLD | NEW |