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

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

Issue 348036: Implement VMS FTP directory listing parser. (Closed)
Patch Set: fix Created 11 years, 1 month 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
« no previous file with comments | « net/ftp/ftp_directory_listing_parsers.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 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_parsers.h" 5 #include "net/ftp/ftp_directory_listing_parsers.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
11 11
12 struct SingleLineTestData { 12 struct SingleLineTestData {
13 const char* input; 13 const char* input;
14 net::FtpDirectoryListingEntry::Type type; 14 net::FtpDirectoryListingEntry::Type type;
15 const char* filename; 15 const char* filename;
16 int64 size; 16 int64 size;
17 int year; 17 int year;
18 int month; 18 int month;
19 int day_of_month; 19 int day_of_month;
20 int hour; 20 int hour;
21 int minute; 21 int minute;
22 }; 22 };
23 23
24 class FtpDirectoryListingParsersTest : public testing::Test { 24 class FtpDirectoryListingParsersTest : public testing::Test {
25 protected: 25 protected:
26 FtpDirectoryListingParsersTest() { 26 FtpDirectoryListingParsersTest() {
27 } 27 }
28 28
29 void RunSingleLineTestCase(net::FtpDirectoryListingParser* parser, 29 void RunSingleLineTestCase(net::FtpDirectoryListingParser* parser,
30 const SingleLineTestData& test_case) { 30 const SingleLineTestData& test_case) {
31 ASSERT_TRUE(parser->ConsumeLine(UTF8ToUTF16(test_case.input))); 31 ASSERT_TRUE(parser->ConsumeLine(UTF8ToUTF16(test_case.input)));
32 ASSERT_TRUE(parser->EntryAvailable()); 32 ASSERT_TRUE(parser->EntryAvailable());
33 net::FtpDirectoryListingEntry entry = parser->PopEntry(); 33 net::FtpDirectoryListingEntry entry = parser->PopEntry();
34 EXPECT_EQ(test_case.type, entry.type); 34 EXPECT_EQ(test_case.type, entry.type);
35 EXPECT_EQ(UTF8ToUTF16(test_case.filename), entry.name); 35 EXPECT_EQ(UTF8ToUTF16(test_case.filename), entry.name);
36 EXPECT_EQ(test_case.size, entry.size); 36 EXPECT_EQ(test_case.size, entry.size);
37 37
38 base::Time::Exploded time_exploded; 38 base::Time::Exploded time_exploded;
39 entry.last_modified.LocalExplode(&time_exploded); 39 entry.last_modified.LocalExplode(&time_exploded);
40 EXPECT_EQ(test_case.year, time_exploded.year); 40 EXPECT_EQ(test_case.year, time_exploded.year);
41 EXPECT_EQ(test_case.month, time_exploded.month); 41 EXPECT_EQ(test_case.month, time_exploded.month);
42 EXPECT_EQ(test_case.day_of_month, time_exploded.day_of_month); 42 EXPECT_EQ(test_case.day_of_month, time_exploded.day_of_month);
43 EXPECT_EQ(test_case.hour, time_exploded.hour); 43 EXPECT_EQ(test_case.hour, time_exploded.hour);
44 EXPECT_EQ(test_case.minute, time_exploded.minute); 44 EXPECT_EQ(test_case.minute, time_exploded.minute);
45 EXPECT_EQ(0, time_exploded.second); 45 EXPECT_EQ(0, time_exploded.second);
46 EXPECT_EQ(0, time_exploded.millisecond); 46 EXPECT_EQ(0, time_exploded.millisecond);
47 } 47 }
48 48
49 private: 49 private:
50 DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingParsersTest); 50 DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingParsersTest);
51 }; 51 };
52 52
53 TEST_F(FtpDirectoryListingParsersTest, Ls) { 53 TEST_F(FtpDirectoryListingParsersTest, Ls) {
54 base::Time::Exploded now_exploded; 54 base::Time::Exploded now_exploded;
55 base::Time::Now().LocalExplode(&now_exploded); 55 base::Time::Now().LocalExplode(&now_exploded);
56 56
57 const struct SingleLineTestData good_cases[] = { 57 const struct SingleLineTestData good_cases[] = {
58 { "-rw-r--r-- 1 ftp ftp 528 Nov 01 2007 README", 58 { "-rw-r--r-- 1 ftp ftp 528 Nov 01 2007 README",
59 net::FtpDirectoryListingEntry::FILE, "README", 528, 59 net::FtpDirectoryListingEntry::FILE, "README", 528,
60 2007, 11, 1, 0, 0 }, 60 2007, 11, 1, 0, 0 },
61 { "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 directory", 61 { "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 directory",
62 net::FtpDirectoryListingEntry::DIRECTORY, "directory", -1, 62 net::FtpDirectoryListingEntry::DIRECTORY, "directory", -1,
63 now_exploded.year, 5, 15, 18, 11 }, 63 now_exploded.year, 5, 15, 18, 11 },
64 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub", 64 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub",
65 net::FtpDirectoryListingEntry::SYMLINK, "pub", -1, 65 net::FtpDirectoryListingEntry::SYMLINK, "pub", -1,
66 2008, 9, 18, 0, 0 }, 66 2008, 9, 18, 0, 0 },
67 { "lrwxrwxrwx 1 0 0 3 Oct 12 13:37 mirror -> pub", 67 { "lrwxrwxrwx 1 0 0 3 Oct 12 13:37 mirror -> pub",
68 net::FtpDirectoryListingEntry::SYMLINK, "mirror", -1, 68 net::FtpDirectoryListingEntry::SYMLINK, "mirror", -1,
69 now_exploded.year, 10, 12, 13, 37 }, 69 now_exploded.year, 10, 12, 13, 37 },
70 }; 70 };
71 for (size_t i = 0; i < arraysize(good_cases); i++) { 71 for (size_t i = 0; i < arraysize(good_cases); i++) {
72 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, good_cases[i].input)); 72 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, good_cases[i].input));
73 73
74 net::FtpLsDirectoryListingParser parser; 74 net::FtpLsDirectoryListingParser parser;
75 RunSingleLineTestCase(&parser, good_cases[i]); 75 RunSingleLineTestCase(&parser, good_cases[i]);
76 } 76 }
77 77
78 const char* bad_cases[] = { 78 const char* bad_cases[] = {
79 "", 79 "",
80 "garbage", 80 "garbage",
81 "-rw-r--r-- 1 ftp ftp", 81 "-rw-r--r-- 1 ftp ftp",
82 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README", 82 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README",
83 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README", 83 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README",
84 "qrwwr--r-- 1 ftp ftp 528 Nov 01 2007 README", 84 "qrwwr--r-- 1 ftp ftp 528 Nov 01 2007 README",
85 "-rw-r--r-- -1 ftp ftp 528 Nov 01 2007 README", 85 "-rw-r--r-- -1 ftp ftp 528 Nov 01 2007 README",
86 "-rw-r--r-- 1 ftp ftp -528 Nov 01 2007 README", 86 "-rw-r--r-- 1 ftp ftp -528 Nov 01 2007 README",
87 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README", 87 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README",
88 }; 88 };
89 for (size_t i = 0; i < arraysize(bad_cases); i++) { 89 for (size_t i = 0; i < arraysize(bad_cases); i++) {
90 net::FtpLsDirectoryListingParser parser; 90 net::FtpLsDirectoryListingParser parser;
91 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i]; 91 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i];
92 } 92 }
93 } 93 }
94 94
95 TEST_F(FtpDirectoryListingParsersTest, Vms) {
96 const struct SingleLineTestData good_cases[] = {
97 { "README.TXT;4 2 18-APR-2000 10:40:39.90",
98 net::FtpDirectoryListingEntry::FILE, "readme.txt", 1024,
99 2000, 4, 18, 10, 40 },
100 { ".WELCOME;1 2 13-FEB-2002 23:32:40.47",
101 net::FtpDirectoryListingEntry::FILE, ".welcome", 1024,
102 2002, 2, 13, 23, 32 },
103 { "FILE.;1 2 13-FEB-2002 23:32:40.47",
104 net::FtpDirectoryListingEntry::FILE, "file.", 1024,
105 2002, 2, 13, 23, 32 },
106 { "EXAMPLE.TXT;1 1 4-NOV-2009 06:02 [JOHNDOE] (RWED,RWED,,)",
107 net::FtpDirectoryListingEntry::FILE, "example.txt", 512,
108 2009, 11, 4, 6, 2 },
109 { "ANNOUNCE.TXT;2 1/16 12-MAR-2005 08:44:57 [SYSTEM] (RWED,RWED,RE,RE)",
110 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512,
111 2005, 3, 12, 8, 44 },
112 { "TEST.DIR;1 1 4-MAR-1999 22:14:34 [UCX$NOBO,ANONYMOUS] (RWE,RWE,RWE,RWE)",
113 net::FtpDirectoryListingEntry::DIRECTORY, "test", -1,
114 1999, 3, 4, 22, 14 },
115 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (,,,)",
116 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512,
117 2005, 3, 12, 8, 44 },
118 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (R,RW,RWD,RE)",
119 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512,
120 2005, 3, 12, 8, 44 },
121 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (ED,RED,WD,WED)",
122 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512,
123 2005, 3, 12, 8, 44 },
124 };
125 for (size_t i = 0; i < arraysize(good_cases); i++) {
126 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, good_cases[i].input));
127
128 net::FtpVmsDirectoryListingParser parser;
129 ASSERT_TRUE(
130 parser.ConsumeLine(ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]")));
131 RunSingleLineTestCase(&parser, good_cases[i]);
132 }
133
134 const char* bad_cases[] = {
135 "Directory ROOT|garbage",
136
137 // Missing file version number.
138 "Directory ROOT|README.TXT 2 18-APR-2000 10:40:39",
139
140 // Missing extension.
141 "Directory ROOT|README;1 2 18-APR-2000 10:40:39",
142
143 // Malformed file size.
144 "Directory ROOT|README.TXT;1 garbage 18-APR-2000 10:40:39",
145 "Directory ROOT|README.TXT;1 -2 18-APR-2000 10:40:39",
146
147 // Malformed date.
148 "Directory ROOT|README.TXT;1 2 APR-2000 10:40:39",
149 "Directory ROOT|README.TXT;1 2 -18-APR-2000 10:40:39",
150 "Directory ROOT|README.TXT;1 2 18-APR 10:40:39",
151 "Directory ROOT|README.TXT;1 2 18-APR-2000 10",
152 "Directory ROOT|README.TXT;1 2 18-APR-2000 10:40.25",
153 "Directory ROOT|README.TXT;1 2 18-APR-2000 10:40.25.25",
154
155 // Empty line inside the listing.
156 "Directory ROOT|README.TXT;1 2 18-APR-2000 10:40:42"
157 "||README.TXT;1 2 18-APR-2000 10:40:42",
158
159 // Data after footer.
160 "Directory ROOT|README.TXT;4 2 18-APR-2000 10:40:39"
161 "||Total of 1 file|",
162 "Directory ROOT|README.TXT;4 2 18-APR-2000 10:40:39"
163 "||Total of 1 file|garbage",
164 "Directory ROOT|README.TXT;4 2 18-APR-2000 10:40:39"
165 "||Total of 1 file|Total of 1 file",
166
167 // Malformed security information.
168 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 (RWED,RWED,RE,RE)",
169 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM]",
170 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 (SYSTEM) (RWED,RWED,RE,RE)",
171 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM] [RWED,RWED,RE,RE]",
172 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED)",
173 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,RE,RE,RE)",
174 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWEDRWED,RE,RE)",
175 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,DEWR,RE,RE)",
176 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,Q,RE)",
177 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RRWWEEDD,RE,RE)",
178 };
179 for (size_t i = 0; i < arraysize(bad_cases); i++) {
180 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, bad_cases[i]));
181
182 std::vector<std::string> lines;
183 SplitString(bad_cases[i], '|', &lines);
184 net::FtpVmsDirectoryListingParser parser;
185 bool failed = false;
186 for (std::vector<std::string>::const_iterator i = lines.begin();
187 i != lines.end(); ++i) {
188 if (!parser.ConsumeLine(UTF8ToUTF16(*i))) {
189 failed = true;
190 break;
191 }
192 }
193 EXPECT_TRUE(failed);
194 }
195 }
196
95 } // namespace 197 } // namespace
OLDNEW
« no previous file with comments | « net/ftp/ftp_directory_listing_parsers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698