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

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

Issue 343022: Also parse file size in new FTP LIST parsing code. (Closed)
Patch Set: 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_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/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string_tokenizer.h" 9 #include "base/string_tokenizer.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 30 matching lines...) Expand all
41 41
42 std::string expected_listing; 42 std::string expected_listing;
43 ASSERT_TRUE(file_util::ReadFileToString( 43 ASSERT_TRUE(file_util::ReadFileToString(
44 test_dir.AppendASCII(std::string(test_files[i]) + ".expected"), 44 test_dir.AppendASCII(std::string(test_files[i]) + ".expected"),
45 &expected_listing)); 45 &expected_listing));
46 46
47 std::vector<std::string> lines; 47 std::vector<std::string> lines;
48 StringTokenizer tokenizer(expected_listing, "\r\n"); 48 StringTokenizer tokenizer(expected_listing, "\r\n");
49 while (tokenizer.GetNext()) 49 while (tokenizer.GetNext())
50 lines.push_back(tokenizer.token()); 50 lines.push_back(tokenizer.token());
51 ASSERT_EQ(0U, lines.size() % 7); 51 ASSERT_EQ(0U, lines.size() % 8);
wtc 2009/10/28 19:12:08 The CL's description doesn't describe the changes
52 52
53 for (size_t i = 0; i < lines.size() / 7; i++) { 53 for (size_t i = 0; i < lines.size() / 8; i++) {
54 std::string type(lines[7 * i]); 54 std::string type(lines[8 * i]);
55 std::string name(lines[7 * i + 1]); 55 std::string name(lines[8 * i + 1]);
56 int64 size = StringToInt64(lines[8 * i + 2]);
56 57
57 SCOPED_TRACE(StringPrintf("Filename: %s", name.c_str())); 58 SCOPED_TRACE(StringPrintf("Filename: %s", name.c_str()));
58 59
59 int year; 60 int year;
60 if (lines[7 * i + 2] == "current") { 61 if (lines[8 * i + 3] == "current") {
61 base::Time::Exploded now_exploded; 62 base::Time::Exploded now_exploded;
62 base::Time::Now().LocalExplode(&now_exploded); 63 base::Time::Now().LocalExplode(&now_exploded);
63 year = now_exploded.year; 64 year = now_exploded.year;
64 } else { 65 } else {
65 year = StringToInt(lines[7 * i + 2]); 66 year = StringToInt(lines[8 * i + 3]);
66 } 67 }
67 int month = StringToInt(lines[7 * i + 3]); 68 int month = StringToInt(lines[8 * i + 4]);
68 int day_of_month = StringToInt(lines[7 * i + 4]); 69 int day_of_month = StringToInt(lines[8 * i + 5]);
69 int hour = StringToInt(lines[7 * i + 5]); 70 int hour = StringToInt(lines[8 * i + 6]);
70 int minute = StringToInt(lines[7 * i + 6]); 71 int minute = StringToInt(lines[8 * i + 7]);
71 72
72 ASSERT_TRUE(buffer.EntryAvailable()); 73 ASSERT_TRUE(buffer.EntryAvailable());
73 net::FtpDirectoryListingEntry entry = buffer.PopEntry(); 74 net::FtpDirectoryListingEntry entry = buffer.PopEntry();
74 75
75 if (type == "d") { 76 if (type == "d") {
76 EXPECT_EQ(net::FtpDirectoryListingEntry::DIRECTORY, entry.type); 77 EXPECT_EQ(net::FtpDirectoryListingEntry::DIRECTORY, entry.type);
77 } else if (type == "-") { 78 } else if (type == "-") {
78 EXPECT_EQ(net::FtpDirectoryListingEntry::FILE, entry.type); 79 EXPECT_EQ(net::FtpDirectoryListingEntry::FILE, entry.type);
79 } else if (type == "l") { 80 } else if (type == "l") {
80 EXPECT_EQ(net::FtpDirectoryListingEntry::SYMLINK, entry.type); 81 EXPECT_EQ(net::FtpDirectoryListingEntry::SYMLINK, entry.type);
81 } else { 82 } else {
82 ADD_FAILURE() << "invalid gold test data: " << type; 83 ADD_FAILURE() << "invalid gold test data: " << type;
83 } 84 }
84 85
85 EXPECT_EQ(UTF8ToUTF16(name), entry.name); 86 EXPECT_EQ(UTF8ToUTF16(name), entry.name);
87 EXPECT_EQ(size, entry.size);
86 88
87 base::Time::Exploded time_exploded; 89 base::Time::Exploded time_exploded;
88 entry.last_modified.LocalExplode(&time_exploded); 90 entry.last_modified.LocalExplode(&time_exploded);
89 EXPECT_EQ(year, time_exploded.year); 91 EXPECT_EQ(year, time_exploded.year);
90 EXPECT_EQ(month, time_exploded.month); 92 EXPECT_EQ(month, time_exploded.month);
91 EXPECT_EQ(day_of_month, time_exploded.day_of_month); 93 EXPECT_EQ(day_of_month, time_exploded.day_of_month);
92 EXPECT_EQ(hour, time_exploded.hour); 94 EXPECT_EQ(hour, time_exploded.hour);
93 EXPECT_EQ(minute, time_exploded.minute); 95 EXPECT_EQ(minute, time_exploded.minute);
94 EXPECT_EQ(0, time_exploded.second); 96 EXPECT_EQ(0, time_exploded.second);
95 EXPECT_EQ(0, time_exploded.millisecond); 97 EXPECT_EQ(0, time_exploded.millisecond);
96 } 98 }
97 EXPECT_FALSE(buffer.EntryAvailable()); 99 EXPECT_FALSE(buffer.EntryAvailable());
98 } 100 }
99 } 101 }
100 102
101 } // namespace 103 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698