| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/ftp/ftp_directory_listing_parser_unittest.h" |
| 6 |
| 7 #include "base/format_macros.h" |
| 8 #include "net/ftp/ftp_directory_listing_parser_vms.h" |
| 9 |
| 10 namespace { |
| 11 |
| 12 typedef net::FtpDirectoryListingParserTest FtpDirectoryListingParserVmsTest; |
| 13 |
| 14 TEST_F(FtpDirectoryListingParserVmsTest, Good) { |
| 15 const struct SingleLineTestData good_cases[] = { |
| 16 { "README.TXT;4 2 18-APR-2000 10:40:39.90", |
| 17 net::FtpDirectoryListingEntry::FILE, "readme.txt", 1024, |
| 18 2000, 4, 18, 10, 40 }, |
| 19 { ".WELCOME;1 2 13-FEB-2002 23:32:40.47", |
| 20 net::FtpDirectoryListingEntry::FILE, ".welcome", 1024, |
| 21 2002, 2, 13, 23, 32 }, |
| 22 { "FILE.;1 2 13-FEB-2002 23:32:40.47", |
| 23 net::FtpDirectoryListingEntry::FILE, "file.", 1024, |
| 24 2002, 2, 13, 23, 32 }, |
| 25 { "EXAMPLE.TXT;1 1 4-NOV-2009 06:02 [JOHNDOE] (RWED,RWED,,)", |
| 26 net::FtpDirectoryListingEntry::FILE, "example.txt", 512, |
| 27 2009, 11, 4, 6, 2 }, |
| 28 { "ANNOUNCE.TXT;2 1/16 12-MAR-2005 08:44:57 [SYSTEM] (RWED,RWED,RE,RE)", |
| 29 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512, |
| 30 2005, 3, 12, 8, 44 }, |
| 31 { "TEST.DIR;1 1 4-MAR-1999 22:14:34 [UCX$NOBO,ANONYMOUS] (RWE,RWE,RWE,RWE)", |
| 32 net::FtpDirectoryListingEntry::DIRECTORY, "test", -1, |
| 33 1999, 3, 4, 22, 14 }, |
| 34 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (,,,)", |
| 35 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512, |
| 36 2005, 3, 12, 8, 44 }, |
| 37 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (R,RW,RWD,RE)", |
| 38 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512, |
| 39 2005, 3, 12, 8, 44 }, |
| 40 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (ED,RED,WD,WED)", |
| 41 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512, |
| 42 2005, 3, 12, 8, 44 }, |
| 43 }; |
| 44 for (size_t i = 0; i < arraysize(good_cases); i++) { |
| 45 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, good_cases[i].input)); |
| 46 |
| 47 net::FtpDirectoryListingParserVms parser; |
| 48 ASSERT_TRUE( |
| 49 parser.ConsumeLine(ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]"))); |
| 50 RunSingleLineTestCase(&parser, good_cases[i]); |
| 51 } |
| 52 } |
| 53 |
| 54 TEST_F(FtpDirectoryListingParserVmsTest, Bad) { |
| 55 const char* bad_cases[] = { |
| 56 "Directory ROOT|garbage", |
| 57 |
| 58 // Missing file version number. |
| 59 "Directory ROOT|README.TXT 2 18-APR-2000 10:40:39", |
| 60 |
| 61 // Missing extension. |
| 62 "Directory ROOT|README;1 2 18-APR-2000 10:40:39", |
| 63 |
| 64 // Malformed file size. |
| 65 "Directory ROOT|README.TXT;1 garbage 18-APR-2000 10:40:39", |
| 66 "Directory ROOT|README.TXT;1 -2 18-APR-2000 10:40:39", |
| 67 |
| 68 // Malformed date. |
| 69 "Directory ROOT|README.TXT;1 2 APR-2000 10:40:39", |
| 70 "Directory ROOT|README.TXT;1 2 -18-APR-2000 10:40:39", |
| 71 "Directory ROOT|README.TXT;1 2 18-APR 10:40:39", |
| 72 "Directory ROOT|README.TXT;1 2 18-APR-2000 10", |
| 73 "Directory ROOT|README.TXT;1 2 18-APR-2000 10:40.25", |
| 74 "Directory ROOT|README.TXT;1 2 18-APR-2000 10:40.25.25", |
| 75 |
| 76 // Empty line inside the listing. |
| 77 "Directory ROOT|README.TXT;1 2 18-APR-2000 10:40:42" |
| 78 "||README.TXT;1 2 18-APR-2000 10:40:42", |
| 79 |
| 80 // Data after footer. |
| 81 "Directory ROOT|README.TXT;4 2 18-APR-2000 10:40:39" |
| 82 "||Total of 1 file|", |
| 83 "Directory ROOT|README.TXT;4 2 18-APR-2000 10:40:39" |
| 84 "||Total of 1 file|garbage", |
| 85 "Directory ROOT|README.TXT;4 2 18-APR-2000 10:40:39" |
| 86 "||Total of 1 file|Total of 1 file", |
| 87 |
| 88 // Malformed security information. |
| 89 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 (RWED,RWED,RE,RE)", |
| 90 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM]", |
| 91 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 (SYSTEM) (RWED,RWED,RE,RE)", |
| 92 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM] [RWED,RWED,RE,RE]", |
| 93 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED)", |
| 94 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,RE,RE,RE)", |
| 95 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWEDRWED,RE,RE)", |
| 96 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,DEWR,RE,RE)", |
| 97 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,Q,RE)", |
| 98 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RRWWEEDD,RE,RE)", |
| 99 }; |
| 100 for (size_t i = 0; i < arraysize(bad_cases); i++) { |
| 101 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i])); |
| 102 |
| 103 std::vector<std::string> lines; |
| 104 SplitString(bad_cases[i], '|', &lines); |
| 105 net::FtpDirectoryListingParserVms parser; |
| 106 bool failed = false; |
| 107 for (std::vector<std::string>::const_iterator i = lines.begin(); |
| 108 i != lines.end(); ++i) { |
| 109 if (!parser.ConsumeLine(UTF8ToUTF16(*i))) { |
| 110 failed = true; |
| 111 break; |
| 112 } |
| 113 } |
| 114 EXPECT_TRUE(failed); |
| 115 } |
| 116 } |
| 117 |
| 118 } // namespace |
| OLD | NEW |