Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: base/file_util_unittest.cc

Issue 3404018: Add a TouchFile function that operates on FilePaths + fixing a bug... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 FilePath(foo.value() + FILE_PATH_LITERAL("/bar.txt")))); 1746 FilePath(foo.value() + FILE_PATH_LITERAL("/bar.txt"))));
1747 #elif defined(OS_MACOSX) 1747 #elif defined(OS_MACOSX)
1748 // We can't really do this test on OS X since the case-sensitivity of the 1748 // We can't really do this test on OS X since the case-sensitivity of the
1749 // filesystem is configurable. 1749 // filesystem is configurable.
1750 #elif defined(OS_POSIX) 1750 #elif defined(OS_POSIX)
1751 EXPECT_FALSE(file_util::ContainsPath(foo, 1751 EXPECT_FALSE(file_util::ContainsPath(foo,
1752 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); 1752 foo_caps.Append(FILE_PATH_LITERAL("bar.txt"))));
1753 #endif 1753 #endif
1754 } 1754 }
1755 1755
1756 TEST_F(FileUtilTest, LastModified) { 1756 TEST_F(FileUtilTest, TouchFile) {
1757 FilePath data_dir = 1757 FilePath data_dir =
1758 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); 1758 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest"));
1759 1759
1760 // Create a fresh, empty copy of this directory. 1760 // Create a fresh, empty copy of this directory.
1761 if (file_util::PathExists(data_dir)) { 1761 if (file_util::PathExists(data_dir)) {
1762 ASSERT_TRUE(file_util::Delete(data_dir, true)); 1762 ASSERT_TRUE(file_util::Delete(data_dir, true));
1763 } 1763 }
1764 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); 1764 ASSERT_TRUE(file_util::CreateDirectory(data_dir));
1765 1765
1766 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); 1766 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt")));
1767 std::string data("hello"); 1767 std::string data("hello");
1768 ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length())); 1768 ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length()));
1769 1769
1770 base::Time access_time;
1771 // This timestamp is divisible by one day (in local timezone),
1772 // to make it work on FAT too.
1773 ASSERT_TRUE(base::Time::FromString(L"Wed, 16 Nov 1994, 00:00:00",
1774 &access_time));
1775
1770 base::Time modification_time; 1776 base::Time modification_time;
1771 // Note that this timestamp is divisible by two (seconds) - FAT stores 1777 // Note that this timestamp is divisible by two (seconds) - FAT stores
1772 // modification times with 2s resolution. 1778 // modification times with 2s resolution.
1773 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT", 1779 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT",
1774 &modification_time)); 1780 &modification_time));
1775 ASSERT_TRUE(file_util::SetLastModifiedTime(foobar, modification_time)); 1781
1782 ASSERT_TRUE(file_util::TouchFile(foobar, access_time, modification_time));
1776 base::PlatformFileInfo file_info; 1783 base::PlatformFileInfo file_info;
1777 ASSERT_TRUE(file_util::GetFileInfo(foobar, &file_info)); 1784 ASSERT_TRUE(file_util::GetFileInfo(foobar, &file_info));
1778 ASSERT_TRUE(file_info.last_modified == modification_time); 1785 EXPECT_EQ(file_info.last_accessed.ToInternalValue(),
1786 access_time.ToInternalValue());
1787 EXPECT_EQ(file_info.last_modified.ToInternalValue(),
1788 modification_time.ToInternalValue());
1779 } 1789 }
1780 1790
1781 TEST_F(FileUtilTest, IsDirectoryEmpty) { 1791 TEST_F(FileUtilTest, IsDirectoryEmpty) {
1782 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); 1792 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir"));
1783 1793
1784 ASSERT_FALSE(file_util::PathExists(empty_dir)); 1794 ASSERT_FALSE(file_util::PathExists(empty_dir));
1785 1795
1786 ASSERT_TRUE(file_util::CreateDirectory(empty_dir)); 1796 ASSERT_TRUE(file_util::CreateDirectory(empty_dir));
1787 1797
1788 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); 1798 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir));
1789 1799
1790 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); 1800 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt")));
1791 std::string bar("baz"); 1801 std::string bar("baz");
1792 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); 1802 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length()));
1793 1803
1794 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); 1804 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir));
1795 } 1805 }
1796 1806
1797 } // namespace 1807 } // namespace
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698