OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 | 798 |
799 // Get rid of the permissions from the directory. | 799 // Get rid of the permissions from the directory. |
800 EXPECT_TRUE(SetPosixFilePermissions(subdir_path, 0u)); | 800 EXPECT_TRUE(SetPosixFilePermissions(subdir_path, 0u)); |
801 EXPECT_TRUE(GetPosixFilePermissions(subdir_path, &mode)); | 801 EXPECT_TRUE(GetPosixFilePermissions(subdir_path, &mode)); |
802 EXPECT_FALSE(mode & FILE_PERMISSION_USER_MASK); | 802 EXPECT_FALSE(mode & FILE_PERMISSION_USER_MASK); |
803 | 803 |
804 // Make sure the file in the directory can't be enumerated. | 804 // Make sure the file in the directory can't be enumerated. |
805 FileEnumerator f1(subdir_path, true, FileEnumerator::FILES); | 805 FileEnumerator f1(subdir_path, true, FileEnumerator::FILES); |
806 EXPECT_TRUE(PathExists(subdir_path)); | 806 EXPECT_TRUE(PathExists(subdir_path)); |
807 FindResultCollector c1(f1); | 807 FindResultCollector c1(f1); |
808 EXPECT_EQ(c1.size(), 0); | 808 EXPECT_EQ(0, c1.size()); |
809 EXPECT_FALSE(GetPosixFilePermissions(file_name, &mode)); | 809 EXPECT_FALSE(GetPosixFilePermissions(file_name, &mode)); |
810 | 810 |
811 // Give the permissions to the directory. | 811 // Give the permissions to the directory. |
812 EXPECT_TRUE(SetPosixFilePermissions(subdir_path, FILE_PERMISSION_USER_MASK)); | 812 EXPECT_TRUE(SetPosixFilePermissions(subdir_path, FILE_PERMISSION_USER_MASK)); |
813 EXPECT_TRUE(GetPosixFilePermissions(subdir_path, &mode)); | 813 EXPECT_TRUE(GetPosixFilePermissions(subdir_path, &mode)); |
814 EXPECT_EQ(FILE_PERMISSION_USER_MASK, mode & FILE_PERMISSION_USER_MASK); | 814 EXPECT_EQ(FILE_PERMISSION_USER_MASK, mode & FILE_PERMISSION_USER_MASK); |
815 | 815 |
816 // Make sure the file in the directory can be enumerated. | 816 // Make sure the file in the directory can be enumerated. |
817 FileEnumerator f2(subdir_path, true, FileEnumerator::FILES); | 817 FileEnumerator f2(subdir_path, true, FileEnumerator::FILES); |
818 FindResultCollector c2(f2); | 818 FindResultCollector c2(f2); |
819 EXPECT_TRUE(c2.HasFile(file_name)); | 819 EXPECT_TRUE(c2.HasFile(file_name)); |
820 EXPECT_EQ(c2.size(), 1); | 820 EXPECT_EQ(1, c2.size()); |
821 | 821 |
822 // Delete the file. | 822 // Delete the file. |
823 EXPECT_TRUE(DeleteFile(subdir_path, true)); | 823 EXPECT_TRUE(DeleteFile(subdir_path, true)); |
824 EXPECT_FALSE(PathExists(subdir_path)); | 824 EXPECT_FALSE(PathExists(subdir_path)); |
825 } | 825 } |
826 | 826 |
827 #endif // defined(OS_POSIX) | 827 #endif // defined(OS_POSIX) |
828 | 828 |
829 #if defined(OS_WIN) | 829 #if defined(OS_WIN) |
830 // Tests that the Delete function works for wild cards, especially | 830 // Tests that the Delete function works for wild cards, especially |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1781 EXPECT_TRUE(PathExists(test_path)); | 1781 EXPECT_TRUE(PathExists(test_path)); |
1782 EXPECT_FALSE(DirectoryExists(test_path)); | 1782 EXPECT_FALSE(DirectoryExists(test_path)); |
1783 EXPECT_TRUE(DeleteFile(test_path, false)); | 1783 EXPECT_TRUE(DeleteFile(test_path, false)); |
1784 | 1784 |
1785 EXPECT_TRUE(DeleteFile(test_root, true)); | 1785 EXPECT_TRUE(DeleteFile(test_root, true)); |
1786 } | 1786 } |
1787 | 1787 |
1788 TEST_F(FileUtilTest, FileEnumeratorTest) { | 1788 TEST_F(FileUtilTest, FileEnumeratorTest) { |
1789 // Test an empty directory. | 1789 // Test an empty directory. |
1790 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1790 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
1791 EXPECT_EQ(f0.Next().value(), FPL("")); | 1791 EXPECT_EQ(FPL(""), f0.Next().value()); |
1792 EXPECT_EQ(f0.Next().value(), FPL("")); | 1792 EXPECT_EQ(FPL(""), f0.Next().value()); |
1793 | 1793 |
1794 // Test an empty directory, non-recursively, including "..". | 1794 // Test an empty directory, non-recursively, including "..". |
1795 FileEnumerator f0_dotdot(temp_dir_.path(), false, | 1795 FileEnumerator f0_dotdot(temp_dir_.path(), false, |
1796 FILES_AND_DIRECTORIES | FileEnumerator::INCLUDE_DOT_DOT); | 1796 FILES_AND_DIRECTORIES | FileEnumerator::INCLUDE_DOT_DOT); |
1797 EXPECT_EQ(temp_dir_.path().Append(FPL("..")).value(), | 1797 EXPECT_EQ(temp_dir_.path().Append(FPL("..")).value(), |
1798 f0_dotdot.Next().value()); | 1798 f0_dotdot.Next().value()); |
1799 EXPECT_EQ(FPL(""), f0_dotdot.Next().value()); | 1799 EXPECT_EQ(FPL(""), f0_dotdot.Next().value()); |
1800 | 1800 |
1801 // create the directories | 1801 // create the directories |
1802 FilePath dir1 = temp_dir_.path().Append(FPL("dir1")); | 1802 FilePath dir1 = temp_dir_.path().Append(FPL("dir1")); |
(...skipping 15 matching lines...) Expand all Loading... |
1818 CreateTextFile(file2_rel, std::wstring()); | 1818 CreateTextFile(file2_rel, std::wstring()); |
1819 FilePath file2_abs = temp_dir_.path().Append(FPL("file2.txt")); | 1819 FilePath file2_abs = temp_dir_.path().Append(FPL("file2.txt")); |
1820 | 1820 |
1821 // Only enumerate files. | 1821 // Only enumerate files. |
1822 FileEnumerator f1(temp_dir_.path(), true, FileEnumerator::FILES); | 1822 FileEnumerator f1(temp_dir_.path(), true, FileEnumerator::FILES); |
1823 FindResultCollector c1(f1); | 1823 FindResultCollector c1(f1); |
1824 EXPECT_TRUE(c1.HasFile(file1)); | 1824 EXPECT_TRUE(c1.HasFile(file1)); |
1825 EXPECT_TRUE(c1.HasFile(file2_abs)); | 1825 EXPECT_TRUE(c1.HasFile(file2_abs)); |
1826 EXPECT_TRUE(c1.HasFile(dir2file)); | 1826 EXPECT_TRUE(c1.HasFile(dir2file)); |
1827 EXPECT_TRUE(c1.HasFile(dir2innerfile)); | 1827 EXPECT_TRUE(c1.HasFile(dir2innerfile)); |
1828 EXPECT_EQ(c1.size(), 4); | 1828 EXPECT_EQ(4, c1.size()); |
1829 | 1829 |
1830 // Only enumerate directories. | 1830 // Only enumerate directories. |
1831 FileEnumerator f2(temp_dir_.path(), true, FileEnumerator::DIRECTORIES); | 1831 FileEnumerator f2(temp_dir_.path(), true, FileEnumerator::DIRECTORIES); |
1832 FindResultCollector c2(f2); | 1832 FindResultCollector c2(f2); |
1833 EXPECT_TRUE(c2.HasFile(dir1)); | 1833 EXPECT_TRUE(c2.HasFile(dir1)); |
1834 EXPECT_TRUE(c2.HasFile(dir2)); | 1834 EXPECT_TRUE(c2.HasFile(dir2)); |
1835 EXPECT_TRUE(c2.HasFile(dir2inner)); | 1835 EXPECT_TRUE(c2.HasFile(dir2inner)); |
1836 EXPECT_EQ(c2.size(), 3); | 1836 EXPECT_EQ(3, c2.size()); |
1837 | 1837 |
1838 // Only enumerate directories non-recursively. | 1838 // Only enumerate directories non-recursively. |
1839 FileEnumerator f2_non_recursive( | 1839 FileEnumerator f2_non_recursive( |
1840 temp_dir_.path(), false, FileEnumerator::DIRECTORIES); | 1840 temp_dir_.path(), false, FileEnumerator::DIRECTORIES); |
1841 FindResultCollector c2_non_recursive(f2_non_recursive); | 1841 FindResultCollector c2_non_recursive(f2_non_recursive); |
1842 EXPECT_TRUE(c2_non_recursive.HasFile(dir1)); | 1842 EXPECT_TRUE(c2_non_recursive.HasFile(dir1)); |
1843 EXPECT_TRUE(c2_non_recursive.HasFile(dir2)); | 1843 EXPECT_TRUE(c2_non_recursive.HasFile(dir2)); |
1844 EXPECT_EQ(c2_non_recursive.size(), 2); | 1844 EXPECT_EQ(2, c2_non_recursive.size()); |
1845 | 1845 |
1846 // Only enumerate directories, non-recursively, including "..". | 1846 // Only enumerate directories, non-recursively, including "..". |
1847 FileEnumerator f2_dotdot(temp_dir_.path(), false, | 1847 FileEnumerator f2_dotdot(temp_dir_.path(), false, |
1848 FileEnumerator::DIRECTORIES | | 1848 FileEnumerator::DIRECTORIES | |
1849 FileEnumerator::INCLUDE_DOT_DOT); | 1849 FileEnumerator::INCLUDE_DOT_DOT); |
1850 FindResultCollector c2_dotdot(f2_dotdot); | 1850 FindResultCollector c2_dotdot(f2_dotdot); |
1851 EXPECT_TRUE(c2_dotdot.HasFile(dir1)); | 1851 EXPECT_TRUE(c2_dotdot.HasFile(dir1)); |
1852 EXPECT_TRUE(c2_dotdot.HasFile(dir2)); | 1852 EXPECT_TRUE(c2_dotdot.HasFile(dir2)); |
1853 EXPECT_TRUE(c2_dotdot.HasFile(temp_dir_.path().Append(FPL("..")))); | 1853 EXPECT_TRUE(c2_dotdot.HasFile(temp_dir_.path().Append(FPL("..")))); |
1854 EXPECT_EQ(c2_dotdot.size(), 3); | 1854 EXPECT_EQ(3, c2_dotdot.size()); |
1855 | 1855 |
1856 // Enumerate files and directories. | 1856 // Enumerate files and directories. |
1857 FileEnumerator f3(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1857 FileEnumerator f3(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
1858 FindResultCollector c3(f3); | 1858 FindResultCollector c3(f3); |
1859 EXPECT_TRUE(c3.HasFile(dir1)); | 1859 EXPECT_TRUE(c3.HasFile(dir1)); |
1860 EXPECT_TRUE(c3.HasFile(dir2)); | 1860 EXPECT_TRUE(c3.HasFile(dir2)); |
1861 EXPECT_TRUE(c3.HasFile(file1)); | 1861 EXPECT_TRUE(c3.HasFile(file1)); |
1862 EXPECT_TRUE(c3.HasFile(file2_abs)); | 1862 EXPECT_TRUE(c3.HasFile(file2_abs)); |
1863 EXPECT_TRUE(c3.HasFile(dir2file)); | 1863 EXPECT_TRUE(c3.HasFile(dir2file)); |
1864 EXPECT_TRUE(c3.HasFile(dir2inner)); | 1864 EXPECT_TRUE(c3.HasFile(dir2inner)); |
1865 EXPECT_TRUE(c3.HasFile(dir2innerfile)); | 1865 EXPECT_TRUE(c3.HasFile(dir2innerfile)); |
1866 EXPECT_EQ(c3.size(), 7); | 1866 EXPECT_EQ(7, c3.size()); |
1867 | 1867 |
1868 // Non-recursive operation. | 1868 // Non-recursive operation. |
1869 FileEnumerator f4(temp_dir_.path(), false, FILES_AND_DIRECTORIES); | 1869 FileEnumerator f4(temp_dir_.path(), false, FILES_AND_DIRECTORIES); |
1870 FindResultCollector c4(f4); | 1870 FindResultCollector c4(f4); |
1871 EXPECT_TRUE(c4.HasFile(dir2)); | 1871 EXPECT_TRUE(c4.HasFile(dir2)); |
1872 EXPECT_TRUE(c4.HasFile(dir2)); | 1872 EXPECT_TRUE(c4.HasFile(dir2)); |
1873 EXPECT_TRUE(c4.HasFile(file1)); | 1873 EXPECT_TRUE(c4.HasFile(file1)); |
1874 EXPECT_TRUE(c4.HasFile(file2_abs)); | 1874 EXPECT_TRUE(c4.HasFile(file2_abs)); |
1875 EXPECT_EQ(c4.size(), 4); | 1875 EXPECT_EQ(4, c4.size()); |
1876 | 1876 |
1877 // Enumerate with a pattern. | 1877 // Enumerate with a pattern. |
1878 FileEnumerator f5(temp_dir_.path(), true, FILES_AND_DIRECTORIES, FPL("dir*")); | 1878 FileEnumerator f5(temp_dir_.path(), true, FILES_AND_DIRECTORIES, FPL("dir*")); |
1879 FindResultCollector c5(f5); | 1879 FindResultCollector c5(f5); |
1880 EXPECT_TRUE(c5.HasFile(dir1)); | 1880 EXPECT_TRUE(c5.HasFile(dir1)); |
1881 EXPECT_TRUE(c5.HasFile(dir2)); | 1881 EXPECT_TRUE(c5.HasFile(dir2)); |
1882 EXPECT_TRUE(c5.HasFile(dir2file)); | 1882 EXPECT_TRUE(c5.HasFile(dir2file)); |
1883 EXPECT_TRUE(c5.HasFile(dir2inner)); | 1883 EXPECT_TRUE(c5.HasFile(dir2inner)); |
1884 EXPECT_TRUE(c5.HasFile(dir2innerfile)); | 1884 EXPECT_TRUE(c5.HasFile(dir2innerfile)); |
1885 EXPECT_EQ(c5.size(), 5); | 1885 EXPECT_EQ(5, c5.size()); |
1886 | 1886 |
1887 #if defined(OS_WIN) | 1887 #if defined(OS_WIN) |
1888 { | 1888 { |
1889 // Make dir1 point to dir2. | 1889 // Make dir1 point to dir2. |
1890 ReparsePoint reparse_point(dir1, dir2); | 1890 ReparsePoint reparse_point(dir1, dir2); |
1891 EXPECT_TRUE(reparse_point.IsValid()); | 1891 EXPECT_TRUE(reparse_point.IsValid()); |
1892 | 1892 |
1893 if ((win::GetVersion() >= win::VERSION_VISTA)) { | 1893 if ((win::GetVersion() >= win::VERSION_VISTA)) { |
1894 // There can be a delay for the enumeration code to see the change on | 1894 // There can be a delay for the enumeration code to see the change on |
1895 // the file system so skip this test for XP. | 1895 // the file system so skip this test for XP. |
1896 // Enumerate the reparse point. | 1896 // Enumerate the reparse point. |
1897 FileEnumerator f6(dir1, true, FILES_AND_DIRECTORIES); | 1897 FileEnumerator f6(dir1, true, FILES_AND_DIRECTORIES); |
1898 FindResultCollector c6(f6); | 1898 FindResultCollector c6(f6); |
1899 FilePath inner2 = dir1.Append(FPL("inner")); | 1899 FilePath inner2 = dir1.Append(FPL("inner")); |
1900 EXPECT_TRUE(c6.HasFile(inner2)); | 1900 EXPECT_TRUE(c6.HasFile(inner2)); |
1901 EXPECT_TRUE(c6.HasFile(inner2.Append(FPL("innerfile.txt")))); | 1901 EXPECT_TRUE(c6.HasFile(inner2.Append(FPL("innerfile.txt")))); |
1902 EXPECT_TRUE(c6.HasFile(dir1.Append(FPL("dir2file.txt")))); | 1902 EXPECT_TRUE(c6.HasFile(dir1.Append(FPL("dir2file.txt")))); |
1903 EXPECT_EQ(c6.size(), 3); | 1903 EXPECT_EQ(3, c6.size()); |
1904 } | 1904 } |
1905 | 1905 |
1906 // No changes for non recursive operation. | 1906 // No changes for non recursive operation. |
1907 FileEnumerator f7(temp_dir_.path(), false, FILES_AND_DIRECTORIES); | 1907 FileEnumerator f7(temp_dir_.path(), false, FILES_AND_DIRECTORIES); |
1908 FindResultCollector c7(f7); | 1908 FindResultCollector c7(f7); |
1909 EXPECT_TRUE(c7.HasFile(dir2)); | 1909 EXPECT_TRUE(c7.HasFile(dir2)); |
1910 EXPECT_TRUE(c7.HasFile(dir2)); | 1910 EXPECT_TRUE(c7.HasFile(dir2)); |
1911 EXPECT_TRUE(c7.HasFile(file1)); | 1911 EXPECT_TRUE(c7.HasFile(file1)); |
1912 EXPECT_TRUE(c7.HasFile(file2_abs)); | 1912 EXPECT_TRUE(c7.HasFile(file2_abs)); |
1913 EXPECT_EQ(c7.size(), 4); | 1913 EXPECT_EQ(4, c7.size()); |
1914 | 1914 |
1915 // Should not enumerate inside dir1 when using recursion. | 1915 // Should not enumerate inside dir1 when using recursion. |
1916 FileEnumerator f8(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1916 FileEnumerator f8(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
1917 FindResultCollector c8(f8); | 1917 FindResultCollector c8(f8); |
1918 EXPECT_TRUE(c8.HasFile(dir1)); | 1918 EXPECT_TRUE(c8.HasFile(dir1)); |
1919 EXPECT_TRUE(c8.HasFile(dir2)); | 1919 EXPECT_TRUE(c8.HasFile(dir2)); |
1920 EXPECT_TRUE(c8.HasFile(file1)); | 1920 EXPECT_TRUE(c8.HasFile(file1)); |
1921 EXPECT_TRUE(c8.HasFile(file2_abs)); | 1921 EXPECT_TRUE(c8.HasFile(file2_abs)); |
1922 EXPECT_TRUE(c8.HasFile(dir2file)); | 1922 EXPECT_TRUE(c8.HasFile(dir2file)); |
1923 EXPECT_TRUE(c8.HasFile(dir2inner)); | 1923 EXPECT_TRUE(c8.HasFile(dir2inner)); |
1924 EXPECT_TRUE(c8.HasFile(dir2innerfile)); | 1924 EXPECT_TRUE(c8.HasFile(dir2innerfile)); |
1925 EXPECT_EQ(c8.size(), 7); | 1925 EXPECT_EQ(7, c8.size()); |
1926 } | 1926 } |
1927 #endif | 1927 #endif |
1928 | 1928 |
1929 // Make sure the destructor closes the find handle while in the middle of a | 1929 // Make sure the destructor closes the find handle while in the middle of a |
1930 // query to allow TearDown to delete the directory. | 1930 // query to allow TearDown to delete the directory. |
1931 FileEnumerator f9(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1931 FileEnumerator f9(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
1932 EXPECT_FALSE(f9.Next().value().empty()); // Should have found something | 1932 EXPECT_FALSE(f9.Next().value().empty()); // Should have found something |
1933 // (we don't care what). | 1933 // (we don't care what). |
1934 } | 1934 } |
1935 | 1935 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1971 WriteFile(file_path, kTestData.data(), kTestData.size())); | 1971 WriteFile(file_path, kTestData.data(), kTestData.size())); |
1972 | 1972 |
1973 // Make buffers with various size. | 1973 // Make buffers with various size. |
1974 std::vector<char> small_buffer(kTestData.size() / 2); | 1974 std::vector<char> small_buffer(kTestData.size() / 2); |
1975 std::vector<char> exact_buffer(kTestData.size()); | 1975 std::vector<char> exact_buffer(kTestData.size()); |
1976 std::vector<char> large_buffer(kTestData.size() * 2); | 1976 std::vector<char> large_buffer(kTestData.size() * 2); |
1977 | 1977 |
1978 // Read the file with smaller buffer. | 1978 // Read the file with smaller buffer. |
1979 int bytes_read_small = ReadFile( | 1979 int bytes_read_small = ReadFile( |
1980 file_path, &small_buffer[0], static_cast<int>(small_buffer.size())); | 1980 file_path, &small_buffer[0], static_cast<int>(small_buffer.size())); |
1981 EXPECT_EQ(bytes_read_small, static_cast<int>(small_buffer.size())); | 1981 EXPECT_EQ(static_cast<int>(small_buffer.size()), bytes_read_small); |
1982 EXPECT_EQ( | 1982 EXPECT_EQ( |
1983 std::string(small_buffer.begin(), small_buffer.end()), | 1983 std::string(kTestData.begin(), kTestData.begin() + small_buffer.size()), |
1984 std::string(kTestData.begin(), kTestData.begin() + small_buffer.size())); | 1984 std::string(small_buffer.begin(), small_buffer.end())); |
1985 | 1985 |
1986 // Read the file with buffer which have exactly same size. | 1986 // Read the file with buffer which have exactly same size. |
1987 int bytes_read_exact = ReadFile( | 1987 int bytes_read_exact = ReadFile( |
1988 file_path, &exact_buffer[0], static_cast<int>(exact_buffer.size())); | 1988 file_path, &exact_buffer[0], static_cast<int>(exact_buffer.size())); |
1989 EXPECT_EQ(bytes_read_exact, static_cast<int>(kTestData.size())); | 1989 EXPECT_EQ(static_cast<int>(kTestData.size()), bytes_read_exact); |
1990 EXPECT_EQ(std::string(exact_buffer.begin(), exact_buffer.end()), kTestData); | 1990 EXPECT_EQ(kTestData, std::string(exact_buffer.begin(), exact_buffer.end())); |
1991 | 1991 |
1992 // Read the file with larger buffer. | 1992 // Read the file with larger buffer. |
1993 int bytes_read_large = ReadFile( | 1993 int bytes_read_large = ReadFile( |
1994 file_path, &large_buffer[0], static_cast<int>(large_buffer.size())); | 1994 file_path, &large_buffer[0], static_cast<int>(large_buffer.size())); |
1995 EXPECT_EQ(bytes_read_large, static_cast<int>(kTestData.size())); | 1995 EXPECT_EQ(static_cast<int>(kTestData.size()), bytes_read_large); |
1996 EXPECT_EQ(std::string(large_buffer.begin(), | 1996 EXPECT_EQ(kTestData, std::string(large_buffer.begin(), |
1997 large_buffer.begin() + kTestData.size()), | 1997 large_buffer.begin() + kTestData.size())); |
1998 kTestData); | |
1999 | 1998 |
2000 // Make sure the return value is -1 if the file doesn't exist. | 1999 // Make sure the return value is -1 if the file doesn't exist. |
2001 FilePath file_path_not_exist = | 2000 FilePath file_path_not_exist = |
2002 temp_dir_.path().Append(FILE_PATH_LITERAL("ReadFileNotExistTest")); | 2001 temp_dir_.path().Append(FILE_PATH_LITERAL("ReadFileNotExistTest")); |
2003 EXPECT_EQ(-1, | 2002 EXPECT_EQ(-1, |
2004 ReadFile(file_path_not_exist, | 2003 ReadFile(file_path_not_exist, |
2005 &exact_buffer[0], | 2004 &exact_buffer[0], |
2006 static_cast<int>(exact_buffer.size()))); | 2005 static_cast<int>(exact_buffer.size()))); |
2007 } | 2006 } |
2008 | 2007 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 ASSERT_TRUE(CreateDirectory(data_dir)); | 2073 ASSERT_TRUE(CreateDirectory(data_dir)); |
2075 | 2074 |
2076 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | 2075 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
2077 std::string data("hello"); | 2076 std::string data("hello"); |
2078 ASSERT_TRUE(WriteFile(foobar, data.c_str(), data.length())); | 2077 ASSERT_TRUE(WriteFile(foobar, data.c_str(), data.length())); |
2079 | 2078 |
2080 Time access_time; | 2079 Time access_time; |
2081 // This timestamp is divisible by one day (in local timezone), | 2080 // This timestamp is divisible by one day (in local timezone), |
2082 // to make it work on FAT too. | 2081 // to make it work on FAT too. |
2083 ASSERT_TRUE(Time::FromString("Wed, 16 Nov 1994, 00:00:00", | 2082 ASSERT_TRUE(Time::FromString("Wed, 16 Nov 1994, 00:00:00", |
2084 &access_time)); | 2083 &access_time)); |
2085 | 2084 |
2086 Time modification_time; | 2085 Time modification_time; |
2087 // Note that this timestamp is divisible by two (seconds) - FAT stores | 2086 // Note that this timestamp is divisible by two (seconds) - FAT stores |
2088 // modification times with 2s resolution. | 2087 // modification times with 2s resolution. |
2089 ASSERT_TRUE(Time::FromString("Tue, 15 Nov 1994, 12:45:26 GMT", | 2088 ASSERT_TRUE(Time::FromString("Tue, 15 Nov 1994, 12:45:26 GMT", |
2090 &modification_time)); | 2089 &modification_time)); |
2091 | 2090 |
2092 ASSERT_TRUE(TouchFile(foobar, access_time, modification_time)); | 2091 ASSERT_TRUE(TouchFile(foobar, access_time, modification_time)); |
2093 File::Info file_info; | 2092 File::Info file_info; |
2094 ASSERT_TRUE(GetFileInfo(foobar, &file_info)); | 2093 ASSERT_TRUE(GetFileInfo(foobar, &file_info)); |
2095 EXPECT_EQ(file_info.last_accessed.ToInternalValue(), | 2094 EXPECT_EQ(access_time.ToInternalValue(), |
2096 access_time.ToInternalValue()); | 2095 file_info.last_accessed.ToInternalValue()); |
2097 EXPECT_EQ(file_info.last_modified.ToInternalValue(), | 2096 EXPECT_EQ(modification_time.ToInternalValue(), |
2098 modification_time.ToInternalValue()); | 2097 file_info.last_modified.ToInternalValue()); |
2099 } | 2098 } |
2100 | 2099 |
2101 TEST_F(FileUtilTest, IsDirectoryEmpty) { | 2100 TEST_F(FileUtilTest, IsDirectoryEmpty) { |
2102 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); | 2101 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); |
2103 | 2102 |
2104 ASSERT_FALSE(PathExists(empty_dir)); | 2103 ASSERT_FALSE(PathExists(empty_dir)); |
2105 | 2104 |
2106 ASSERT_TRUE(CreateDirectory(empty_dir)); | 2105 ASSERT_TRUE(CreateDirectory(empty_dir)); |
2107 | 2106 |
2108 EXPECT_TRUE(IsDirectoryEmpty(empty_dir)); | 2107 EXPECT_TRUE(IsDirectoryEmpty(empty_dir)); |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2562 // Trying to close it should crash. This is important for security. | 2561 // Trying to close it should crash. This is important for security. |
2563 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); | 2562 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); |
2564 #endif | 2563 #endif |
2565 } | 2564 } |
2566 | 2565 |
2567 #endif // defined(OS_POSIX) | 2566 #endif // defined(OS_POSIX) |
2568 | 2567 |
2569 } // namespace | 2568 } // namespace |
2570 | 2569 |
2571 } // namespace base | 2570 } // namespace base |
OLD | NEW |