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

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

Issue 11470035: FTP: correctly handle newlines in file names (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed \r Created 8 years 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
« no previous file with comments | « net/ftp/ftp_directory_listing_parser.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.h" 5 #include "net/ftp/ftp_directory_listing_parser.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/string_tokenizer.h" 12 #include "base/string_split.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/ftp/ftp_directory_listing_parser.h" 15 #include "net/ftp/ftp_directory_listing_parser.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace net { 18 namespace net {
19 19
20 namespace { 20 namespace {
21 21
22 class FtpDirectoryListingParserTest 22 class FtpDirectoryListingParserTest
(...skipping 26 matching lines...) Expand all
49 EXPECT_EQ(OK, ParseFtpDirectoryListing(test_listing, 49 EXPECT_EQ(OK, ParseFtpDirectoryListing(test_listing,
50 mock_current_time, 50 mock_current_time,
51 &entries)); 51 &entries));
52 52
53 std::string expected_listing; 53 std::string expected_listing;
54 ASSERT_TRUE(file_util::ReadFileToString( 54 ASSERT_TRUE(file_util::ReadFileToString(
55 test_dir.AppendASCII(std::string(GetParam()) + ".expected"), 55 test_dir.AppendASCII(std::string(GetParam()) + ".expected"),
56 &expected_listing)); 56 &expected_listing));
57 57
58 std::vector<std::string> lines; 58 std::vector<std::string> lines;
59 StringTokenizer tokenizer(expected_listing, "\r\n"); 59 base::SplitStringUsingSubstr(expected_listing, "\r\n", &lines);
60 while (tokenizer.GetNext())
61 lines.push_back(tokenizer.token());
62 60
63 ASSERT_EQ(8 * entries.size(), lines.size()); 61 // Special case for empty listings.
62 if (lines.size() == 1 && lines[0].empty())
63 lines.clear();
64 64
65 for (size_t i = 0; i < lines.size() / 8; i++) { 65 ASSERT_EQ(9 * entries.size(), lines.size());
66 std::string type(lines[8 * i]); 66
67 std::string name(lines[8 * i + 1]); 67 for (size_t i = 0; i < lines.size() / 9; i++) {
68 std::string type(lines[9 * i]);
69 std::string name(lines[9 * i + 1]);
68 int64 size; 70 int64 size;
69 base::StringToInt64(lines[8 * i + 2], &size); 71 base::StringToInt64(lines[9 * i + 2], &size);
70 72
71 SCOPED_TRACE(base::StringPrintf("Filename: %s", name.c_str())); 73 SCOPED_TRACE(base::StringPrintf("Filename: %s", name.c_str()));
72 74
73 int year, month, day_of_month, hour, minute; 75 int year, month, day_of_month, hour, minute;
74 base::StringToInt(lines[8 * i + 3], &year); 76 base::StringToInt(lines[9 * i + 3], &year);
75 base::StringToInt(lines[8 * i + 4], &month); 77 base::StringToInt(lines[9 * i + 4], &month);
76 base::StringToInt(lines[8 * i + 5], &day_of_month); 78 base::StringToInt(lines[9 * i + 5], &day_of_month);
77 base::StringToInt(lines[8 * i + 6], &hour); 79 base::StringToInt(lines[9 * i + 6], &hour);
78 base::StringToInt(lines[8 * i + 7], &minute); 80 base::StringToInt(lines[9 * i + 7], &minute);
79 81
80 const FtpDirectoryListingEntry& entry = entries[i]; 82 const FtpDirectoryListingEntry& entry = entries[i];
81 83
82 if (type == "d") { 84 if (type == "d") {
83 EXPECT_EQ(FtpDirectoryListingEntry::DIRECTORY, entry.type); 85 EXPECT_EQ(FtpDirectoryListingEntry::DIRECTORY, entry.type);
84 } else if (type == "-") { 86 } else if (type == "-") {
85 EXPECT_EQ(FtpDirectoryListingEntry::FILE, entry.type); 87 EXPECT_EQ(FtpDirectoryListingEntry::FILE, entry.type);
86 } else if (type == "l") { 88 } else if (type == "l") {
87 EXPECT_EQ(FtpDirectoryListingEntry::SYMLINK, entry.type); 89 EXPECT_EQ(FtpDirectoryListingEntry::SYMLINK, entry.type);
88 } else { 90 } else {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 133
132 // Tests for Russian listings. The only difference between those 134 // Tests for Russian listings. The only difference between those
133 // files is character encoding: 135 // files is character encoding:
134 "dir-listing-ls-25", // UTF-8 136 "dir-listing-ls-25", // UTF-8
135 "dir-listing-ls-26", // KOI8-R 137 "dir-listing-ls-26", // KOI8-R
136 "dir-listing-ls-27", // windows-1251 138 "dir-listing-ls-27", // windows-1251
137 139
138 "dir-listing-ls-28", // Hylafax FTP server 140 "dir-listing-ls-28", // Hylafax FTP server
139 "dir-listing-ls-29", 141 "dir-listing-ls-29",
140 "dir-listing-ls-30", 142 "dir-listing-ls-30",
143 "dir-listing-ls-31",
141 144
142 "dir-listing-netware-1", 145 "dir-listing-netware-1",
143 "dir-listing-netware-2", 146 "dir-listing-netware-2",
144 "dir-listing-netware-3", // Spaces in file names. 147 "dir-listing-netware-3", // Spaces in file names.
145 "dir-listing-os2-1", 148 "dir-listing-os2-1",
146 "dir-listing-vms-1", 149 "dir-listing-vms-1",
147 "dir-listing-vms-2", 150 "dir-listing-vms-2",
148 "dir-listing-vms-3", 151 "dir-listing-vms-3",
149 "dir-listing-vms-4", 152 "dir-listing-vms-4",
150 "dir-listing-vms-5", 153 "dir-listing-vms-5",
151 "dir-listing-windows-1", 154 "dir-listing-windows-1",
152 "dir-listing-windows-2", 155 "dir-listing-windows-2",
153 }; 156 };
154 157
155 INSTANTIATE_TEST_CASE_P(, FtpDirectoryListingParserTest, 158 INSTANTIATE_TEST_CASE_P(, FtpDirectoryListingParserTest,
156 testing::ValuesIn(kTestFiles)); 159 testing::ValuesIn(kTestFiles));
157 160
158 } // namespace 161 } // namespace
159 162
160 } // namespace net 163 } // namespace net
OLDNEW
« no previous file with comments | « net/ftp/ftp_directory_listing_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698