OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_parser_unittest.h" | 5 #include "net/ftp/ftp_directory_listing_parser_unittest.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "net/ftp/ftp_directory_listing_parser_netware.h" | 11 #include "net/ftp/ftp_directory_listing_parser_netware.h" |
12 | 12 |
| 13 namespace net { |
| 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 typedef net::FtpDirectoryListingParserTest FtpDirectoryListingParserNetwareTest; | 17 typedef FtpDirectoryListingParserTest FtpDirectoryListingParserNetwareTest; |
16 | 18 |
17 TEST_F(FtpDirectoryListingParserNetwareTest, Good) { | 19 TEST_F(FtpDirectoryListingParserNetwareTest, Good) { |
18 const struct SingleLineTestData good_cases[] = { | 20 const struct SingleLineTestData good_cases[] = { |
19 { "d [RWCEAFMS] ftpadmin 512 Jan 29 2004 pub", | 21 { "d [RWCEAFMS] ftpadmin 512 Jan 29 2004 pub", |
20 net::FtpDirectoryListingEntry::DIRECTORY, "pub", -1, | 22 FtpDirectoryListingEntry::DIRECTORY, "pub", -1, |
21 2004, 1, 29, 0, 0 }, | 23 2004, 1, 29, 0, 0 }, |
22 { "- [RW------] ftpadmin 123 Nov 11 18:25 afile", | 24 { "- [RW------] ftpadmin 123 Nov 11 18:25 afile", |
23 net::FtpDirectoryListingEntry::FILE, "afile", 123, | 25 FtpDirectoryListingEntry::FILE, "afile", 123, |
24 1994, 11, 11, 18, 25 }, | 26 1994, 11, 11, 18, 25 }, |
25 }; | 27 }; |
26 for (size_t i = 0; i < arraysize(good_cases); i++) { | 28 for (size_t i = 0; i < arraysize(good_cases); i++) { |
27 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, | 29 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
28 good_cases[i].input)); | 30 good_cases[i].input)); |
29 | 31 |
30 net::FtpDirectoryListingParserNetware parser(GetMockCurrentTime()); | 32 std::vector<string16> lines(GetSingleLineTestCase(good_cases[i].input)); |
31 // The parser requires a "total n" like before accepting regular input. | 33 |
32 ASSERT_TRUE(parser.ConsumeLine(UTF8ToUTF16("total 1"))); | 34 // The parser requires a "total n" line before accepting regular input. |
33 RunSingleLineTestCase(&parser, good_cases[i]); | 35 lines.insert(lines.begin(), ASCIIToUTF16("total 1")); |
| 36 |
| 37 std::vector<FtpDirectoryListingEntry> entries; |
| 38 EXPECT_TRUE(ParseFtpDirectoryListingNetware(lines, |
| 39 GetMockCurrentTime(), |
| 40 &entries)); |
| 41 VerifySingleLineTestCase(good_cases[i], entries); |
34 } | 42 } |
35 } | 43 } |
36 | 44 |
37 TEST_F(FtpDirectoryListingParserNetwareTest, Bad) { | 45 TEST_F(FtpDirectoryListingParserNetwareTest, Bad) { |
38 const char* bad_cases[] = { | 46 const char* bad_cases[] = { |
39 " foo", | 47 " foo", |
40 "garbage", | 48 "garbage", |
41 "d [] ftpadmin 512 Jan 29 2004 pub", | 49 "d [] ftpadmin 512 Jan 29 2004 pub", |
42 "d [XGARBAGE] ftpadmin 512 Jan 29 2004 pub", | 50 "d [XGARBAGE] ftpadmin 512 Jan 29 2004 pub", |
43 "d [RWCEAFMS] 512 Jan 29 2004 pub", | 51 "d [RWCEAFMS] 512 Jan 29 2004 pub", |
44 "d [RWCEAFMS] ftpadmin -1 Jan 29 2004 pub", | 52 "d [RWCEAFMS] ftpadmin -1 Jan 29 2004 pub", |
45 "l [RW------] ftpadmin 512 Jan 29 2004 pub", | 53 "l [RW------] ftpadmin 512 Jan 29 2004 pub", |
46 }; | 54 }; |
47 for (size_t i = 0; i < arraysize(bad_cases); i++) { | 55 for (size_t i = 0; i < arraysize(bad_cases); i++) { |
48 net::FtpDirectoryListingParserNetware parser(GetMockCurrentTime()); | 56 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
49 // The parser requires a "total n" like before accepting regular input. | 57 bad_cases[i])); |
50 ASSERT_TRUE(parser.ConsumeLine(UTF8ToUTF16("total 1"))); | 58 |
51 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i]; | 59 std::vector<string16> lines(GetSingleLineTestCase(bad_cases[i])); |
| 60 |
| 61 // The parser requires a "total n" line before accepting regular input. |
| 62 lines.insert(lines.begin(), ASCIIToUTF16("total 1")); |
| 63 |
| 64 std::vector<FtpDirectoryListingEntry> entries; |
| 65 EXPECT_FALSE(ParseFtpDirectoryListingNetware(lines, |
| 66 GetMockCurrentTime(), |
| 67 &entries)); |
52 } | 68 } |
53 } | 69 } |
54 | 70 |
55 } // namespace | 71 } // namespace |
| 72 |
| 73 } // namespace net |
OLD | NEW |