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

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

Issue 1120012: Fix the "ls -l" style date parser to correctly guess the year if it is not provided. (Closed)
Patch Set: better comments Created 10 years, 9 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
« no previous file with comments | « net/ftp/ftp_directory_listing_buffer.cc ('k') | net/ftp/ftp_directory_listing_parser_ls.h » ('j') | 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_buffer.h" 5 #include "net/ftp/ftp_directory_listing_buffer.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/string_tokenizer.h" 10 #include "base/string_tokenizer.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 "dir-listing-windows-1", 47 "dir-listing-windows-1",
48 "dir-listing-windows-2", 48 "dir-listing-windows-2",
49 }; 49 };
50 50
51 FilePath test_dir; 51 FilePath test_dir;
52 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir); 52 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir);
53 test_dir = test_dir.AppendASCII("net"); 53 test_dir = test_dir.AppendASCII("net");
54 test_dir = test_dir.AppendASCII("data"); 54 test_dir = test_dir.AppendASCII("data");
55 test_dir = test_dir.AppendASCII("ftp"); 55 test_dir = test_dir.AppendASCII("ftp");
56 56
57 base::Time mock_current_time;
58 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994 12:45:26 GMT",
59 &mock_current_time));
60
57 for (size_t i = 0; i < arraysize(test_files); i++) { 61 for (size_t i = 0; i < arraysize(test_files); i++) {
58 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, test_files[i])); 62 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, test_files[i]));
59 63
60 net::FtpDirectoryListingBuffer buffer; 64 net::FtpDirectoryListingBuffer buffer(mock_current_time);
61 65
62 std::string test_listing; 66 std::string test_listing;
63 EXPECT_TRUE(file_util::ReadFileToString(test_dir.AppendASCII(test_files[i]), 67 EXPECT_TRUE(file_util::ReadFileToString(test_dir.AppendASCII(test_files[i]),
64 &test_listing)); 68 &test_listing));
65 69
66 EXPECT_EQ(net::OK, buffer.ConsumeData(test_listing.data(), 70 EXPECT_EQ(net::OK, buffer.ConsumeData(test_listing.data(),
67 test_listing.length())); 71 test_listing.length()));
68 EXPECT_EQ(net::OK, buffer.ProcessRemainingData()); 72 EXPECT_EQ(net::OK, buffer.ProcessRemainingData());
69 73
70 std::string expected_listing; 74 std::string expected_listing;
71 ASSERT_TRUE(file_util::ReadFileToString( 75 ASSERT_TRUE(file_util::ReadFileToString(
72 test_dir.AppendASCII(std::string(test_files[i]) + ".expected"), 76 test_dir.AppendASCII(std::string(test_files[i]) + ".expected"),
73 &expected_listing)); 77 &expected_listing));
74 78
75 std::vector<std::string> lines; 79 std::vector<std::string> lines;
76 StringTokenizer tokenizer(expected_listing, "\r\n"); 80 StringTokenizer tokenizer(expected_listing, "\r\n");
77 while (tokenizer.GetNext()) 81 while (tokenizer.GetNext())
78 lines.push_back(tokenizer.token()); 82 lines.push_back(tokenizer.token());
79 ASSERT_EQ(0U, lines.size() % 8); 83 ASSERT_EQ(0U, lines.size() % 8);
80 84
81 for (size_t i = 0; i < lines.size() / 8; i++) { 85 for (size_t i = 0; i < lines.size() / 8; i++) {
82 std::string type(lines[8 * i]); 86 std::string type(lines[8 * i]);
83 std::string name(lines[8 * i + 1]); 87 std::string name(lines[8 * i + 1]);
84 int64 size = StringToInt64(lines[8 * i + 2]); 88 int64 size = StringToInt64(lines[8 * i + 2]);
85 89
86 SCOPED_TRACE(StringPrintf("Filename: %s", name.c_str())); 90 SCOPED_TRACE(StringPrintf("Filename: %s", name.c_str()));
87 91
88 int year; 92 int year = StringToInt(lines[8 * i + 3]);
89 if (lines[8 * i + 3] == "current") {
90 base::Time::Exploded now_exploded;
91 base::Time::Now().LocalExplode(&now_exploded);
92 year = now_exploded.year;
93 } else {
94 year = StringToInt(lines[8 * i + 3]);
95 }
96 int month = StringToInt(lines[8 * i + 4]); 93 int month = StringToInt(lines[8 * i + 4]);
97 int day_of_month = StringToInt(lines[8 * i + 5]); 94 int day_of_month = StringToInt(lines[8 * i + 5]);
98 int hour = StringToInt(lines[8 * i + 6]); 95 int hour = StringToInt(lines[8 * i + 6]);
99 int minute = StringToInt(lines[8 * i + 7]); 96 int minute = StringToInt(lines[8 * i + 7]);
100 97
101 ASSERT_TRUE(buffer.EntryAvailable()); 98 ASSERT_TRUE(buffer.EntryAvailable());
102 net::FtpDirectoryListingEntry entry = buffer.PopEntry(); 99 net::FtpDirectoryListingEntry entry = buffer.PopEntry();
103 100
104 if (type == "d") { 101 if (type == "d") {
105 EXPECT_EQ(net::FtpDirectoryListingEntry::DIRECTORY, entry.type); 102 EXPECT_EQ(net::FtpDirectoryListingEntry::DIRECTORY, entry.type);
(...skipping 16 matching lines...) Expand all
122 EXPECT_EQ(hour, time_exploded.hour); 119 EXPECT_EQ(hour, time_exploded.hour);
123 EXPECT_EQ(minute, time_exploded.minute); 120 EXPECT_EQ(minute, time_exploded.minute);
124 EXPECT_EQ(0, time_exploded.second); 121 EXPECT_EQ(0, time_exploded.second);
125 EXPECT_EQ(0, time_exploded.millisecond); 122 EXPECT_EQ(0, time_exploded.millisecond);
126 } 123 }
127 EXPECT_FALSE(buffer.EntryAvailable()); 124 EXPECT_FALSE(buffer.EntryAvailable());
128 } 125 }
129 } 126 }
130 127
131 } // namespace 128 } // namespace
OLDNEW
« no previous file with comments | « net/ftp/ftp_directory_listing_buffer.cc ('k') | net/ftp/ftp_directory_listing_parser_ls.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698