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