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

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

Issue 339059: Add compiler-specific "examine printf format" attributes to printfs. (Closed)
Patch Set: cleanups 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
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/format_macros.h"
7 #include "base/string_util.h" 8 #include "base/string_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 namespace { 11 namespace {
11 12
12 struct SingleLineTestData { 13 struct SingleLineTestData {
13 const char* input; 14 const char* input;
14 net::FtpDirectoryListingEntry::Type type; 15 net::FtpDirectoryListingEntry::Type type;
15 const char* filename; 16 const char* filename;
16 int64 size; 17 int64 size;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 net::FtpDirectoryListingEntry::DIRECTORY, "directory", -1, 63 net::FtpDirectoryListingEntry::DIRECTORY, "directory", -1,
63 now_exploded.year, 5, 15, 18, 11 }, 64 now_exploded.year, 5, 15, 18, 11 },
64 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub", 65 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub",
65 net::FtpDirectoryListingEntry::SYMLINK, "pub", -1, 66 net::FtpDirectoryListingEntry::SYMLINK, "pub", -1,
66 2008, 9, 18, 0, 0 }, 67 2008, 9, 18, 0, 0 },
67 { "lrwxrwxrwx 1 0 0 3 Oct 12 13:37 mirror -> pub", 68 { "lrwxrwxrwx 1 0 0 3 Oct 12 13:37 mirror -> pub",
68 net::FtpDirectoryListingEntry::SYMLINK, "mirror", -1, 69 net::FtpDirectoryListingEntry::SYMLINK, "mirror", -1,
69 now_exploded.year, 10, 12, 13, 37 }, 70 now_exploded.year, 10, 12, 13, 37 },
70 }; 71 };
71 for (size_t i = 0; i < arraysize(good_cases); i++) { 72 for (size_t i = 0; i < arraysize(good_cases); i++) {
72 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, good_cases[i].input)); 73 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, good_cases[i].input));
73 74
74 net::FtpLsDirectoryListingParser parser; 75 net::FtpLsDirectoryListingParser parser;
75 RunSingleLineTestCase(&parser, good_cases[i]); 76 RunSingleLineTestCase(&parser, good_cases[i]);
76 } 77 }
77 78
78 const char* bad_cases[] = { 79 const char* bad_cases[] = {
79 "garbage", 80 "garbage",
80 "-rw-r--r-- 1 ftp ftp", 81 "-rw-r--r-- 1 ftp ftp",
81 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README", 82 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README",
82 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README", 83 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README",
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // TODO(phajdan.jr): Re-enable when 2038-year problem is fixed on Linux. 122 // TODO(phajdan.jr): Re-enable when 2038-year problem is fixed on Linux.
122 { "01-06-79 02:42AM 458 Corner4", 123 { "01-06-79 02:42AM 458 Corner4",
123 net::FtpDirectoryListingEntry::FILE, "Corner4", 458, 124 net::FtpDirectoryListingEntry::FILE, "Corner4", 458,
124 2079, 1, 6, 2, 42 }, 125 2079, 1, 6, 2, 42 },
125 #endif // !defined (OS_LINUX) 126 #endif // !defined (OS_LINUX)
126 { "01-06-1979 02:42AM 458 Readme.txt", 127 { "01-06-1979 02:42AM 458 Readme.txt",
127 net::FtpDirectoryListingEntry::FILE, "Readme.txt", 458, 128 net::FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
128 1979, 1, 6, 2, 42 }, 129 1979, 1, 6, 2, 42 },
129 }; 130 };
130 for (size_t i = 0; i < arraysize(good_cases); i++) { 131 for (size_t i = 0; i < arraysize(good_cases); i++) {
131 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, good_cases[i].input)); 132 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, good_cases[i].input));
132 133
133 net::FtpWindowsDirectoryListingParser parser; 134 net::FtpWindowsDirectoryListingParser parser;
134 RunSingleLineTestCase(&parser, good_cases[i]); 135 RunSingleLineTestCase(&parser, good_cases[i]);
135 } 136 }
136 137
137 const char* bad_cases[] = { 138 const char* bad_cases[] = {
138 "", 139 "",
139 "garbage", 140 "garbage",
140 "11-02-09 05:32PM <GARBAGE> NT", 141 "11-02-09 05:32PM <GARBAGE> NT",
141 "11-02-09 05:32 <DIR> NT", 142 "11-02-09 05:32 <DIR> NT",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512, 174 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512,
174 2005, 3, 12, 8, 44 }, 175 2005, 3, 12, 8, 44 },
175 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (R,RW,RWD,RE)", 176 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (R,RW,RWD,RE)",
176 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512, 177 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512,
177 2005, 3, 12, 8, 44 }, 178 2005, 3, 12, 8, 44 },
178 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (ED,RED,WD,WED)", 179 { "ANNOUNCE.TXT;2 1 12-MAR-2005 08:44:57 [X] (ED,RED,WD,WED)",
179 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512, 180 net::FtpDirectoryListingEntry::FILE, "announce.txt", 512,
180 2005, 3, 12, 8, 44 }, 181 2005, 3, 12, 8, 44 },
181 }; 182 };
182 for (size_t i = 0; i < arraysize(good_cases); i++) { 183 for (size_t i = 0; i < arraysize(good_cases); i++) {
183 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, good_cases[i].input)); 184 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, good_cases[i].input));
184 185
185 net::FtpVmsDirectoryListingParser parser; 186 net::FtpVmsDirectoryListingParser parser;
186 ASSERT_TRUE( 187 ASSERT_TRUE(
187 parser.ConsumeLine(ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]"))); 188 parser.ConsumeLine(ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]")));
188 RunSingleLineTestCase(&parser, good_cases[i]); 189 RunSingleLineTestCase(&parser, good_cases[i]);
189 } 190 }
190 191
191 const char* bad_cases[] = { 192 const char* bad_cases[] = {
192 "Directory ROOT|garbage", 193 "Directory ROOT|garbage",
193 194
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 (SYSTEM) (RWED,RWED,RE,RE)", 228 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 (SYSTEM) (RWED,RWED,RE,RE)",
228 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM] [RWED,RWED,RE,RE]", 229 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM] [RWED,RWED,RE,RE]",
229 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED)", 230 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED)",
230 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,RE,RE,RE)", 231 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,RE,RE,RE)",
231 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWEDRWED,RE,RE)", 232 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWEDRWED,RE,RE)",
232 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,DEWR,RE,RE)", 233 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,DEWR,RE,RE)",
233 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,Q,RE)", 234 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,Q,RE)",
234 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RRWWEEDD,RE,RE)", 235 "Directory ROOT|X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RRWWEEDD,RE,RE)",
235 }; 236 };
236 for (size_t i = 0; i < arraysize(bad_cases); i++) { 237 for (size_t i = 0; i < arraysize(bad_cases); i++) {
237 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, bad_cases[i])); 238 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i]));
238 239
239 std::vector<std::string> lines; 240 std::vector<std::string> lines;
240 SplitString(bad_cases[i], '|', &lines); 241 SplitString(bad_cases[i], '|', &lines);
241 net::FtpVmsDirectoryListingParser parser; 242 net::FtpVmsDirectoryListingParser parser;
242 bool failed = false; 243 bool failed = false;
243 for (std::vector<std::string>::const_iterator i = lines.begin(); 244 for (std::vector<std::string>::const_iterator i = lines.begin();
244 i != lines.end(); ++i) { 245 i != lines.end(); ++i) {
245 if (!parser.ConsumeLine(UTF8ToUTF16(*i))) { 246 if (!parser.ConsumeLine(UTF8ToUTF16(*i))) {
246 failed = true; 247 failed = true;
247 break; 248 break;
248 } 249 }
249 } 250 }
250 EXPECT_TRUE(failed); 251 EXPECT_TRUE(failed);
251 } 252 }
252 } 253 }
253 254
254 } // namespace 255 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698