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
3 // found in the LICENSE file.
5 #include "net/ftp/ftp_directory_listing_parser_unittest.h"
7 #include "base/format_macros.h"
8 #include "base/string_util.h"
9 #include "base/stringprintf.h"
10 #include "net/ftp/ftp_directory_listing_parser_os2.h"
16 typedef FtpDirectoryListingParserTest FtpDirectoryListingParserOS2Test
;
18 TEST_F(FtpDirectoryListingParserOS2Test
, Good
) {
19 const struct SingleLineTestData good_cases
[] = {
20 { "0 DIR 11-02-09 17:32 NT",
21 FtpDirectoryListingEntry::DIRECTORY
, "NT", -1,
22 2009, 11, 2, 17, 32 },
23 { "458 A 01-06-09 14:42 Readme.txt",
24 FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
26 { "1 A 01-06-09 02:42 Readme.txt",
27 FtpDirectoryListingEntry::FILE, "Readme.txt", 1,
29 { "458 A 01-06-01 02:42 Readme.txt",
30 FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
32 { "458 A 01-06-00 02:42 Corner1.txt",
33 FtpDirectoryListingEntry::FILE, "Corner1.txt", 458,
35 { "458 A 01-06-99 02:42 Corner2.txt",
36 FtpDirectoryListingEntry::FILE, "Corner2.txt", 458,
38 { "458 A 01-06-80 02:42 Corner3.txt",
39 FtpDirectoryListingEntry::FILE, "Corner3.txt", 458,
41 { "458 A 01-06-1979 02:42 Readme.txt",
42 FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
44 { "0 DIR 11-02-09 17:32 My Directory",
45 FtpDirectoryListingEntry::DIRECTORY
, "My Directory", -1,
46 2009, 11, 2, 17, 32 },
47 { "0 DIR 12-25-10 00:00 Christmas Midnight",
48 FtpDirectoryListingEntry::DIRECTORY
, "Christmas Midnight", -1,
50 { "0 DIR 12-25-10 12:00 Christmas Midday",
51 FtpDirectoryListingEntry::DIRECTORY
, "Christmas Midday", -1,
52 2010, 12, 25, 12, 0 },
54 for (size_t i
= 0; i
< arraysize(good_cases
); i
++) {
55 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS
"]: %s", i
,
56 good_cases
[i
].input
));
58 std::vector
<FtpDirectoryListingEntry
> entries
;
59 EXPECT_TRUE(ParseFtpDirectoryListingOS2(
60 GetSingleLineTestCase(good_cases
[i
].input
),
62 VerifySingleLineTestCase(good_cases
[i
], entries
);
66 TEST_F(FtpDirectoryListingParserOS2Test
, Ignored
) {
67 const char* ignored_cases
[] = {
68 "1234 A 12-07-10 12:05",
69 "0 DIR 11-02-09 05:32",
71 for (size_t i
= 0; i
< arraysize(ignored_cases
); i
++) {
72 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS
"]: %s", i
,
75 std::vector
<FtpDirectoryListingEntry
> entries
;
76 EXPECT_TRUE(ParseFtpDirectoryListingOS2(
77 GetSingleLineTestCase(ignored_cases
[i
]),
79 EXPECT_EQ(0U, entries
.size());
83 TEST_F(FtpDirectoryListingParserOS2Test
, Bad
) {
84 const char* bad_cases
[] = {
86 "0 GARBAGE 11-02-09 05:32",
87 "0 GARBAGE 11-02-09 05:32 NT",
88 "0 DIR 11-FEB-09 05:32",
90 "-1 A 11-02-09 05:32",
91 "0 DIR 11-FEB-09 05:32",
92 "0 DIR 11-02 05:32 NT",
93 "-1 A 11-02-09 05:32 NT",
98 "0 A 99-25-10 12:00 months out of range",
99 "0 A 12-99-10 12:00 days out of range",
100 "0 A 12-25-10 99:00 hours out of range",
101 "0 A 12-25-10 12:99 minutes out of range",
103 for (size_t i
= 0; i
< arraysize(bad_cases
); i
++) {
104 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS
"]: %s", i
,
107 std::vector
<FtpDirectoryListingEntry
> entries
;
108 EXPECT_FALSE(ParseFtpDirectoryListingOS2(
109 GetSingleLineTestCase(bad_cases
[i
]),