From b82ff7e8291ac0e4cb4235b2ca27c141549974f3 Mon Sep 17 00:00:00 2001 From: "dumi@chromium.org" Date: Thu, 23 Sep 2010 19:13:40 +0000 Subject: Add a TouchFile function that operates on FilePaths + fixing a bug related to FILE_WRITE_ATTRIBUTES on Windows. BUG=none TEST=FileUtilTest::TouchFile Review URL: http://codereview.chromium.org/3404018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60322 0039d316-1c4b-4281-b951-d872f2087c98 --- base/file_util_unittest.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'base/file_util_unittest.cc') diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index 068e5e50..ca36b6a 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -1753,7 +1753,7 @@ TEST_F(FileUtilTest, Contains) { #endif } -TEST_F(FileUtilTest, LastModified) { +TEST_F(FileUtilTest, TouchFile) { FilePath data_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); @@ -1767,15 +1767,25 @@ TEST_F(FileUtilTest, LastModified) { std::string data("hello"); ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length())); + base::Time access_time; + // This timestamp is divisible by one day (in local timezone), + // to make it work on FAT too. + ASSERT_TRUE(base::Time::FromString(L"Wed, 16 Nov 1994, 00:00:00", + &access_time)); + base::Time modification_time; // Note that this timestamp is divisible by two (seconds) - FAT stores // modification times with 2s resolution. ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT", &modification_time)); - ASSERT_TRUE(file_util::SetLastModifiedTime(foobar, modification_time)); + + ASSERT_TRUE(file_util::TouchFile(foobar, access_time, modification_time)); base::PlatformFileInfo file_info; ASSERT_TRUE(file_util::GetFileInfo(foobar, &file_info)); - ASSERT_TRUE(file_info.last_modified == modification_time); + EXPECT_EQ(file_info.last_accessed.ToInternalValue(), + access_time.ToInternalValue()); + EXPECT_EQ(file_info.last_modified.ToInternalValue(), + modification_time.ToInternalValue()); } TEST_F(FileUtilTest, IsDirectoryEmpty) { -- cgit v1.1