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

Side by Side Diff: net/ftp/ftp_directory_listing_parsers_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_parsers.h" 5 #include "net/ftp/ftp_directory_listing_parsers.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
11 11
12 struct SingleLineTestData { 12 struct SingleLineTestData {
13 const char* input; 13 const char* input;
14 net::FtpDirectoryListingEntry::Type type; 14 net::FtpDirectoryListingEntry::Type type;
15 const char* filename; 15 const char* filename;
16 int64 size;
16 int year; 17 int year;
17 int month; 18 int month;
18 int day_of_month; 19 int day_of_month;
19 int hour; 20 int hour;
20 int minute; 21 int minute;
21 }; 22 };
22 23
23 class FtpDirectoryListingParsersTest : public testing::Test { 24 class FtpDirectoryListingParsersTest : public testing::Test {
24 protected: 25 protected:
25 FtpDirectoryListingParsersTest() { 26 FtpDirectoryListingParsersTest() {
26 } 27 }
27 28
28 void RunSingleLineTestCase(net::FtpDirectoryListingParser* parser, 29 void RunSingleLineTestCase(net::FtpDirectoryListingParser* parser,
29 const SingleLineTestData& test_case) { 30 const SingleLineTestData& test_case) {
30 ASSERT_TRUE(parser->ConsumeLine(UTF8ToUTF16(test_case.input))); 31 ASSERT_TRUE(parser->ConsumeLine(UTF8ToUTF16(test_case.input)));
31 ASSERT_TRUE(parser->EntryAvailable()); 32 ASSERT_TRUE(parser->EntryAvailable());
32 net::FtpDirectoryListingEntry entry = parser->PopEntry(); 33 net::FtpDirectoryListingEntry entry = parser->PopEntry();
33 EXPECT_EQ(test_case.type, entry.type); 34 EXPECT_EQ(test_case.type, entry.type);
34 EXPECT_EQ(UTF8ToUTF16(test_case.filename), entry.name); 35 EXPECT_EQ(UTF8ToUTF16(test_case.filename), entry.name);
36 EXPECT_EQ(test_case.size, entry.size);
35 37
36 base::Time::Exploded time_exploded; 38 base::Time::Exploded time_exploded;
37 entry.last_modified.LocalExplode(&time_exploded); 39 entry.last_modified.LocalExplode(&time_exploded);
38 EXPECT_EQ(test_case.year, time_exploded.year); 40 EXPECT_EQ(test_case.year, time_exploded.year);
39 EXPECT_EQ(test_case.month, time_exploded.month); 41 EXPECT_EQ(test_case.month, time_exploded.month);
40 EXPECT_EQ(test_case.day_of_month, time_exploded.day_of_month); 42 EXPECT_EQ(test_case.day_of_month, time_exploded.day_of_month);
41 EXPECT_EQ(test_case.hour, time_exploded.hour); 43 EXPECT_EQ(test_case.hour, time_exploded.hour);
42 EXPECT_EQ(test_case.minute, time_exploded.minute); 44 EXPECT_EQ(test_case.minute, time_exploded.minute);
43 EXPECT_EQ(0, time_exploded.second); 45 EXPECT_EQ(0, time_exploded.second);
44 EXPECT_EQ(0, time_exploded.millisecond); 46 EXPECT_EQ(0, time_exploded.millisecond);
45 } 47 }
46 48
47 private: 49 private:
48 DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingParsersTest); 50 DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingParsersTest);
49 }; 51 };
50 52
51 TEST_F(FtpDirectoryListingParsersTest, Ls) { 53 TEST_F(FtpDirectoryListingParsersTest, Ls) {
52 base::Time::Exploded now_exploded; 54 base::Time::Exploded now_exploded;
53 base::Time::Now().LocalExplode(&now_exploded); 55 base::Time::Now().LocalExplode(&now_exploded);
54 56
55 const struct SingleLineTestData good_cases[] = { 57 const struct SingleLineTestData good_cases[] = {
56 { "-rw-r--r-- 1 ftp ftp 528 Nov 01 2007 README", 58 { "-rw-r--r-- 1 ftp ftp 528 Nov 01 2007 README",
57 net::FtpDirectoryListingEntry::FILE, "README", 59 net::FtpDirectoryListingEntry::FILE, "README", 528,
58 2007, 11, 1, 0, 0 }, 60 2007, 11, 1, 0, 0 },
59 { "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 directory", 61 { "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 directory",
60 net::FtpDirectoryListingEntry::DIRECTORY, "directory", 62 net::FtpDirectoryListingEntry::DIRECTORY, "directory", -1,
61 now_exploded.year, 5, 15, 18, 11 }, 63 now_exploded.year, 5, 15, 18, 11 },
62 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub", 64 { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub",
63 net::FtpDirectoryListingEntry::SYMLINK, "pub", 65 net::FtpDirectoryListingEntry::SYMLINK, "pub", -1,
64 2008, 9, 18, 0, 0 }, 66 2008, 9, 18, 0, 0 },
65 { "lrwxrwxrwx 1 0 0 3 Oct 12 13:37 mirror -> pub", 67 { "lrwxrwxrwx 1 0 0 3 Oct 12 13:37 mirror -> pub",
66 net::FtpDirectoryListingEntry::SYMLINK, "mirror", 68 net::FtpDirectoryListingEntry::SYMLINK, "mirror", -1,
67 now_exploded.year, 10, 12, 13, 37 }, 69 now_exploded.year, 10, 12, 13, 37 },
68 }; 70 };
69 for (size_t i = 0; i < arraysize(good_cases); i++) { 71 for (size_t i = 0; i < arraysize(good_cases); i++) {
70 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, good_cases[i].input)); 72 SCOPED_TRACE(StringPrintf("Test[%d]: %s", i, good_cases[i].input));
71 73
72 net::FtpLsDirectoryListingParser parser; 74 net::FtpLsDirectoryListingParser parser;
73 RunSingleLineTestCase(&parser, good_cases[i]); 75 RunSingleLineTestCase(&parser, good_cases[i]);
74 } 76 }
75 77
76 const char* bad_cases[] = { 78 const char* bad_cases[] = {
77 "", 79 "",
78 "garbage", 80 "garbage",
79 "-rw-r--r-- 1 ftp ftp", 81 "-rw-r--r-- 1 ftp ftp",
80 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README", 82 "-rw-r--rgb 1 ftp ftp 528 Nov 01 2007 README",
81 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README", 83 "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README",
82 "qrwwr--r-- 1 ftp ftp 528 Nov 01 2007 README", 84 "qrwwr--r-- 1 ftp ftp 528 Nov 01 2007 README",
83 "-rw-r--r-- -1 ftp ftp 528 Nov 01 2007 README", 85 "-rw-r--r-- -1 ftp ftp 528 Nov 01 2007 README",
84 "-rw-r--r-- 1 ftp ftp -528 Nov 01 2007 README", 86 "-rw-r--r-- 1 ftp ftp -528 Nov 01 2007 README",
85 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README", 87 "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README",
86 }; 88 };
87 for (size_t i = 0; i < arraysize(bad_cases); i++) { 89 for (size_t i = 0; i < arraysize(bad_cases); i++) {
88 net::FtpLsDirectoryListingParser parser; 90 net::FtpLsDirectoryListingParser parser;
89 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i]; 91 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i];
90 } 92 }
91 } 93 }
92 94
93 } // namespace 95 } // namespace
OLDNEW
« net/ftp/ftp_directory_listing_parsers.cc ('K') | « net/ftp/ftp_directory_listing_parsers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698