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

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

Issue 7590011: FTP: add directory listing parser for OS/2 format. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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
OLDNEW
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
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 }
eroman 2011/08/10 23:52:16 nit: add a newline.
Paweł Hajdan Jr. 2011/08/11 00:03:19 Done.
178 TEST(FtpUtilTest, GetStringPartAfterColumns) { 218 TEST(FtpUtilTest, GetStringPartAfterColumns) {
179 const struct { 219 const struct {
180 const char* text; 220 const char* text;
181 int column; 221 int column;
182 const char* expected_result; 222 const char* expected_result;
183 } kTestCases[] = { 223 } kTestCases[] = {
184 { "", 0, "" }, 224 { "", 0, "" },
185 { "", 1, "" }, 225 { "", 1, "" },
186 { "foo abc", 0, "foo abc" }, 226 { "foo abc", 0, "foo abc" },
187 { "foo abc", 1, "abc" }, 227 { "foo abc", 1, "abc" },
188 { " foo abc", 0, "foo abc" }, 228 { " foo abc", 0, "foo abc" },
189 { " foo abc", 1, "abc" }, 229 { " foo abc", 1, "abc" },
190 { " foo abc", 2, "" }, 230 { " foo abc", 2, "" },
191 { " foo abc ", 0, "foo abc" }, 231 { " foo abc ", 0, "foo abc" },
192 { " foo abc ", 1, "abc" }, 232 { " foo abc ", 1, "abc" },
193 { " foo abc ", 2, "" }, 233 { " foo abc ", 2, "" },
194 }; 234 };
195 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { 235 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) {
196 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s %d", i, 236 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s %d", i,
197 kTestCases[i].text, kTestCases[i].column)); 237 kTestCases[i].text, kTestCases[i].column));
198 238
199 EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_result), 239 EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_result),
200 net::FtpUtil::GetStringPartAfterColumns( 240 net::FtpUtil::GetStringPartAfterColumns(
201 ASCIIToUTF16(kTestCases[i].text), kTestCases[i].column)); 241 ASCIIToUTF16(kTestCases[i].text), kTestCases[i].column));
202 } 242 }
203 } 243 }
204 244
205 } // namespace 245 } // namespace
OLDNEW
« net/ftp/ftp_util.cc ('K') | « net/ftp/ftp_util.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698