OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 { | 13 namespace { |
14 | 14 |
15 typedef net::FtpDirectoryListingParserTest FtpDirectoryListingParserNetwareTest; | 15 typedef net::FtpDirectoryListingParserTest FtpDirectoryListingParserNetwareTest; |
16 | 16 |
17 TEST_F(FtpDirectoryListingParserNetwareTest, Good) { | 17 TEST_F(FtpDirectoryListingParserNetwareTest, Good) { |
18 base::Time mock_current_time; | |
19 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994 12:45:26 GMT", | |
20 &mock_current_time)); | |
21 | |
22 const struct SingleLineTestData good_cases[] = { | 18 const struct SingleLineTestData good_cases[] = { |
23 { "d [RWCEAFMS] ftpadmin 512 Jan 29 2004 pub", | 19 { "d [RWCEAFMS] ftpadmin 512 Jan 29 2004 pub", |
24 net::FtpDirectoryListingEntry::DIRECTORY, "pub", -1, | 20 net::FtpDirectoryListingEntry::DIRECTORY, "pub", -1, |
25 2004, 1, 29, 0, 0 }, | 21 2004, 1, 29, 0, 0 }, |
26 { "- [RW------] ftpadmin 123 Nov 11 18:25 afile", | 22 { "- [RW------] ftpadmin 123 Nov 11 18:25 afile", |
27 net::FtpDirectoryListingEntry::FILE, "afile", 123, | 23 net::FtpDirectoryListingEntry::FILE, "afile", 123, |
28 1994, 11, 11, 18, 25 }, | 24 1994, 11, 11, 18, 25 }, |
29 }; | 25 }; |
30 for (size_t i = 0; i < arraysize(good_cases); i++) { | 26 for (size_t i = 0; i < arraysize(good_cases); i++) { |
31 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, | 27 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
32 good_cases[i].input)); | 28 good_cases[i].input)); |
33 | 29 |
34 net::FtpDirectoryListingParserNetware parser(mock_current_time); | 30 net::FtpDirectoryListingParserNetware parser(GetMockCurrentTime()); |
35 // The parser requires a "total n" like before accepting regular input. | 31 // The parser requires a "total n" like before accepting regular input. |
36 ASSERT_TRUE(parser.ConsumeLine(UTF8ToUTF16("total 1"))); | 32 ASSERT_TRUE(parser.ConsumeLine(UTF8ToUTF16("total 1"))); |
37 RunSingleLineTestCase(&parser, good_cases[i]); | 33 RunSingleLineTestCase(&parser, good_cases[i]); |
38 } | 34 } |
39 } | 35 } |
40 | 36 |
41 TEST_F(FtpDirectoryListingParserNetwareTest, Bad) { | 37 TEST_F(FtpDirectoryListingParserNetwareTest, Bad) { |
42 base::Time mock_current_time; | |
43 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994 12:45:26 GMT", | |
44 &mock_current_time)); | |
45 | |
46 const char* bad_cases[] = { | 38 const char* bad_cases[] = { |
| 39 " foo", |
47 "garbage", | 40 "garbage", |
48 "d [] ftpadmin 512 Jan 29 2004 pub", | 41 "d [] ftpadmin 512 Jan 29 2004 pub", |
49 "d [XGARBAGE] ftpadmin 512 Jan 29 2004 pub", | 42 "d [XGARBAGE] ftpadmin 512 Jan 29 2004 pub", |
50 "d [RWCEAFMS] 512 Jan 29 2004 pub", | 43 "d [RWCEAFMS] 512 Jan 29 2004 pub", |
51 "d [RWCEAFMS] ftpadmin -1 Jan 29 2004 pub", | 44 "d [RWCEAFMS] ftpadmin -1 Jan 29 2004 pub", |
52 "l [RW------] ftpadmin 512 Jan 29 2004 pub", | 45 "l [RW------] ftpadmin 512 Jan 29 2004 pub", |
53 }; | 46 }; |
54 for (size_t i = 0; i < arraysize(bad_cases); i++) { | 47 for (size_t i = 0; i < arraysize(bad_cases); i++) { |
55 net::FtpDirectoryListingParserNetware parser(mock_current_time); | 48 net::FtpDirectoryListingParserNetware parser(GetMockCurrentTime()); |
56 // The parser requires a "total n" like before accepting regular input. | 49 // The parser requires a "total n" like before accepting regular input. |
57 ASSERT_TRUE(parser.ConsumeLine(UTF8ToUTF16("total 1"))); | 50 ASSERT_TRUE(parser.ConsumeLine(UTF8ToUTF16("total 1"))); |
58 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i]; | 51 EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i]; |
59 } | 52 } |
60 } | 53 } |
61 | 54 |
62 } // namespace | 55 } // namespace |
OLD | NEW |