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

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

Issue 465059: Implement parser for Netware-style FTP LIST response listing. (Closed)
Patch Set: Created 11 years 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
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"
9 #include "base/string_util.h"
10 #include "base/time.h"
8 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
9 12
10 namespace { 13 namespace {
11 14
12 TEST(FtpUtilTest, UnixFilePathToVMS) { 15 TEST(FtpUtilTest, UnixFilePathToVMS) {
13 const struct { 16 const struct {
14 const char* input; 17 const char* input;
15 const char* expected_output; 18 const char* expected_output;
16 } kTestCases[] = { 19 } kTestCases[] = {
17 { "", "" }, 20 { "", "" },
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 { "[.a.b.c]d", "a/b/c/d" }, 94 { "[.a.b.c]d", "a/b/c/d" },
92 { "[.a.b.c.d]", "a/b/c/d" }, 95 { "[.a.b.c.d]", "a/b/c/d" },
93 }; 96 };
94 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { 97 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) {
95 EXPECT_EQ(kTestCases[i].expected_output, 98 EXPECT_EQ(kTestCases[i].expected_output,
96 net::FtpUtil::VMSPathToUnix(kTestCases[i].input)) 99 net::FtpUtil::VMSPathToUnix(kTestCases[i].input))
97 << kTestCases[i].input; 100 << kTestCases[i].input;
98 } 101 }
99 } 102 }
100 103
104 TEST(FtpUtilTest, LsDateListingToTime) {
105 base::Time::Exploded now_exploded;
106 base::Time::Now().LocalExplode(&now_exploded);
107
108 const struct {
109 // Input.
110 const char* month;
111 const char* day;
112 const char* rest;
113
114 // Expected output.
115 int expected_year;
116 int expected_month;
117 int expected_day_of_month;
118 int expected_hour;
119 int expected_minute;
120 } kTestCases[] = {
121 { "Nov", "01", "2007", 2007, 11, 1, 0, 0 },
122 { "Jul", "25", "13:37", now_exploded.year, 7, 25, 13, 37 },
123
124 // Test date listings in German, we should support them for FTP servers
125 // giving localized listings.
126 { "M\xc3\xa4r", "13", "2009", 2009, 3, 13, 0, 0 },
127 { "Mai", "1", "10:10", now_exploded.year, 5, 1, 10, 10 },
128 { "Okt", "14", "21:18", now_exploded.year, 10, 14, 21, 18 },
129 { "Dez", "25", "2008", 2008, 12, 25, 0, 0 },
130 };
131 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) {
132 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s %s %s", i,
133 kTestCases[i].month, kTestCases[i].day,
134 kTestCases[i].rest));
135
136 base::Time time;
137 ASSERT_TRUE(net::FtpUtil::LsDateListingToTime(
138 UTF8ToUTF16(kTestCases[i].month), UTF8ToUTF16(kTestCases[i].day),
139 UTF8ToUTF16(kTestCases[i].rest), &time));
140
141 base::Time::Exploded time_exploded;
142 time.LocalExplode(&time_exploded);
143 EXPECT_EQ(kTestCases[i].expected_year, time_exploded.year);
144 EXPECT_EQ(kTestCases[i].expected_month, time_exploded.month);
145 EXPECT_EQ(kTestCases[i].expected_day_of_month, time_exploded.day_of_month);
146 EXPECT_EQ(kTestCases[i].expected_hour, time_exploded.hour);
147 EXPECT_EQ(kTestCases[i].expected_minute, time_exploded.minute);
148 EXPECT_EQ(0, time_exploded.second);
149 EXPECT_EQ(0, time_exploded.millisecond);
150 }
151 }
152
101 } // namespace 153 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698