| OLD | NEW |
| 1 // Copyright (c) 2010 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_directory_listing_parser_unittest.h" | 5 #include "net/ftp/ftp_directory_listing_parser_unittest.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "net/ftp/ftp_directory_listing_parser_windows.h" | 10 #include "net/ftp/ftp_directory_listing_parser_windows.h" |
| 11 | 11 |
| 12 namespace net { |
| 13 |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 typedef net::FtpDirectoryListingParserTest FtpDirectoryListingParserWindowsTest; | 16 typedef FtpDirectoryListingParserTest FtpDirectoryListingParserWindowsTest; |
| 15 | 17 |
| 16 TEST_F(FtpDirectoryListingParserWindowsTest, Good) { | 18 TEST_F(FtpDirectoryListingParserWindowsTest, Good) { |
| 17 const struct SingleLineTestData good_cases[] = { | 19 const struct SingleLineTestData good_cases[] = { |
| 18 { "11-02-09 05:32PM <DIR> NT", | 20 { "11-02-09 05:32PM <DIR> NT", |
| 19 net::FtpDirectoryListingEntry::DIRECTORY, "NT", -1, | 21 FtpDirectoryListingEntry::DIRECTORY, "NT", -1, |
| 20 2009, 11, 2, 17, 32 }, | 22 2009, 11, 2, 17, 32 }, |
| 21 { "01-06-09 02:42PM 458 Readme.txt", | 23 { "01-06-09 02:42PM 458 Readme.txt", |
| 22 net::FtpDirectoryListingEntry::FILE, "Readme.txt", 458, | 24 FtpDirectoryListingEntry::FILE, "Readme.txt", 458, |
| 23 2009, 1, 6, 14, 42 }, | 25 2009, 1, 6, 14, 42 }, |
| 24 { "01-06-09 02:42AM 1 Readme.txt", | 26 { "01-06-09 02:42AM 1 Readme.txt", |
| 25 net::FtpDirectoryListingEntry::FILE, "Readme.txt", 1, | 27 FtpDirectoryListingEntry::FILE, "Readme.txt", 1, |
| 26 2009, 1, 6, 2, 42 }, | 28 2009, 1, 6, 2, 42 }, |
| 27 { "01-06-01 02:42AM 458 Readme.txt", | 29 { "01-06-01 02:42AM 458 Readme.txt", |
| 28 net::FtpDirectoryListingEntry::FILE, "Readme.txt", 458, | 30 FtpDirectoryListingEntry::FILE, "Readme.txt", 458, |
| 29 2001, 1, 6, 2, 42 }, | 31 2001, 1, 6, 2, 42 }, |
| 30 { "01-06-00 02:42AM 458 Corner1.txt", | 32 { "01-06-00 02:42AM 458 Corner1.txt", |
| 31 net::FtpDirectoryListingEntry::FILE, "Corner1.txt", 458, | 33 FtpDirectoryListingEntry::FILE, "Corner1.txt", 458, |
| 32 2000, 1, 6, 2, 42 }, | 34 2000, 1, 6, 2, 42 }, |
| 33 { "01-06-99 02:42AM 458 Corner2.txt", | 35 { "01-06-99 02:42AM 458 Corner2.txt", |
| 34 net::FtpDirectoryListingEntry::FILE, "Corner2.txt", 458, | 36 FtpDirectoryListingEntry::FILE, "Corner2.txt", 458, |
| 35 1999, 1, 6, 2, 42 }, | 37 1999, 1, 6, 2, 42 }, |
| 36 { "01-06-80 02:42AM 458 Corner3.txt", | 38 { "01-06-80 02:42AM 458 Corner3.txt", |
| 37 net::FtpDirectoryListingEntry::FILE, "Corner3.txt", 458, | 39 FtpDirectoryListingEntry::FILE, "Corner3.txt", 458, |
| 38 1980, 1, 6, 2, 42 }, | 40 1980, 1, 6, 2, 42 }, |
| 39 #if !defined(OS_LINUX) | 41 #if !defined(OS_LINUX) |
| 40 // TODO(phajdan.jr): Re-enable when 2038-year problem is fixed on Linux. | 42 // TODO(phajdan.jr): Re-enable when 2038-year problem is fixed on Linux. |
| 41 { "01-06-79 02:42AM 458 Corner4", | 43 { "01-06-79 02:42AM 458 Corner4", |
| 42 net::FtpDirectoryListingEntry::FILE, "Corner4", 458, | 44 FtpDirectoryListingEntry::FILE, "Corner4", 458, |
| 43 2079, 1, 6, 2, 42 }, | 45 2079, 1, 6, 2, 42 }, |
| 44 #endif // !defined (OS_LINUX) | 46 #endif // !defined (OS_LINUX) |
| 45 { "01-06-1979 02:42AM 458 Readme.txt", | 47 { "01-06-1979 02:42AM 458 Readme.txt", |
| 46 net::FtpDirectoryListingEntry::FILE, "Readme.txt", 458, | 48 FtpDirectoryListingEntry::FILE, "Readme.txt", 458, |
| 47 1979, 1, 6, 2, 42 }, | 49 1979, 1, 6, 2, 42 }, |
| 48 { "11-02-09 05:32PM <DIR> My Directory", | 50 { "11-02-09 05:32PM <DIR> My Directory", |
| 49 net::FtpDirectoryListingEntry::DIRECTORY, "My Directory", -1, | 51 FtpDirectoryListingEntry::DIRECTORY, "My Directory", -1, |
| 50 2009, 11, 2, 17, 32 }, | 52 2009, 11, 2, 17, 32 }, |
| 51 { "12-25-10 12:00AM <DIR> Christmas Midnight", | 53 { "12-25-10 12:00AM <DIR> Christmas Midnight", |
| 52 net::FtpDirectoryListingEntry::DIRECTORY, "Christmas Midnight", -1, | 54 FtpDirectoryListingEntry::DIRECTORY, "Christmas Midnight", -1, |
| 53 2010, 12, 25, 0, 0 }, | 55 2010, 12, 25, 0, 0 }, |
| 54 { "12-25-10 12:00PM <DIR> Christmas Midday", | 56 { "12-25-10 12:00PM <DIR> Christmas Midday", |
| 55 net::FtpDirectoryListingEntry::DIRECTORY, "Christmas Midday", -1, | 57 FtpDirectoryListingEntry::DIRECTORY, "Christmas Midday", -1, |
| 56 2010, 12, 25, 12, 0 }, | 58 2010, 12, 25, 12, 0 }, |
| 57 }; | 59 }; |
| 58 for (size_t i = 0; i < arraysize(good_cases); i++) { | 60 for (size_t i = 0; i < arraysize(good_cases); i++) { |
| 59 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, | 61 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
| 60 good_cases[i].input)); | 62 good_cases[i].input)); |
| 61 | 63 |
| 62 net::FtpDirectoryListingParserWindows parser; | 64 std::vector<FtpDirectoryListingEntry> entries; |
| 63 RunSingleLineTestCase(&parser, good_cases[i]); | 65 EXPECT_TRUE(ParseFtpDirectoryListingWindows( |
| 66 GetSingleLineTestCase(good_cases[i].input), |
| 67 &entries)); |
| 68 VerifySingleLineTestCase(good_cases[i], entries); |
| 64 } | 69 } |
| 65 } | 70 } |
| 66 | 71 |
| 67 TEST_F(FtpDirectoryListingParserWindowsTest, Ignored) { | 72 TEST_F(FtpDirectoryListingParserWindowsTest, Ignored) { |
| 68 const char* ignored_cases[] = { | 73 const char* ignored_cases[] = { |
| 69 "12-07-10 12:05AM <DIR> ", // http://crbug.com/66097 | 74 "12-07-10 12:05AM <DIR> ", // http://crbug.com/66097 |
| 70 "12-07-10 12:05AM 1234 ", | 75 "12-07-10 12:05AM 1234 ", |
| 71 }; | 76 }; |
| 72 for (size_t i = 0; i < arraysize(ignored_cases); i++) { | 77 for (size_t i = 0; i < arraysize(ignored_cases); i++) { |
| 73 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, | 78 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
| 74 ignored_cases[i])); | 79 ignored_cases[i])); |
| 75 | 80 |
| 76 net::FtpDirectoryListingParserWindows parser; | 81 std::vector<FtpDirectoryListingEntry> entries; |
| 77 EXPECT_TRUE(parser.ConsumeLine(UTF8ToUTF16(ignored_cases[i]))); | 82 EXPECT_TRUE(ParseFtpDirectoryListingWindows( |
| 78 EXPECT_FALSE(parser.EntryAvailable()); | 83 GetSingleLineTestCase(ignored_cases[i]), |
| 79 EXPECT_TRUE(parser.OnEndOfInput()); | 84 &entries)); |
| 80 EXPECT_FALSE(parser.EntryAvailable()); | 85 EXPECT_EQ(0U, entries.size()); |
| 81 } | 86 } |
| 82 } | 87 } |
| 83 | 88 |
| 84 TEST_F(FtpDirectoryListingParserWindowsTest, Bad) { | 89 TEST_F(FtpDirectoryListingParserWindowsTest, Bad) { |
| 85 const char* bad_cases[] = { | 90 const char* bad_cases[] = { |
| 86 "", | |
| 87 "garbage", | 91 "garbage", |
| 88 "11-02-09 05:32PM <GARBAGE>", | 92 "11-02-09 05:32PM <GARBAGE>", |
| 89 "11-02-09 05:32PM <GARBAGE> NT", | 93 "11-02-09 05:32PM <GARBAGE> NT", |
| 90 "11-02-09 05:32 <DIR>", | 94 "11-02-09 05:32 <DIR>", |
| 91 "11-FEB-09 05:32PM <DIR>", | 95 "11-FEB-09 05:32PM <DIR>", |
| 92 "11-02 05:32PM <DIR>", | 96 "11-02 05:32PM <DIR>", |
| 93 "11-02-09 05:32PM -1", | 97 "11-02-09 05:32PM -1", |
| 94 "11-02-09 05:32 <DIR> NT", | 98 "11-02-09 05:32 <DIR> NT", |
| 95 "11-FEB-09 05:32PM <DIR> NT", | 99 "11-FEB-09 05:32PM <DIR> NT", |
| 96 "11-02 05:32PM <DIR> NT", | 100 "11-02 05:32PM <DIR> NT", |
| 97 "11-02-09 05:32PM -1 NT", | 101 "11-02-09 05:32PM -1 NT", |
| 98 "99-25-10 12:00AM 0", | 102 "99-25-10 12:00AM 0", |
| 99 "12-99-10 12:00AM 0", | 103 "12-99-10 12:00AM 0", |
| 100 "12-25-10 99:00AM 0", | 104 "12-25-10 99:00AM 0", |
| 101 "12-25-10 12:99AM 0", | 105 "12-25-10 12:99AM 0", |
| 102 "12-25-10 12:00ZM 0", | 106 "12-25-10 12:00ZM 0", |
| 103 "99-25-10 12:00AM 0 months out of range", | 107 "99-25-10 12:00AM 0 months out of range", |
| 104 "12-99-10 12:00AM 0 days out of range", | 108 "12-99-10 12:00AM 0 days out of range", |
| 105 "12-25-10 99:00AM 0 hours out of range", | 109 "12-25-10 99:00AM 0 hours out of range", |
| 106 "12-25-10 12:99AM 0 minutes out of range", | 110 "12-25-10 12:99AM 0 minutes out of range", |
| 107 "12-25-10 12:00ZM 0 what does ZM mean", | 111 "12-25-10 12:00ZM 0 what does ZM mean", |
| 108 }; | 112 }; |
| 109 for (size_t i = 0; i < arraysize(bad_cases); i++) { | 113 for (size_t i = 0; i < arraysize(bad_cases); i++) { |
| 110 net::FtpDirectoryListingParserWindows parser; | 114 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
| 111 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i]; | 115 bad_cases[i])); |
| 116 |
| 117 std::vector<FtpDirectoryListingEntry> entries; |
| 118 EXPECT_FALSE(ParseFtpDirectoryListingWindows( |
| 119 GetSingleLineTestCase(bad_cases[i]), |
| 120 &entries)); |
| 112 } | 121 } |
| 113 } | 122 } |
| 114 | 123 |
| 115 } // namespace | 124 } // namespace |
| 125 |
| 126 } // namespace net |
| OLD | NEW |