Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / ftp / ftp_directory_listing_parser_os2_unittest.cc
blob7302f4c9a9d33687a3f0984d1971c952072faa12
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/strings/string_util.h"
9 #include "base/strings/stringprintf.h"
10 #include "net/ftp/ftp_directory_listing_parser_os2.h"
12 namespace net {
14 namespace {
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,
25 2009, 1, 6, 14, 42 },
26 { "1 A 01-06-09 02:42 Readme.txt",
27 FtpDirectoryListingEntry::FILE, "Readme.txt", 1,
28 2009, 1, 6, 2, 42 },
29 { "458 A 01-06-01 02:42 Readme.txt",
30 FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
31 2001, 1, 6, 2, 42 },
32 { "458 A 01-06-00 02:42 Corner1.txt",
33 FtpDirectoryListingEntry::FILE, "Corner1.txt", 458,
34 2000, 1, 6, 2, 42 },
35 { "458 A 01-06-99 02:42 Corner2.txt",
36 FtpDirectoryListingEntry::FILE, "Corner2.txt", 458,
37 1999, 1, 6, 2, 42 },
38 { "458 A 01-06-80 02:42 Corner3.txt",
39 FtpDirectoryListingEntry::FILE, "Corner3.txt", 458,
40 1980, 1, 6, 2, 42 },
41 { "458 A 01-06-1979 02:42 Readme.txt",
42 FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
43 1979, 1, 6, 2, 42 },
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,
49 2010, 12, 25, 0, 0 },
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),
61 &entries));
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,
73 ignored_cases[i]));
75 std::vector<FtpDirectoryListingEntry> entries;
76 EXPECT_TRUE(ParseFtpDirectoryListingOS2(
77 GetSingleLineTestCase(ignored_cases[i]),
78 &entries));
79 EXPECT_EQ(0U, entries.size());
83 TEST_F(FtpDirectoryListingParserOS2Test, Bad) {
84 const char* bad_cases[] = {
85 "garbage",
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",
89 "0 DIR 11-02 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",
94 "0 A 99-25-10 12:00",
95 "0 A 12-99-10 12:00",
96 "0 A 12-25-10 99:00",
97 "0 A 12-25-10 12:99",
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,
105 bad_cases[i]));
107 std::vector<FtpDirectoryListingEntry> entries;
108 EXPECT_FALSE(ParseFtpDirectoryListingOS2(
109 GetSingleLineTestCase(bad_cases[i]),
110 &entries));
114 } // namespace
116 } // namespace net