OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 EXPECT_EQ(kTestCases[i].expected_year, time_exploded.year); | 168 EXPECT_EQ(kTestCases[i].expected_year, time_exploded.year); |
169 EXPECT_EQ(kTestCases[i].expected_month, time_exploded.month); | 169 EXPECT_EQ(kTestCases[i].expected_month, time_exploded.month); |
170 EXPECT_EQ(kTestCases[i].expected_day_of_month, time_exploded.day_of_month); | 170 EXPECT_EQ(kTestCases[i].expected_day_of_month, time_exploded.day_of_month); |
171 EXPECT_EQ(kTestCases[i].expected_hour, time_exploded.hour); | 171 EXPECT_EQ(kTestCases[i].expected_hour, time_exploded.hour); |
172 EXPECT_EQ(kTestCases[i].expected_minute, time_exploded.minute); | 172 EXPECT_EQ(kTestCases[i].expected_minute, time_exploded.minute); |
173 EXPECT_EQ(0, time_exploded.second); | 173 EXPECT_EQ(0, time_exploded.second); |
174 EXPECT_EQ(0, time_exploded.millisecond); | 174 EXPECT_EQ(0, time_exploded.millisecond); |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
| 178 TEST(FtpUtilTest, WindowsDateListingToTime) { |
| 179 const struct { |
| 180 // Input. |
| 181 const char* date; |
| 182 const char* time; |
| 183 |
| 184 // Expected output. |
| 185 int expected_year; |
| 186 int expected_month; |
| 187 int expected_day_of_month; |
| 188 int expected_hour; |
| 189 int expected_minute; |
| 190 } kTestCases[] = { |
| 191 { "11-01-07", "12:42", 2007, 11, 1, 12, 42 }, |
| 192 { "11-01-07", "12:42AM", 2007, 11, 1, 0, 42 }, |
| 193 { "11-01-07", "12:42PM", 2007, 11, 1, 12, 42 }, |
| 194 |
| 195 { "11-01-2007", "12:42", 2007, 11, 1, 12, 42 }, |
| 196 }; |
| 197 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { |
| 198 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s %s", i, |
| 199 kTestCases[i].date, kTestCases[i].time)); |
| 200 |
| 201 base::Time time; |
| 202 ASSERT_TRUE(net::FtpUtil::WindowsDateListingToTime( |
| 203 UTF8ToUTF16(kTestCases[i].date), |
| 204 UTF8ToUTF16(kTestCases[i].time), |
| 205 &time)); |
| 206 |
| 207 base::Time::Exploded time_exploded; |
| 208 time.LocalExplode(&time_exploded); |
| 209 EXPECT_EQ(kTestCases[i].expected_year, time_exploded.year); |
| 210 EXPECT_EQ(kTestCases[i].expected_month, time_exploded.month); |
| 211 EXPECT_EQ(kTestCases[i].expected_day_of_month, time_exploded.day_of_month); |
| 212 EXPECT_EQ(kTestCases[i].expected_hour, time_exploded.hour); |
| 213 EXPECT_EQ(kTestCases[i].expected_minute, time_exploded.minute); |
| 214 EXPECT_EQ(0, time_exploded.second); |
| 215 EXPECT_EQ(0, time_exploded.millisecond); |
| 216 } |
| 217 } |
| 218 |
178 TEST(FtpUtilTest, GetStringPartAfterColumns) { | 219 TEST(FtpUtilTest, GetStringPartAfterColumns) { |
179 const struct { | 220 const struct { |
180 const char* text; | 221 const char* text; |
181 int column; | 222 int column; |
182 const char* expected_result; | 223 const char* expected_result; |
183 } kTestCases[] = { | 224 } kTestCases[] = { |
184 { "", 0, "" }, | 225 { "", 0, "" }, |
185 { "", 1, "" }, | 226 { "", 1, "" }, |
186 { "foo abc", 0, "foo abc" }, | 227 { "foo abc", 0, "foo abc" }, |
187 { "foo abc", 1, "abc" }, | 228 { "foo abc", 1, "abc" }, |
188 { " foo abc", 0, "foo abc" }, | 229 { " foo abc", 0, "foo abc" }, |
189 { " foo abc", 1, "abc" }, | 230 { " foo abc", 1, "abc" }, |
190 { " foo abc", 2, "" }, | 231 { " foo abc", 2, "" }, |
191 { " foo abc ", 0, "foo abc" }, | 232 { " foo abc ", 0, "foo abc" }, |
192 { " foo abc ", 1, "abc" }, | 233 { " foo abc ", 1, "abc" }, |
193 { " foo abc ", 2, "" }, | 234 { " foo abc ", 2, "" }, |
194 }; | 235 }; |
195 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { | 236 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { |
196 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s %d", i, | 237 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s %d", i, |
197 kTestCases[i].text, kTestCases[i].column)); | 238 kTestCases[i].text, kTestCases[i].column)); |
198 | 239 |
199 EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_result), | 240 EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_result), |
200 net::FtpUtil::GetStringPartAfterColumns( | 241 net::FtpUtil::GetStringPartAfterColumns( |
201 ASCIIToUTF16(kTestCases[i].text), kTestCases[i].column)); | 242 ASCIIToUTF16(kTestCases[i].text), kTestCases[i].column)); |
202 } | 243 } |
203 } | 244 } |
204 | 245 |
205 } // namespace | 246 } // namespace |
OLD | NEW |