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

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

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

Powered by Google App Engine
This is Rietveld 408576698