| 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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 using base::ASCIIToUTF16; | 15 using base::ASCIIToUTF16; |
| 16 using base::UTF8ToUTF16; | 16 using base::UTF8ToUTF16; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 TEST(FtpUtilTest, UnixFilePathToVMS) { | 20 TEST(FtpUtilTest, UnixFilePathToVMS) { |
| 21 const struct { | 21 const struct { |
| 22 const char* input; | 22 const char* input; |
| 23 const char* expected_output; | 23 const char* expected_output; |
| 24 } kTestCases[] = { | 24 } kTestCases[] = { |
| 25 { "", "" }, | 25 {"", ""}, |
| 26 { "/", "[]" }, | 26 {"/", "[]"}, |
| 27 { "/a", "a" }, | 27 {"/a", "a"}, |
| 28 { "/a/b", "a:[000000]b" }, | 28 {"/a/b", "a:[000000]b"}, |
| 29 { "/a/b/c", "a:[b]c" }, | 29 {"/a/b/c", "a:[b]c"}, |
| 30 { "/a/b/c/d", "a:[b.c]d" }, | 30 {"/a/b/c/d", "a:[b.c]d"}, |
| 31 { "/a/b/c/d/e", "a:[b.c.d]e" }, | 31 {"/a/b/c/d/e", "a:[b.c.d]e"}, |
| 32 { "a", "a" }, | 32 {"a", "a"}, |
| 33 { "a/b", "[.a]b" }, | 33 {"a/b", "[.a]b"}, |
| 34 { "a/b/c", "[.a.b]c" }, | 34 {"a/b/c", "[.a.b]c"}, |
| 35 { "a/b/c/d", "[.a.b.c]d" }, | 35 {"a/b/c/d", "[.a.b.c]d"}, |
| 36 }; | 36 }; |
| 37 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { | 37 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { |
| 38 EXPECT_EQ(kTestCases[i].expected_output, | 38 EXPECT_EQ(kTestCases[i].expected_output, |
| 39 net::FtpUtil::UnixFilePathToVMS(kTestCases[i].input)) | 39 net::FtpUtil::UnixFilePathToVMS(kTestCases[i].input)) |
| 40 << kTestCases[i].input; | 40 << kTestCases[i].input; |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 TEST(FtpUtilTest, UnixDirectoryPathToVMS) { | 44 TEST(FtpUtilTest, UnixDirectoryPathToVMS) { |
| 45 const struct { | 45 const struct { |
| 46 const char* input; | 46 const char* input; |
| 47 const char* expected_output; | 47 const char* expected_output; |
| 48 } kTestCases[] = { | 48 } kTestCases[] = { |
| 49 { "", "" }, | 49 {"", ""}, |
| 50 { "/", "" }, | 50 {"/", ""}, |
| 51 { "/a", "a:[000000]" }, | 51 {"/a", "a:[000000]"}, |
| 52 { "/a/", "a:[000000]" }, | 52 {"/a/", "a:[000000]"}, |
| 53 { "/a/b", "a:[b]" }, | 53 {"/a/b", "a:[b]"}, |
| 54 { "/a/b/", "a:[b]" }, | 54 {"/a/b/", "a:[b]"}, |
| 55 { "/a/b/c", "a:[b.c]" }, | 55 {"/a/b/c", "a:[b.c]"}, |
| 56 { "/a/b/c/", "a:[b.c]" }, | 56 {"/a/b/c/", "a:[b.c]"}, |
| 57 { "/a/b/c/d", "a:[b.c.d]" }, | 57 {"/a/b/c/d", "a:[b.c.d]"}, |
| 58 { "/a/b/c/d/", "a:[b.c.d]" }, | 58 {"/a/b/c/d/", "a:[b.c.d]"}, |
| 59 { "/a/b/c/d/e", "a:[b.c.d.e]" }, | 59 {"/a/b/c/d/e", "a:[b.c.d.e]"}, |
| 60 { "/a/b/c/d/e/", "a:[b.c.d.e]" }, | 60 {"/a/b/c/d/e/", "a:[b.c.d.e]"}, |
| 61 { "a", "[.a]" }, | 61 {"a", "[.a]"}, |
| 62 { "a/", "[.a]" }, | 62 {"a/", "[.a]"}, |
| 63 { "a/b", "[.a.b]" }, | 63 {"a/b", "[.a.b]"}, |
| 64 { "a/b/", "[.a.b]" }, | 64 {"a/b/", "[.a.b]"}, |
| 65 { "a/b/c", "[.a.b.c]" }, | 65 {"a/b/c", "[.a.b.c]"}, |
| 66 { "a/b/c/", "[.a.b.c]" }, | 66 {"a/b/c/", "[.a.b.c]"}, |
| 67 { "a/b/c/d", "[.a.b.c.d]" }, | 67 {"a/b/c/d", "[.a.b.c.d]"}, |
| 68 { "a/b/c/d/", "[.a.b.c.d]" }, | 68 {"a/b/c/d/", "[.a.b.c.d]"}, |
| 69 }; | 69 }; |
| 70 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { | 70 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { |
| 71 EXPECT_EQ(kTestCases[i].expected_output, | 71 EXPECT_EQ(kTestCases[i].expected_output, |
| 72 net::FtpUtil::UnixDirectoryPathToVMS(kTestCases[i].input)) | 72 net::FtpUtil::UnixDirectoryPathToVMS(kTestCases[i].input)) |
| 73 << kTestCases[i].input; | 73 << kTestCases[i].input; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 TEST(FtpUtilTest, VMSPathToUnix) { | 77 TEST(FtpUtilTest, VMSPathToUnix) { |
| 78 const struct { | 78 const struct { |
| 79 const char* input; | 79 const char* input; |
| 80 const char* expected_output; | 80 const char* expected_output; |
| 81 } kTestCases[] = { | 81 } kTestCases[] = { |
| 82 { "", "." }, | 82 {"", "."}, |
| 83 { "[]", "/" }, | 83 {"[]", "/"}, |
| 84 { "a", "/a" }, | 84 {"a", "/a"}, |
| 85 { "a:[000000]", "/a" }, | 85 {"a:[000000]", "/a"}, |
| 86 { "a:[000000]b", "/a/b" }, | 86 {"a:[000000]b", "/a/b"}, |
| 87 { "a:[b]", "/a/b" }, | 87 {"a:[b]", "/a/b"}, |
| 88 { "a:[b]c", "/a/b/c" }, | 88 {"a:[b]c", "/a/b/c"}, |
| 89 { "a:[b.c]", "/a/b/c" }, | 89 {"a:[b.c]", "/a/b/c"}, |
| 90 { "a:[b.c]d", "/a/b/c/d" }, | 90 {"a:[b.c]d", "/a/b/c/d"}, |
| 91 { "a:[b.c.d]", "/a/b/c/d" }, | 91 {"a:[b.c.d]", "/a/b/c/d"}, |
| 92 { "a:[b.c.d]e", "/a/b/c/d/e" }, | 92 {"a:[b.c.d]e", "/a/b/c/d/e"}, |
| 93 { "a:[b.c.d.e]", "/a/b/c/d/e" }, | 93 {"a:[b.c.d.e]", "/a/b/c/d/e"}, |
| 94 { "[.a]", "a" }, | 94 {"[.a]", "a"}, |
| 95 { "[.a]b", "a/b" }, | 95 {"[.a]b", "a/b"}, |
| 96 { "[.a.b]", "a/b" }, | 96 {"[.a.b]", "a/b"}, |
| 97 { "[.a.b]c", "a/b/c" }, | 97 {"[.a.b]c", "a/b/c"}, |
| 98 { "[.a.b.c]", "a/b/c" }, | 98 {"[.a.b.c]", "a/b/c"}, |
| 99 { "[.a.b.c]d", "a/b/c/d" }, | 99 {"[.a.b.c]d", "a/b/c/d"}, |
| 100 { "[.a.b.c.d]", "a/b/c/d" }, | 100 {"[.a.b.c.d]", "a/b/c/d"}, |
| 101 { "[.", "" }, | 101 {"[.", ""}, |
| 102 | 102 |
| 103 // UNIX emulation: | 103 // UNIX emulation: |
| 104 { "/", "/" }, | 104 {"/", "/"}, |
| 105 { "/a", "/a" }, | 105 {"/a", "/a"}, |
| 106 { "/a/b", "/a/b" }, | 106 {"/a/b", "/a/b"}, |
| 107 { "/a/b/c", "/a/b/c" }, | 107 {"/a/b/c", "/a/b/c"}, |
| 108 { "/a/b/c/d", "/a/b/c/d" }, | 108 {"/a/b/c/d", "/a/b/c/d"}, |
| 109 }; | 109 }; |
| 110 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { | 110 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { |
| 111 EXPECT_EQ(kTestCases[i].expected_output, | 111 EXPECT_EQ(kTestCases[i].expected_output, |
| 112 net::FtpUtil::VMSPathToUnix(kTestCases[i].input)) | 112 net::FtpUtil::VMSPathToUnix(kTestCases[i].input)) |
| 113 << kTestCases[i].input; | 113 << kTestCases[i].input; |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 TEST(FtpUtilTest, LsDateListingToTime) { | 117 TEST(FtpUtilTest, LsDateListingToTime) { |
| 118 base::Time mock_current_time; | 118 base::Time mock_current_time; |
| 119 ASSERT_TRUE(base::Time::FromString("Tue, 15 Nov 1994 12:45:26 GMT", | 119 ASSERT_TRUE(base::Time::FromString("Tue, 15 Nov 1994 12:45:26 GMT", |
| 120 &mock_current_time)); | 120 &mock_current_time)); |
| 121 | 121 |
| 122 const struct { | 122 const struct { |
| 123 // Input. | 123 // Input. |
| 124 const char* month; | 124 const char* month; |
| 125 const char* day; | 125 const char* day; |
| 126 const char* rest; | 126 const char* rest; |
| 127 | 127 |
| 128 // Expected output. | 128 // Expected output. |
| 129 int expected_year; | 129 int expected_year; |
| 130 int expected_month; | 130 int expected_month; |
| 131 int expected_day_of_month; | 131 int expected_day_of_month; |
| 132 int expected_hour; | 132 int expected_hour; |
| 133 int expected_minute; | 133 int expected_minute; |
| 134 } kTestCases[] = { | 134 } kTestCases[] = { |
| 135 { "Nov", "01", "2007", 2007, 11, 1, 0, 0 }, | 135 {"Nov", "01", "2007", 2007, 11, 1, 0, 0}, |
| 136 { "Jul", "25", "13:37", 1994, 7, 25, 13, 37 }, | 136 {"Jul", "25", "13:37", 1994, 7, 25, 13, 37}, |
| 137 | 137 |
| 138 // Test date listings in German. | 138 // Test date listings in German. |
| 139 { "M\xc3\xa4r", "13", "2009", 2009, 3, 13, 0, 0 }, | 139 {"M\xc3\xa4r", "13", "2009", 2009, 3, 13, 0, 0}, |
| 140 { "Mai", "1", "10:10", 1994, 5, 1, 10, 10 }, | 140 {"Mai", "1", "10:10", 1994, 5, 1, 10, 10}, |
| 141 { "Okt", "14", "21:18", 1994, 10, 14, 21, 18 }, | 141 {"Okt", "14", "21:18", 1994, 10, 14, 21, 18}, |
| 142 { "Dez", "25", "2008", 2008, 12, 25, 0, 0 }, | 142 {"Dez", "25", "2008", 2008, 12, 25, 0, 0}, |
| 143 | 143 |
| 144 // Test date listings in Russian. | 144 // Test date listings in Russian. |
| 145 { "\xd1\x8f\xd0\xbd\xd0\xb2", "1", "2011", 2011, 1, 1, 0, 0 }, | 145 {"\xd1\x8f\xd0\xbd\xd0\xb2", "1", "2011", 2011, 1, 1, 0, 0}, |
| 146 { "\xd1\x84\xd0\xb5\xd0\xb2", "1", "2011", 2011, 2, 1, 0, 0 }, | 146 {"\xd1\x84\xd0\xb5\xd0\xb2", "1", "2011", 2011, 2, 1, 0, 0}, |
| 147 { "\xd0\xbc\xd0\xb0\xd1\x80", "1", "2011", 2011, 3, 1, 0, 0 }, | 147 {"\xd0\xbc\xd0\xb0\xd1\x80", "1", "2011", 2011, 3, 1, 0, 0}, |
| 148 { "\xd0\xb0\xd0\xbf\xd1\x80", "1", "2011", 2011, 4, 1, 0, 0 }, | 148 {"\xd0\xb0\xd0\xbf\xd1\x80", "1", "2011", 2011, 4, 1, 0, 0}, |
| 149 { "\xd0\xbc\xd0\xb0\xd0\xb9", "1", "2011", 2011, 5, 1, 0, 0 }, | 149 {"\xd0\xbc\xd0\xb0\xd0\xb9", "1", "2011", 2011, 5, 1, 0, 0}, |
| 150 { "\xd0\xb8\xd1\x8e\xd0\xbd", "1", "2011", 2011, 6, 1, 0, 0 }, | 150 {"\xd0\xb8\xd1\x8e\xd0\xbd", "1", "2011", 2011, 6, 1, 0, 0}, |
| 151 { "\xd0\xb8\xd1\x8e\xd0\xbb", "1", "2011", 2011, 7, 1, 0, 0 }, | 151 {"\xd0\xb8\xd1\x8e\xd0\xbb", "1", "2011", 2011, 7, 1, 0, 0}, |
| 152 { "\xd0\xb0\xd0\xb2\xd0\xb3", "1", "2011", 2011, 8, 1, 0, 0 }, | 152 {"\xd0\xb0\xd0\xb2\xd0\xb3", "1", "2011", 2011, 8, 1, 0, 0}, |
| 153 { "\xd1\x81\xd0\xb5\xd0\xbd", "1", "2011", 2011, 9, 1, 0, 0 }, | 153 {"\xd1\x81\xd0\xb5\xd0\xbd", "1", "2011", 2011, 9, 1, 0, 0}, |
| 154 { "\xd0\xbe\xd0\xba\xd1\x82", "1", "2011", 2011, 10, 1, 0, 0 }, | 154 {"\xd0\xbe\xd0\xba\xd1\x82", "1", "2011", 2011, 10, 1, 0, 0}, |
| 155 { "\xd0\xbd\xd0\xbe\xd1\x8f", "1", "2011", 2011, 11, 1, 0, 0 }, | 155 {"\xd0\xbd\xd0\xbe\xd1\x8f", "1", "2011", 2011, 11, 1, 0, 0}, |
| 156 { "\xd0\xb4\xd0\xb5\xd0\xba", "1", "2011", 2011, 12, 1, 0, 0 }, | 156 {"\xd0\xb4\xd0\xb5\xd0\xba", "1", "2011", 2011, 12, 1, 0, 0}, |
| 157 | 157 |
| 158 // Test current year detection. | 158 // Test current year detection. |
| 159 { "Nov", "01", "12:00", 1994, 11, 1, 12, 0 }, | 159 {"Nov", "01", "12:00", 1994, 11, 1, 12, 0}, |
| 160 { "Nov", "15", "12:00", 1994, 11, 15, 12, 0 }, | 160 {"Nov", "15", "12:00", 1994, 11, 15, 12, 0}, |
| 161 { "Nov", "16", "12:00", 1993, 11, 16, 12, 0 }, | 161 {"Nov", "16", "12:00", 1993, 11, 16, 12, 0}, |
| 162 { "Jan", "01", "08:30", 1994, 1, 1, 8, 30 }, | 162 {"Jan", "01", "08:30", 1994, 1, 1, 8, 30}, |
| 163 { "Sep", "02", "09:00", 1994, 9, 2, 9, 0 }, | 163 {"Sep", "02", "09:00", 1994, 9, 2, 9, 0}, |
| 164 { "Dec", "06", "21:00", 1993, 12, 6, 21, 0 }, | 164 {"Dec", "06", "21:00", 1993, 12, 6, 21, 0}, |
| 165 }; | 165 }; |
| 166 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { | 166 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { |
| 167 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s %s %s", i, | 167 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s %s %s", |
| 168 kTestCases[i].month, kTestCases[i].day, | 168 i, |
| 169 kTestCases[i].month, |
| 170 kTestCases[i].day, |
| 169 kTestCases[i].rest)); | 171 kTestCases[i].rest)); |
| 170 | 172 |
| 171 base::Time time; | 173 base::Time time; |
| 172 ASSERT_TRUE(net::FtpUtil::LsDateListingToTime( | 174 ASSERT_TRUE( |
| 173 UTF8ToUTF16(kTestCases[i].month), UTF8ToUTF16(kTestCases[i].day), | 175 net::FtpUtil::LsDateListingToTime(UTF8ToUTF16(kTestCases[i].month), |
| 174 UTF8ToUTF16(kTestCases[i].rest), mock_current_time, &time)); | 176 UTF8ToUTF16(kTestCases[i].day), |
| 177 UTF8ToUTF16(kTestCases[i].rest), |
| 178 mock_current_time, |
| 179 &time)); |
| 175 | 180 |
| 176 base::Time::Exploded time_exploded; | 181 base::Time::Exploded time_exploded; |
| 177 time.LocalExplode(&time_exploded); | 182 time.LocalExplode(&time_exploded); |
| 178 EXPECT_EQ(kTestCases[i].expected_year, time_exploded.year); | 183 EXPECT_EQ(kTestCases[i].expected_year, time_exploded.year); |
| 179 EXPECT_EQ(kTestCases[i].expected_month, time_exploded.month); | 184 EXPECT_EQ(kTestCases[i].expected_month, time_exploded.month); |
| 180 EXPECT_EQ(kTestCases[i].expected_day_of_month, time_exploded.day_of_month); | 185 EXPECT_EQ(kTestCases[i].expected_day_of_month, time_exploded.day_of_month); |
| 181 EXPECT_EQ(kTestCases[i].expected_hour, time_exploded.hour); | 186 EXPECT_EQ(kTestCases[i].expected_hour, time_exploded.hour); |
| 182 EXPECT_EQ(kTestCases[i].expected_minute, time_exploded.minute); | 187 EXPECT_EQ(kTestCases[i].expected_minute, time_exploded.minute); |
| 183 EXPECT_EQ(0, time_exploded.second); | 188 EXPECT_EQ(0, time_exploded.second); |
| 184 EXPECT_EQ(0, time_exploded.millisecond); | 189 EXPECT_EQ(0, time_exploded.millisecond); |
| 185 } | 190 } |
| 186 } | 191 } |
| 187 | 192 |
| 188 TEST(FtpUtilTest, WindowsDateListingToTime) { | 193 TEST(FtpUtilTest, WindowsDateListingToTime) { |
| 189 const struct { | 194 const struct { |
| 190 // Input. | 195 // Input. |
| 191 const char* date; | 196 const char* date; |
| 192 const char* time; | 197 const char* time; |
| 193 | 198 |
| 194 // Expected output. | 199 // Expected output. |
| 195 int expected_year; | 200 int expected_year; |
| 196 int expected_month; | 201 int expected_month; |
| 197 int expected_day_of_month; | 202 int expected_day_of_month; |
| 198 int expected_hour; | 203 int expected_hour; |
| 199 int expected_minute; | 204 int expected_minute; |
| 200 } kTestCases[] = { | 205 } kTestCases[] = { |
| 201 { "11-01-07", "12:42", 2007, 11, 1, 12, 42 }, | 206 {"11-01-07", "12:42", 2007, 11, 1, 12, 42}, |
| 202 { "11-01-07", "12:42AM", 2007, 11, 1, 0, 42 }, | 207 {"11-01-07", "12:42AM", 2007, 11, 1, 0, 42}, |
| 203 { "11-01-07", "12:42PM", 2007, 11, 1, 12, 42 }, | 208 {"11-01-07", "12:42PM", 2007, 11, 1, 12, 42}, |
| 204 | 209 {"11-01-2007", "12:42", 2007, 11, 1, 12, 42}, |
| 205 { "11-01-2007", "12:42", 2007, 11, 1, 12, 42 }, | 210 }; |
| 206 }; | |
| 207 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { | 211 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { |
| 208 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s %s", i, | 212 SCOPED_TRACE(base::StringPrintf( |
| 209 kTestCases[i].date, kTestCases[i].time)); | 213 "Test[%" PRIuS "]: %s %s", i, kTestCases[i].date, kTestCases[i].time)); |
| 210 | 214 |
| 211 base::Time time; | 215 base::Time time; |
| 212 ASSERT_TRUE(net::FtpUtil::WindowsDateListingToTime( | 216 ASSERT_TRUE( |
| 213 UTF8ToUTF16(kTestCases[i].date), | 217 net::FtpUtil::WindowsDateListingToTime(UTF8ToUTF16(kTestCases[i].date), |
| 214 UTF8ToUTF16(kTestCases[i].time), | 218 UTF8ToUTF16(kTestCases[i].time), |
| 215 &time)); | 219 &time)); |
| 216 | 220 |
| 217 base::Time::Exploded time_exploded; | 221 base::Time::Exploded time_exploded; |
| 218 time.LocalExplode(&time_exploded); | 222 time.LocalExplode(&time_exploded); |
| 219 EXPECT_EQ(kTestCases[i].expected_year, time_exploded.year); | 223 EXPECT_EQ(kTestCases[i].expected_year, time_exploded.year); |
| 220 EXPECT_EQ(kTestCases[i].expected_month, time_exploded.month); | 224 EXPECT_EQ(kTestCases[i].expected_month, time_exploded.month); |
| 221 EXPECT_EQ(kTestCases[i].expected_day_of_month, time_exploded.day_of_month); | 225 EXPECT_EQ(kTestCases[i].expected_day_of_month, time_exploded.day_of_month); |
| 222 EXPECT_EQ(kTestCases[i].expected_hour, time_exploded.hour); | 226 EXPECT_EQ(kTestCases[i].expected_hour, time_exploded.hour); |
| 223 EXPECT_EQ(kTestCases[i].expected_minute, time_exploded.minute); | 227 EXPECT_EQ(kTestCases[i].expected_minute, time_exploded.minute); |
| 224 EXPECT_EQ(0, time_exploded.second); | 228 EXPECT_EQ(0, time_exploded.second); |
| 225 EXPECT_EQ(0, time_exploded.millisecond); | 229 EXPECT_EQ(0, time_exploded.millisecond); |
| 226 } | 230 } |
| 227 } | 231 } |
| 228 | 232 |
| 229 TEST(FtpUtilTest, GetStringPartAfterColumns) { | 233 TEST(FtpUtilTest, GetStringPartAfterColumns) { |
| 230 const struct { | 234 const struct { |
| 231 const char* text; | 235 const char* text; |
| 232 int column; | 236 int column; |
| 233 const char* expected_result; | 237 const char* expected_result; |
| 234 } kTestCases[] = { | 238 } kTestCases[] = { |
| 235 { "", 0, "" }, | 239 {"", 0, ""}, |
| 236 { "", 1, "" }, | 240 {"", 1, ""}, |
| 237 { "foo abc", 0, "foo abc" }, | 241 {"foo abc", 0, "foo abc"}, |
| 238 { "foo abc", 1, "abc" }, | 242 {"foo abc", 1, "abc"}, |
| 239 { " foo abc", 0, "foo abc" }, | 243 {" foo abc", 0, "foo abc"}, |
| 240 { " foo abc", 1, "abc" }, | 244 {" foo abc", 1, "abc"}, |
| 241 { " foo abc", 2, "" }, | 245 {" foo abc", 2, ""}, |
| 242 { " foo abc ", 0, "foo abc" }, | 246 {" foo abc ", 0, "foo abc"}, |
| 243 { " foo abc ", 1, "abc" }, | 247 {" foo abc ", 1, "abc"}, |
| 244 { " foo abc ", 2, "" }, | 248 {" foo abc ", 2, ""}, |
| 245 }; | 249 }; |
| 246 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { | 250 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { |
| 247 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s %d", i, | 251 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s %d", |
| 248 kTestCases[i].text, kTestCases[i].column)); | 252 i, |
| 253 kTestCases[i].text, |
| 254 kTestCases[i].column)); |
| 249 | 255 |
| 250 EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_result), | 256 EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_result), |
| 251 net::FtpUtil::GetStringPartAfterColumns( | 257 net::FtpUtil::GetStringPartAfterColumns( |
| 252 ASCIIToUTF16(kTestCases[i].text), kTestCases[i].column)); | 258 ASCIIToUTF16(kTestCases[i].text), kTestCases[i].column)); |
| 253 } | 259 } |
| 254 } | 260 } |
| 255 | 261 |
| 256 } // namespace | 262 } // namespace |
| OLD | NEW |