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

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

Issue 374010: Implement Windows FTP directory listing parser. (Closed)
Patch Set: fixes 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 {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 "-rw-r--r-- -1 ftp ftp 528 Nov 01 2007 README", 84 "-rw-r--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 Foo 01 2007 README", 86 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README",
87 }; 87 };
88 for (size_t i = 0; i < arraysize(bad_cases); i++) { 88 for (size_t i = 0; i < arraysize(bad_cases); i++) {
89 net::FtpLsDirectoryListingParser parser; 89 net::FtpLsDirectoryListingParser parser;
90 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i]; 90 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i];
91 } 91 }
92 } 92 }
93 93
94 TEST_F(FtpDirectoryListingParsersTest, Windows) {
95 base::Time::Exploded now_exploded;
96 base::Time::Now().LocalExplode(&now_exploded);
97
98 const struct SingleLineTestData good_cases[] = {
99 { "11-02-09 05:32PM <DIR> NT",
100 net::FtpDirectoryListingEntry::DIRECTORY, "NT", -1,
101 2009, 11, 2, 17, 32 },
102 { "01-06-09 02:42PM 458 Readme.txt",
103 net::FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
104 2009, 1, 6, 14, 42 },
105 { "01-06-09 02:42AM 1 Readme.txt",
106 net::FtpDirectoryListingEntry::FILE, "Readme.txt", 1,
107 2009, 1, 6, 2, 42 },
108 { "01-06-01 02:42AM 458 Readme.txt",
109 net::FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
110 2001, 1, 6, 2, 42 },
111 { "01-06-00 02:42AM 458 Corner1.txt",
112 net::FtpDirectoryListingEntry::FILE, "Corner1.txt", 458,
113 2000, 1, 6, 2, 42 },
114 { "01-06-99 02:42AM 458 Corner2.txt",
115 net::FtpDirectoryListingEntry::FILE, "Corner2.txt", 458,
116 1999, 1, 6, 2, 42 },
117 { "01-06-80 02:42AM 458 Corner3.txt",
118 net::FtpDirectoryListingEntry::FILE, "Corner3.txt", 458,
119 1980, 1, 6, 2, 42 },
120 { "01-06-79 02:42AM 458 Corner4",
121 net::FtpDirectoryListingEntry::FILE, "Corner4", 458,
122 2079, 1, 6, 2, 42 },
123 { "01-06-1979 02:42AM 458 Readme.txt",
124 net::FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
125 1979, 1, 6, 2, 42 },
126 };
127 for (size_t i = 0; i < arraysize(good_cases); i++) {
128 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, good_cases[i].input));
129
130 net::FtpWindowsDirectoryListingParser parser;
131 RunSingleLineTestCase(&parser, good_cases[i]);
132 }
133
134 const char* bad_cases[] = {
135 "",
136 "garbage",
137 "11-02-09 05:32PM <GARBAGE> NT",
138 "11-02-09 05:32 <DIR> NT",
139 "11-FEB-09 05:32PM <DIR> NT",
140 "11-02 05:32PM <DIR> NT",
141 "11-02-09 05:32PM -1 NT",
142 };
143 for (size_t i = 0; i < arraysize(bad_cases); i++) {
144 net::FtpWindowsDirectoryListingParser parser;
145 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i];
146 }
147 }
148
94 TEST_F(FtpDirectoryListingParsersTest, Vms) { 149 TEST_F(FtpDirectoryListingParsersTest, Vms) {
95 const struct SingleLineTestData good_cases[] = { 150 const struct SingleLineTestData good_cases[] = {
96 { "README.TXT;4 2 18-APR-2000 10:40:39.90", 151 { "README.TXT;4 2 18-APR-2000 10:40:39.90",
97 net::FtpDirectoryListingEntry::FILE, "readme.txt", 1024, 152 net::FtpDirectoryListingEntry::FILE, "readme.txt", 1024,
98 2000, 4, 18, 10, 40 }, 153 2000, 4, 18, 10, 40 },
99 { ".WELCOME;1 2 13-FEB-2002 23:32:40.47", 154 { ".WELCOME;1 2 13-FEB-2002 23:32:40.47",
100 net::FtpDirectoryListingEntry::FILE, ".welcome", 1024, 155 net::FtpDirectoryListingEntry::FILE, ".welcome", 1024,
101 2002, 2, 13, 23, 32 }, 156 2002, 2, 13, 23, 32 },
102 { "FILE.;1 2 13-FEB-2002 23:32:40.47", 157 { "FILE.;1 2 13-FEB-2002 23:32:40.47",
103 net::FtpDirectoryListingEntry::FILE, "file.", 1024, 158 net::FtpDirectoryListingEntry::FILE, "file.", 1024,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 if (!parser.ConsumeLine(UTF8ToUTF16(*i))) { 242 if (!parser.ConsumeLine(UTF8ToUTF16(*i))) {
188 failed = true; 243 failed = true;
189 break; 244 break;
190 } 245 }
191 } 246 }
192 EXPECT_TRUE(failed); 247 EXPECT_TRUE(failed);
193 } 248 }
194 } 249 }
195 250
196 } // namespace 251 } // 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