Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: net/ftp/ftp_directory_listing_parser_vms_unittest.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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,
47 2005, 3, 12, 8, 44 },
48 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (ED,RED,WD,WED)",
49 FtpDirectoryListingEntry::FILE, "announce.txt", 512,
50 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 }; 46 };
55 for (size_t i = 0; i < arraysize(good_cases); i++) { 47 for (size_t i = 0; i < arraysize(good_cases); i++) {
56 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, 48 SCOPED_TRACE(
57 good_cases[i].input)); 49 base::StringPrintf("Test[%" PRIuS "]: %s", i, good_cases[i].input));
58 50
59 std::vector<base::string16> lines( 51 std::vector<base::string16> lines(
60 GetSingleLineTestCase(good_cases[i].input)); 52 GetSingleLineTestCase(good_cases[i].input));
61 53
62 // The parser requires a directory header before accepting regular input. 54 // The parser requires a directory header before accepting regular input.
63 lines.insert(lines.begin(), 55 lines.insert(lines.begin(),
64 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]")); 56 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]"));
65 57
66 // A valid listing must also have a "Total" line at the end. 58 // A valid listing must also have a "Total" line at the end.
67 lines.insert(lines.end(), 59 lines.insert(lines.end(), ASCIIToUTF16("Total of 1 file, 2 blocks."));
68 ASCIIToUTF16("Total of 1 file, 2 blocks."));
69 60
70 std::vector<FtpDirectoryListingEntry> entries; 61 std::vector<FtpDirectoryListingEntry> entries;
71 EXPECT_TRUE(ParseFtpDirectoryListingVms(lines, 62 EXPECT_TRUE(ParseFtpDirectoryListingVms(lines, &entries));
72 &entries));
73 VerifySingleLineTestCase(good_cases[i], entries); 63 VerifySingleLineTestCase(good_cases[i], entries);
74 } 64 }
75 } 65 }
76 66
77 TEST_F(FtpDirectoryListingParserVmsTest, Bad) { 67 TEST_F(FtpDirectoryListingParserVmsTest, Bad) {
78 const char* bad_cases[] = { 68 const char* bad_cases[] = {
79 "garbage", 69 "garbage",
80 70
81 // Missing file version number. 71 // Missing file version number.
82 "README.TXT 2 18-APR-2000 10:40:39", 72 "README.TXT 2 18-APR-2000 10:40:39",
83 73
84 // Missing extension. 74 // Missing extension.
85 "README;1 2 18-APR-2000 10:40:39", 75 "README;1 2 18-APR-2000 10:40:39",
86 76
87 // Malformed file size. 77 // Malformed file size.
88 "README.TXT;1 garbage 18-APR-2000 10:40:39", 78 "README.TXT;1 garbage 18-APR-2000 10:40:39",
89 "README.TXT;1 -2 18-APR-2000 10:40:39", 79 "README.TXT;1 -2 18-APR-2000 10:40:39",
90 80
91 // Malformed date. 81 // Malformed date.
92 "README.TXT;1 2 APR-2000 10:40:39", 82 "README.TXT;1 2 APR-2000 10:40:39",
93 "README.TXT;1 2 -18-APR-2000 10:40:39", 83 "README.TXT;1 2 -18-APR-2000 10:40:39",
94 "README.TXT;1 2 18-APR 10:40:39", 84 "README.TXT;1 2 18-APR 10:40:39",
95 "README.TXT;1 2 18-APR-2000 10", 85 "README.TXT;1 2 18-APR-2000 10",
96 "README.TXT;1 2 18-APR-2000 10:40.25", 86 "README.TXT;1 2 18-APR-2000 10:40.25",
97 "README.TXT;1 2 18-APR-2000 10:40.25.25", 87 "README.TXT;1 2 18-APR-2000 10:40.25.25",
98 88
99 // Malformed security information. 89 // Malformed security information.
100 "X.TXT;2 1 12-MAR-2005 08:44:57 (RWED,RWED,RE,RE)", 90 "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]", 91 "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)", 92 "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]", 93 "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)", 94 "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)", 95 "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)", 96 "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)", 97 "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)", 98 "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)", 99 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RRWWEEDD,RE,RE)",
110 }; 100 };
111 for (size_t i = 0; i < arraysize(bad_cases); i++) { 101 for (size_t i = 0; i < arraysize(bad_cases); i++) {
112 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i])); 102 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i]));
113 103
114 std::vector<base::string16> lines(GetSingleLineTestCase(bad_cases[i])); 104 std::vector<base::string16> lines(GetSingleLineTestCase(bad_cases[i]));
115 105
116 // The parser requires a directory header before accepting regular input. 106 // The parser requires a directory header before accepting regular input.
117 lines.insert(lines.begin(), 107 lines.insert(lines.begin(),
118 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]")); 108 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]"));
119 109
120 // A valid listing must also have a "Total" line at the end. 110 // A valid listing must also have a "Total" line at the end.
121 lines.insert(lines.end(), 111 lines.insert(lines.end(), ASCIIToUTF16("Total of 1 file, 2 blocks."));
122 ASCIIToUTF16("Total of 1 file, 2 blocks."));
123 112
124 std::vector<FtpDirectoryListingEntry> entries; 113 std::vector<FtpDirectoryListingEntry> entries;
125 EXPECT_FALSE(ParseFtpDirectoryListingVms(lines, 114 EXPECT_FALSE(ParseFtpDirectoryListingVms(lines, &entries));
126 &entries));
127 } 115 }
128 } 116 }
129 117
130 TEST_F(FtpDirectoryListingParserVmsTest, BadDataAfterFooter) { 118 TEST_F(FtpDirectoryListingParserVmsTest, BadDataAfterFooter) {
131 const char* bad_cases[] = { 119 const char* bad_cases[] = {
132 "garbage", 120 "garbage", "Total of 1 file, 2 blocks.",
133 "Total of 1 file, 2 blocks.", 121 "Directory ANYNYMOUS_ROOT:[000000]",
134 "Directory ANYNYMOUS_ROOT:[000000]",
135 }; 122 };
136 for (size_t i = 0; i < arraysize(bad_cases); i++) { 123 for (size_t i = 0; i < arraysize(bad_cases); i++) {
137 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i])); 124 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i]));
138 125
139 std::vector<base::string16> lines( 126 std::vector<base::string16> lines(
140 GetSingleLineTestCase("README.TXT;4 2 18-APR-2000 10:40:39.90")); 127 GetSingleLineTestCase("README.TXT;4 2 18-APR-2000 10:40:39.90"));
141 128
142 // The parser requires a directory header before accepting regular input. 129 // The parser requires a directory header before accepting regular input.
143 lines.insert(lines.begin(), 130 lines.insert(lines.begin(),
144 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]")); 131 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]"));
145 132
146 // A valid listing must also have a "Total" line at the end. 133 // A valid listing must also have a "Total" line at the end.
147 lines.insert(lines.end(), 134 lines.insert(lines.end(), ASCIIToUTF16("Total of 1 file, 2 blocks."));
148 ASCIIToUTF16("Total of 1 file, 2 blocks."));
149 135
150 { 136 {
151 // Make sure the listing is valid before we add data after footer. 137 // Make sure the listing is valid before we add data after footer.
152 std::vector<FtpDirectoryListingEntry> entries; 138 std::vector<FtpDirectoryListingEntry> entries;
153 EXPECT_TRUE(ParseFtpDirectoryListingVms(lines, 139 EXPECT_TRUE(ParseFtpDirectoryListingVms(lines, &entries));
154 &entries));
155 } 140 }
156 141
157 { 142 {
158 // Insert a line at the end of the listing that should make it invalid. 143 // Insert a line at the end of the listing that should make it invalid.
159 lines.insert(lines.end(), 144 lines.insert(lines.end(), ASCIIToUTF16(bad_cases[i]));
160 ASCIIToUTF16(bad_cases[i]));
161 std::vector<FtpDirectoryListingEntry> entries; 145 std::vector<FtpDirectoryListingEntry> entries;
162 EXPECT_FALSE(ParseFtpDirectoryListingVms(lines, 146 EXPECT_FALSE(ParseFtpDirectoryListingVms(lines, &entries));
163 &entries));
164 } 147 }
165 } 148 }
166 } 149 }
167 150
168 } // namespace 151 } // namespace
169 152
170 } // namespace net 153 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698