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

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

Issue 348036: Implement VMS FTP directory listing parser. (Closed)
Patch Set: fix 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_buffer.cc ('k') | net/ftp/ftp_directory_listing_parsers.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/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"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/ftp/ftp_directory_listing_parsers.h" 12 #include "net/ftp/ftp_directory_listing_parsers.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace { 15 namespace {
16 16
17 TEST(FtpDirectoryListingBufferTest, Parse) { 17 TEST(FtpDirectoryListingBufferTest, Parse) {
18 const char* test_files[] = { 18 const char* test_files[] = {
19 "dir-listing-ls-1", 19 "dir-listing-ls-1",
20 "dir-listing-ls-2", 20 "dir-listing-ls-2",
21 "dir-listing-vms-1",
22 "dir-listing-vms-2",
23 "dir-listing-vms-3",
24 "dir-listing-vms-4",
21 }; 25 };
22 26
23 FilePath test_dir; 27 FilePath test_dir;
24 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir); 28 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir);
25 test_dir = test_dir.AppendASCII("net"); 29 test_dir = test_dir.AppendASCII("net");
26 test_dir = test_dir.AppendASCII("data"); 30 test_dir = test_dir.AppendASCII("data");
27 test_dir = test_dir.AppendASCII("ftp"); 31 test_dir = test_dir.AppendASCII("ftp");
28 32
29 for (size_t i = 0; i < arraysize(test_files); i++) { 33 for (size_t i = 0; i < arraysize(test_files); i++) {
30 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, test_files[i])); 34 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, test_files[i]));
31 35
32 net::FtpDirectoryListingBuffer buffer; 36 net::FtpDirectoryListingBuffer buffer;
33 37
34 std::string test_listing; 38 std::string test_listing;
35 EXPECT_TRUE(file_util::ReadFileToString(test_dir.AppendASCII(test_files[i]), 39 EXPECT_TRUE(file_util::ReadFileToString(test_dir.AppendASCII(test_files[i]),
36 &test_listing)); 40 &test_listing));
37 41
38 EXPECT_EQ(net::OK, buffer.ConsumeData(test_listing.data(), 42 EXPECT_EQ(net::OK, buffer.ConsumeData(test_listing.data(),
39 test_listing.length())); 43 test_listing.length()));
40 EXPECT_EQ(net::OK, buffer.ProcessRemainingData()); 44 EXPECT_EQ(net::OK, buffer.ProcessRemainingData());
41 45
42 std::string expected_listing; 46 std::string expected_listing;
43 ASSERT_TRUE(file_util::ReadFileToString( 47 ASSERT_TRUE(file_util::ReadFileToString(
44 test_dir.AppendASCII(std::string(test_files[i]) + ".expected"), 48 test_dir.AppendASCII(std::string(test_files[i]) + ".expected"),
45 &expected_listing)); 49 &expected_listing));
46 50
47 std::vector<std::string> lines; 51 std::vector<std::string> lines;
48 StringTokenizer tokenizer(expected_listing, "\r\n"); 52 StringTokenizer tokenizer(expected_listing, "\r\n");
49 while (tokenizer.GetNext()) 53 while (tokenizer.GetNext())
50 lines.push_back(tokenizer.token()); 54 lines.push_back(tokenizer.token());
51 ASSERT_EQ(0U, lines.size() % 8); 55 ASSERT_EQ(0U, lines.size() % 8);
52 56
53 for (size_t i = 0; i < lines.size() / 8; i++) { 57 for (size_t i = 0; i < lines.size() / 8; i++) {
54 std::string type(lines[8 * i]); 58 std::string type(lines[8 * i]);
55 std::string name(lines[8 * i + 1]); 59 std::string name(lines[8 * i + 1]);
56 int64 size = StringToInt64(lines[8 * i + 2]); 60 int64 size = StringToInt64(lines[8 * i + 2]);
57 61
58 SCOPED_TRACE(StringPrintf("Filename: %s", name.c_str())); 62 SCOPED_TRACE(StringPrintf("Filename: %s", name.c_str()));
59 63
60 int year; 64 int year;
61 if (lines[8 * i + 3] == "current") { 65 if (lines[8 * i + 3] == "current") {
62 base::Time::Exploded now_exploded; 66 base::Time::Exploded now_exploded;
63 base::Time::Now().LocalExplode(&now_exploded); 67 base::Time::Now().LocalExplode(&now_exploded);
64 year = now_exploded.year; 68 year = now_exploded.year;
65 } else { 69 } else {
66 year = StringToInt(lines[8 * i + 3]); 70 year = StringToInt(lines[8 * i + 3]);
67 } 71 }
68 int month = StringToInt(lines[8 * i + 4]); 72 int month = StringToInt(lines[8 * i + 4]);
69 int day_of_month = StringToInt(lines[8 * i + 5]); 73 int day_of_month = StringToInt(lines[8 * i + 5]);
70 int hour = StringToInt(lines[8 * i + 6]); 74 int hour = StringToInt(lines[8 * i + 6]);
71 int minute = StringToInt(lines[8 * i + 7]); 75 int minute = StringToInt(lines[8 * i + 7]);
72 76
73 ASSERT_TRUE(buffer.EntryAvailable()); 77 ASSERT_TRUE(buffer.EntryAvailable());
74 net::FtpDirectoryListingEntry entry = buffer.PopEntry(); 78 net::FtpDirectoryListingEntry entry = buffer.PopEntry();
75 79
76 if (type == "d") { 80 if (type == "d") {
77 EXPECT_EQ(net::FtpDirectoryListingEntry::DIRECTORY, entry.type); 81 EXPECT_EQ(net::FtpDirectoryListingEntry::DIRECTORY, entry.type);
78 } else if (type == "-") { 82 } else if (type == "-") {
79 EXPECT_EQ(net::FtpDirectoryListingEntry::FILE, entry.type); 83 EXPECT_EQ(net::FtpDirectoryListingEntry::FILE, entry.type);
80 } else if (type == "l") { 84 } else if (type == "l") {
81 EXPECT_EQ(net::FtpDirectoryListingEntry::SYMLINK, entry.type); 85 EXPECT_EQ(net::FtpDirectoryListingEntry::SYMLINK, entry.type);
82 } else { 86 } else {
83 ADD_FAILURE() << "invalid gold test data: " << type; 87 ADD_FAILURE() << "invalid gold test data: " << type;
84 } 88 }
85 89
86 EXPECT_EQ(UTF8ToUTF16(name), entry.name); 90 EXPECT_EQ(UTF8ToUTF16(name), entry.name);
87 EXPECT_EQ(size, entry.size); 91 EXPECT_EQ(size, entry.size);
88 92
89 base::Time::Exploded time_exploded; 93 base::Time::Exploded time_exploded;
90 entry.last_modified.LocalExplode(&time_exploded); 94 entry.last_modified.LocalExplode(&time_exploded);
91 EXPECT_EQ(year, time_exploded.year); 95 EXPECT_EQ(year, time_exploded.year);
92 EXPECT_EQ(month, time_exploded.month); 96 EXPECT_EQ(month, time_exploded.month);
93 EXPECT_EQ(day_of_month, time_exploded.day_of_month); 97 EXPECT_EQ(day_of_month, time_exploded.day_of_month);
94 EXPECT_EQ(hour, time_exploded.hour); 98 EXPECT_EQ(hour, time_exploded.hour);
95 EXPECT_EQ(minute, time_exploded.minute); 99 EXPECT_EQ(minute, time_exploded.minute);
96 EXPECT_EQ(0, time_exploded.second); 100 EXPECT_EQ(0, time_exploded.second);
97 EXPECT_EQ(0, time_exploded.millisecond); 101 EXPECT_EQ(0, time_exploded.millisecond);
98 } 102 }
99 EXPECT_FALSE(buffer.EntryAvailable()); 103 EXPECT_FALSE(buffer.EntryAvailable());
100 } 104 }
101 } 105 }
102 106
103 } // namespace 107 } // namespace
OLDNEW
« no previous file with comments | « net/ftp/ftp_directory_listing_buffer.cc ('k') | net/ftp/ftp_directory_listing_parsers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698