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_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/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "net/ftp/ftp_directory_listing_parser_vms.h" | 12 #include "net/ftp/ftp_directory_listing_parser_vms.h" |
13 | 13 |
14 using base::ASCIIToUTF16; | 14 using base::ASCIIToUTF16; |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 typedef FtpDirectoryListingParserTest FtpDirectoryListingParserVmsTest; | 20 typedef FtpDirectoryListingParserTest FtpDirectoryListingParserVmsTest; |
21 | 21 |
22 TEST_F(FtpDirectoryListingParserVmsTest, Good) { | 22 TEST_F(FtpDirectoryListingParserVmsTest, Good) { |
23 const struct SingleLineTestData good_cases[] = { | 23 const struct SingleLineTestData good_cases[] = { |
24 { "README.TXT;4 2 18-APR-2000 10:40:39.90", | 24 {"README.TXT;4 2 18-APR-2000 10:40:39.90", |
25 FtpDirectoryListingEntry::FILE, "readme.txt", 1024, | 25 FtpDirectoryListingEntry::FILE, "readme.txt", 1024, 2000, 4, 18, 10, 40}, |
26 2000, 4, 18, 10, 40 }, | 26 {".WELCOME;1 2 13-FEB-2002 23:32:40.47", |
27 { ".WELCOME;1 2 13-FEB-2002 23:32:40.47", | 27 FtpDirectoryListingEntry::FILE, ".welcome", 1024, 2002, 2, 13, 23, 32}, |
28 FtpDirectoryListingEntry::FILE, ".welcome", 1024, | 28 {"FILE.;1 2 13-FEB-2002 23:32:40.47", FtpDirectoryListingEntry::FILE, |
29 2002, 2, 13, 23, 32 }, | 29 "file.", 1024, 2002, 2, 13, 23, 32}, |
30 { "FILE.;1 2 13-FEB-2002 23:32:40.47", | 30 {"EXAMPLE.TXT;1 1 4-NOV-2009 06:02 [JOHNDOE] (RWED,RWED,,)", |
31 FtpDirectoryListingEntry::FILE, "file.", 1024, | 31 FtpDirectoryListingEntry::FILE, "example.txt", 512, 2009, 11, 4, 6, 2}, |
32 2002, 2, 13, 23, 32 }, | 32 {"ANNOUNCE.TXT;2 1/16 12-MAR-2005 08:44:57 [SYSTEM] (RWED,RWED,RE,RE)", |
33 { "EXAMPLE.TXT;1 1 4-NOV-2009 06:02 [JOHNDOE] (RWED,RWED,,)", | 33 FtpDirectoryListingEntry::FILE, "announce.txt", 512, 2005, 3, 12, 8, 44}, |
34 FtpDirectoryListingEntry::FILE, "example.txt", 512, | 34 {"TEST.DIR;1 1 4-MAR-1999 22:14:34 [UCX$NOBO,ANONYMOUS] " |
35 2009, 11, 4, 6, 2 }, | 35 "(RWE,RWE,RWE,RWE)", |
36 { "ANNOUNCE.TXT;2 1/16 12-MAR-2005 08:44:57 [SYSTEM] (RWED,RWED,RE,RE)", | 36 FtpDirectoryListingEntry::DIRECTORY, "test", -1, 1999, 3, 4, 22, 14}, |
37 FtpDirectoryListingEntry::FILE, "announce.txt", 512, | 37 {"ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (,,,)", |
38 2005, 3, 12, 8, 44 }, | 38 FtpDirectoryListingEntry::FILE, "announce.txt", 512, 2005, 3, 12, 8, 44}, |
39 { "TEST.DIR;1 1 4-MAR-1999 22:14:34 [UCX$NOBO,ANONYMOUS] (RWE,RWE,RWE,RWE)", | 39 {"ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (R,RW,RWD,RE)", |
40 FtpDirectoryListingEntry::DIRECTORY, "test", -1, | 40 FtpDirectoryListingEntry::FILE, "announce.txt", 512, 2005, 3, 12, 8, 44}, |
41 1999, 3, 4, 22, 14 }, | 41 {"ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (ED,RED,WD,WED)", |
42 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (,,,)", | 42 FtpDirectoryListingEntry::FILE, "announce.txt", 512, 2005, 3, 12, 8, 44}, |
43 FtpDirectoryListingEntry::FILE, "announce.txt", 512, | 43 {"VMS721.ISO;2 ****** 6-MAY-2008 09:29 [ANONY,ANONYMOUS] " |
44 2005, 3, 12, 8, 44 }, | 44 "(RE,RWED,RE,RE)", |
45 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (R,RW,RWD,RE)", | 45 FtpDirectoryListingEntry::FILE, "vms721.iso", -1, 2008, 5, 6, 9, 29}, |
46 FtpDirectoryListingEntry::FILE, "announce.txt", 512, | 46 // This has an unusually large allocated block size (INT64_MAX), but |
47 2005, 3, 12, 8, 44 }, | 47 // shouldn't matter as it is not used. |
48 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (ED,RED,WD,WED)", | 48 {"ANNOUNCE.TXT;2 1/9223372036854775807 12-MAR-2005 08:44:57 [SYSTEM] " |
49 FtpDirectoryListingEntry::FILE, "announce.txt", 512, | 49 "(RWED,RWED,RE,RE)", |
50 2005, 3, 12, 8, 44 }, | 50 FtpDirectoryListingEntry::FILE, "announce.txt", 512, 2005, 3, 12, 8, 44}, |
51 { "VMS721.ISO;2 ****** 6-MAY-2008 09:29 [ANONY,ANONYMOUS] (RE,RWED,RE,RE)", | |
52 FtpDirectoryListingEntry::FILE, "vms721.iso", -1, | |
53 2008, 5, 6, 9, 29 }, | |
54 }; | 51 }; |
55 for (size_t i = 0; i < arraysize(good_cases); i++) { | 52 for (size_t i = 0; i < arraysize(good_cases); i++) { |
56 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, | 53 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
57 good_cases[i].input)); | 54 good_cases[i].input)); |
58 | 55 |
59 std::vector<base::string16> lines( | 56 std::vector<base::string16> lines( |
60 GetSingleLineTestCase(good_cases[i].input)); | 57 GetSingleLineTestCase(good_cases[i].input)); |
61 | 58 |
62 // The parser requires a directory header before accepting regular input. | 59 // The parser requires a directory header before accepting regular input. |
63 lines.insert(lines.begin(), | 60 lines.insert(lines.begin(), |
64 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]")); | 61 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]")); |
65 | 62 |
66 // A valid listing must also have a "Total" line at the end. | 63 // A valid listing must also have a "Total" line at the end. |
67 lines.insert(lines.end(), | 64 lines.insert(lines.end(), |
68 ASCIIToUTF16("Total of 1 file, 2 blocks.")); | 65 ASCIIToUTF16("Total of 1 file, 2 blocks.")); |
69 | 66 |
70 std::vector<FtpDirectoryListingEntry> entries; | 67 std::vector<FtpDirectoryListingEntry> entries; |
71 EXPECT_TRUE(ParseFtpDirectoryListingVms(lines, | 68 EXPECT_TRUE(ParseFtpDirectoryListingVms(lines, |
72 &entries)); | 69 &entries)); |
73 VerifySingleLineTestCase(good_cases[i], entries); | 70 VerifySingleLineTestCase(good_cases[i], entries); |
74 } | 71 } |
75 } | 72 } |
76 | 73 |
77 TEST_F(FtpDirectoryListingParserVmsTest, Bad) { | 74 TEST_F(FtpDirectoryListingParserVmsTest, Bad) { |
78 const char* const bad_cases[] = { | 75 const char* const bad_cases[] = { |
79 "garbage", | 76 "garbage", |
80 | 77 |
81 // Missing file version number. | 78 // Missing file version number. |
82 "README.TXT 2 18-APR-2000 10:40:39", | 79 "README.TXT 2 18-APR-2000 10:40:39", |
83 | 80 |
84 // Missing extension. | 81 // Missing extension. |
85 "README;1 2 18-APR-2000 10:40:39", | 82 "README;1 2 18-APR-2000 10:40:39", |
86 | 83 |
87 // Malformed file size. | 84 // Malformed file size. |
88 "README.TXT;1 garbage 18-APR-2000 10:40:39", | 85 "README.TXT;1 garbage 18-APR-2000 10:40:39", |
89 "README.TXT;1 -2 18-APR-2000 10:40:39", | 86 "README.TXT;1 -2 18-APR-2000 10:40:39", |
90 | 87 |
91 // Malformed date. | 88 // Malformed date. |
92 "README.TXT;1 2 APR-2000 10:40:39", | 89 "README.TXT;1 2 APR-2000 10:40:39", |
93 "README.TXT;1 2 -18-APR-2000 10:40:39", | 90 "README.TXT;1 2 -18-APR-2000 10:40:39", "README.TXT;1 2 18-APR 10:40:39", |
94 "README.TXT;1 2 18-APR 10:40:39", | 91 "README.TXT;1 2 18-APR-2000 10", "README.TXT;1 2 18-APR-2000 10:40.25", |
95 "README.TXT;1 2 18-APR-2000 10", | 92 "README.TXT;1 2 18-APR-2000 10:40.25.25", |
96 "README.TXT;1 2 18-APR-2000 10:40.25", | |
97 "README.TXT;1 2 18-APR-2000 10:40.25.25", | |
98 | 93 |
99 // Malformed security information. | 94 // Malformed security information. |
100 "X.TXT;2 1 12-MAR-2005 08:44:57 (RWED,RWED,RE,RE)", | 95 "X.TXT;2 1 12-MAR-2005 08:44:57 (RWED,RWED,RE,RE)", |
101 "X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM]", | 96 "X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM]", |
102 "X.TXT;2 1 12-MAR-2005 08:44:57 (SYSTEM) (RWED,RWED,RE,RE)", | 97 "X.TXT;2 1 12-MAR-2005 08:44:57 (SYSTEM) (RWED,RWED,RE,RE)", |
103 "X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM] [RWED,RWED,RE,RE]", | 98 "X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM] [RWED,RWED,RE,RE]", |
104 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED)", | 99 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED)", |
105 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,RE,RE,RE)", | 100 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,RE,RE,RE)", |
106 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWEDRWED,RE,RE)", | 101 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWEDRWED,RE,RE)", |
107 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,DEWR,RE,RE)", | 102 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,DEWR,RE,RE)", |
108 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,Q,RE)", | 103 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,Q,RE)", |
109 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RRWWEEDD,RE,RE)", | 104 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RRWWEEDD,RE,RE)", |
| 105 |
| 106 // Block size (INT64_MAX) is too large -- will overflow when |
| 107 // multiplying by 512 to calculate the file size in bytes. |
| 108 "README.TXT;1 9223372036854775807 18-APR-2000 10:40:39.90", |
| 109 "README.TXT;1 9223372036854775807/9223372036854775807 18-APR-2000 " |
| 110 "10:40:39.90", |
| 111 |
| 112 // Block size (larger than INT64_MAX) is too large -- will fail to |
| 113 // parse to an int64_t |
| 114 "README.TXT;1 19223372036854775807 18-APR-2000 10:40:39.90", |
| 115 "README.TXT;1 19223372036854775807/19223372036854775807 18-APR-2000 " |
| 116 "10:40:39.90", |
110 }; | 117 }; |
111 for (size_t i = 0; i < arraysize(bad_cases); i++) { | 118 for (size_t i = 0; i < arraysize(bad_cases); i++) { |
112 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i])); | 119 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i])); |
113 | 120 |
114 std::vector<base::string16> lines(GetSingleLineTestCase(bad_cases[i])); | 121 std::vector<base::string16> lines(GetSingleLineTestCase(bad_cases[i])); |
115 | 122 |
116 // The parser requires a directory header before accepting regular input. | 123 // The parser requires a directory header before accepting regular input. |
117 lines.insert(lines.begin(), | 124 lines.insert(lines.begin(), |
118 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]")); | 125 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]")); |
119 | 126 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 193 |
187 lines.push_back(ASCIIToUTF16(" ")); | 194 lines.push_back(ASCIIToUTF16(" ")); |
188 | 195 |
189 std::vector<FtpDirectoryListingEntry> entries; | 196 std::vector<FtpDirectoryListingEntry> entries; |
190 EXPECT_FALSE(ParseFtpDirectoryListingVms(lines, &entries)); | 197 EXPECT_FALSE(ParseFtpDirectoryListingVms(lines, &entries)); |
191 } | 198 } |
192 | 199 |
193 } // namespace | 200 } // namespace |
194 | 201 |
195 } // namespace net | 202 } // namespace net |
OLD | NEW |