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