diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 10:35:27 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 10:35:27 +0000 |
commit | b7394ff0fd9dc89187d40860e7e86386c373c9ab (patch) | |
tree | 3a3b37db268e304d9f867952486a07ce673c778a /net/ftp/ftp_util_unittest.cc | |
parent | 8ba4973cfcfe2a6b8c0cacca76fabe8b66d41646 (diff) | |
download | chromium_src-b7394ff0fd9dc89187d40860e7e86386c373c9ab.zip chromium_src-b7394ff0fd9dc89187d40860e7e86386c373c9ab.tar.gz chromium_src-b7394ff0fd9dc89187d40860e7e86386c373c9ab.tar.bz2 |
Fix the "ls -l" style date parser to correctly guess the year if it is not provided.
Also provide an infrastructure to mock the current time in the tests.
BUG=36293
TEST=net_unittests
Review URL: http://codereview.chromium.org/1120012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42447 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp/ftp_util_unittest.cc')
-rw-r--r-- | net/ftp/ftp_util_unittest.cc | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/net/ftp/ftp_util_unittest.cc b/net/ftp/ftp_util_unittest.cc index 834d86f..480c893 100644 --- a/net/ftp/ftp_util_unittest.cc +++ b/net/ftp/ftp_util_unittest.cc @@ -103,8 +103,9 @@ TEST(FtpUtilTest, VMSPathToUnix) { } TEST(FtpUtilTest, LsDateListingToTime) { - base::Time::Exploded now_exploded; - base::Time::Now().LocalExplode(&now_exploded); + base::Time mock_current_time; + ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994 12:45:26 GMT", + &mock_current_time)); const struct { // Input. @@ -120,14 +121,22 @@ TEST(FtpUtilTest, LsDateListingToTime) { int expected_minute; } kTestCases[] = { { "Nov", "01", "2007", 2007, 11, 1, 0, 0 }, - { "Jul", "25", "13:37", now_exploded.year, 7, 25, 13, 37 }, + { "Jul", "25", "13:37", 1994, 7, 25, 13, 37 }, // Test date listings in German, we should support them for FTP servers // giving localized listings. { "M\xc3\xa4r", "13", "2009", 2009, 3, 13, 0, 0 }, - { "Mai", "1", "10:10", now_exploded.year, 5, 1, 10, 10 }, - { "Okt", "14", "21:18", now_exploded.year, 10, 14, 21, 18 }, + { "Mai", "1", "10:10", 1994, 5, 1, 10, 10 }, + { "Okt", "14", "21:18", 1994, 10, 14, 21, 18 }, { "Dez", "25", "2008", 2008, 12, 25, 0, 0 }, + + // Test current year detection. + { "Nov", "01", "12:00", 1994, 11, 1, 12, 0 }, + { "Nov", "15", "12:00", 1994, 11, 15, 12, 0 }, + { "Nov", "16", "12:00", 1993, 11, 16, 12, 0 }, + { "Jan", "01", "08:30", 1994, 1, 1, 8, 30 }, + { "Sep", "02", "09:00", 1994, 9, 2, 9, 0 }, + { "Dec", "06", "21:00", 1993, 12, 6, 21, 0 }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s %s %s", i, @@ -137,7 +146,7 @@ TEST(FtpUtilTest, LsDateListingToTime) { base::Time time; ASSERT_TRUE(net::FtpUtil::LsDateListingToTime( UTF8ToUTF16(kTestCases[i].month), UTF8ToUTF16(kTestCases[i].day), - UTF8ToUTF16(kTestCases[i].rest), &time)); + UTF8ToUTF16(kTestCases[i].rest), mock_current_time, &time)); base::Time::Exploded time_exploded; time.LocalExplode(&time_exploded); |