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

Side by Side Diff: net/ftp/ftp_util_unittest.cc

Issue 1120012: Fix the "ls -l" style date parser to correctly guess the year if it is not provided. (Closed)
Patch Set: better comments Created 10 years, 9 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
« no previous file with comments | « net/ftp/ftp_util.cc ('k') | webkit/glue/ftp_directory_listing_response_delegate.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "net/ftp/ftp_util.h" 5 #include "net/ftp/ftp_util.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 { "[.a.b.c.d]", "a/b/c/d" }, 96 { "[.a.b.c.d]", "a/b/c/d" },
97 }; 97 };
98 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { 98 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) {
99 EXPECT_EQ(kTestCases[i].expected_output, 99 EXPECT_EQ(kTestCases[i].expected_output,
100 net::FtpUtil::VMSPathToUnix(kTestCases[i].input)) 100 net::FtpUtil::VMSPathToUnix(kTestCases[i].input))
101 << kTestCases[i].input; 101 << kTestCases[i].input;
102 } 102 }
103 } 103 }
104 104
105 TEST(FtpUtilTest, LsDateListingToTime) { 105 TEST(FtpUtilTest, LsDateListingToTime) {
106 base::Time::Exploded now_exploded; 106 base::Time mock_current_time;
107 base::Time::Now().LocalExplode(&now_exploded); 107 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994 12:45:26 GMT",
108 &mock_current_time));
108 109
109 const struct { 110 const struct {
110 // Input. 111 // Input.
111 const char* month; 112 const char* month;
112 const char* day; 113 const char* day;
113 const char* rest; 114 const char* rest;
114 115
115 // Expected output. 116 // Expected output.
116 int expected_year; 117 int expected_year;
117 int expected_month; 118 int expected_month;
118 int expected_day_of_month; 119 int expected_day_of_month;
119 int expected_hour; 120 int expected_hour;
120 int expected_minute; 121 int expected_minute;
121 } kTestCases[] = { 122 } kTestCases[] = {
122 { "Nov", "01", "2007", 2007, 11, 1, 0, 0 }, 123 { "Nov", "01", "2007", 2007, 11, 1, 0, 0 },
123 { "Jul", "25", "13:37", now_exploded.year, 7, 25, 13, 37 }, 124 { "Jul", "25", "13:37", 1994, 7, 25, 13, 37 },
124 125
125 // Test date listings in German, we should support them for FTP servers 126 // Test date listings in German, we should support them for FTP servers
126 // giving localized listings. 127 // giving localized listings.
127 { "M\xc3\xa4r", "13", "2009", 2009, 3, 13, 0, 0 }, 128 { "M\xc3\xa4r", "13", "2009", 2009, 3, 13, 0, 0 },
128 { "Mai", "1", "10:10", now_exploded.year, 5, 1, 10, 10 }, 129 { "Mai", "1", "10:10", 1994, 5, 1, 10, 10 },
129 { "Okt", "14", "21:18", now_exploded.year, 10, 14, 21, 18 }, 130 { "Okt", "14", "21:18", 1994, 10, 14, 21, 18 },
130 { "Dez", "25", "2008", 2008, 12, 25, 0, 0 }, 131 { "Dez", "25", "2008", 2008, 12, 25, 0, 0 },
132
133 // Test current year detection.
134 { "Nov", "01", "12:00", 1994, 11, 1, 12, 0 },
135 { "Nov", "15", "12:00", 1994, 11, 15, 12, 0 },
136 { "Nov", "16", "12:00", 1993, 11, 16, 12, 0 },
137 { "Jan", "01", "08:30", 1994, 1, 1, 8, 30 },
138 { "Sep", "02", "09:00", 1994, 9, 2, 9, 0 },
139 { "Dec", "06", "21:00", 1993, 12, 6, 21, 0 },
131 }; 140 };
132 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { 141 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) {
133 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s %s %s", i, 142 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s %s %s", i,
134 kTestCases[i].month, kTestCases[i].day, 143 kTestCases[i].month, kTestCases[i].day,
135 kTestCases[i].rest)); 144 kTestCases[i].rest));
136 145
137 base::Time time; 146 base::Time time;
138 ASSERT_TRUE(net::FtpUtil::LsDateListingToTime( 147 ASSERT_TRUE(net::FtpUtil::LsDateListingToTime(
139 UTF8ToUTF16(kTestCases[i].month), UTF8ToUTF16(kTestCases[i].day), 148 UTF8ToUTF16(kTestCases[i].month), UTF8ToUTF16(kTestCases[i].day),
140 UTF8ToUTF16(kTestCases[i].rest), &time)); 149 UTF8ToUTF16(kTestCases[i].rest), mock_current_time, &time));
141 150
142 base::Time::Exploded time_exploded; 151 base::Time::Exploded time_exploded;
143 time.LocalExplode(&time_exploded); 152 time.LocalExplode(&time_exploded);
144 EXPECT_EQ(kTestCases[i].expected_year, time_exploded.year); 153 EXPECT_EQ(kTestCases[i].expected_year, time_exploded.year);
145 EXPECT_EQ(kTestCases[i].expected_month, time_exploded.month); 154 EXPECT_EQ(kTestCases[i].expected_month, time_exploded.month);
146 EXPECT_EQ(kTestCases[i].expected_day_of_month, time_exploded.day_of_month); 155 EXPECT_EQ(kTestCases[i].expected_day_of_month, time_exploded.day_of_month);
147 EXPECT_EQ(kTestCases[i].expected_hour, time_exploded.hour); 156 EXPECT_EQ(kTestCases[i].expected_hour, time_exploded.hour);
148 EXPECT_EQ(kTestCases[i].expected_minute, time_exploded.minute); 157 EXPECT_EQ(kTestCases[i].expected_minute, time_exploded.minute);
149 EXPECT_EQ(0, time_exploded.second); 158 EXPECT_EQ(0, time_exploded.second);
150 EXPECT_EQ(0, time_exploded.millisecond); 159 EXPECT_EQ(0, time_exploded.millisecond);
(...skipping 21 matching lines...) Expand all
172 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s %d", 181 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s %d",
173 i, kTestCases[i].text, kTestCases[i].column)); 182 i, kTestCases[i].text, kTestCases[i].column));
174 183
175 EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_result), 184 EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_result),
176 net::FtpUtil::GetStringPartAfterColumns( 185 net::FtpUtil::GetStringPartAfterColumns(
177 ASCIIToUTF16(kTestCases[i].text), kTestCases[i].column)); 186 ASCIIToUTF16(kTestCases[i].text), kTestCases[i].column));
178 } 187 }
179 } 188 }
180 189
181 } // namespace 190 } // namespace
OLDNEW
« no previous file with comments | « net/ftp/ftp_util.cc ('k') | webkit/glue/ftp_directory_listing_response_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698