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 #ifndef NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_ | 5 #ifndef NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_ |
6 #define NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_ | 6 #define NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
| 9 #include <vector> |
| 10 |
9 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
10 #include "net/ftp/ftp_directory_listing_parser.h" | 12 #include "net/ftp/ftp_directory_listing_parser.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 namespace net { | 15 namespace net { |
14 | 16 |
15 class FtpDirectoryListingParserTest : public testing::Test { | 17 class FtpDirectoryListingParserTest : public testing::Test { |
16 public: | 18 public: |
17 struct SingleLineTestData { | 19 struct SingleLineTestData { |
18 const char* input; | 20 const char* input; |
19 FtpDirectoryListingEntry::Type type; | 21 FtpDirectoryListingEntry::Type type; |
20 const char* filename; | 22 const char* filename; |
21 int64 size; | 23 int64 size; |
22 int year; | 24 int year; |
23 int month; | 25 int month; |
24 int day_of_month; | 26 int day_of_month; |
25 int hour; | 27 int hour; |
26 int minute; | 28 int minute; |
27 }; | 29 }; |
28 | 30 |
29 protected: | 31 protected: |
30 FtpDirectoryListingParserTest() {} | 32 FtpDirectoryListingParserTest() {} |
31 | 33 |
32 void RunSingleLineTestCase(FtpDirectoryListingParser* parser, | 34 std::vector<string16> GetSingleLineTestCase(const std::string& text) { |
33 const SingleLineTestData& test_case) { | 35 std::vector<string16> lines; |
34 ASSERT_TRUE(parser->ConsumeLine(UTF8ToUTF16(test_case.input))); | 36 lines.push_back(UTF8ToUTF16(text)); |
35 ASSERT_TRUE(parser->EntryAvailable()); | 37 return lines; |
36 FtpDirectoryListingEntry entry = parser->PopEntry(); | 38 } |
| 39 |
| 40 void VerifySingleLineTestCase( |
| 41 const SingleLineTestData& test_case, |
| 42 const std::vector<FtpDirectoryListingEntry>& entries) { |
| 43 ASSERT_FALSE(entries.empty()); |
| 44 |
| 45 FtpDirectoryListingEntry entry = entries[0]; |
37 EXPECT_EQ(test_case.type, entry.type); | 46 EXPECT_EQ(test_case.type, entry.type); |
38 EXPECT_EQ(UTF8ToUTF16(test_case.filename), entry.name); | 47 EXPECT_EQ(UTF8ToUTF16(test_case.filename), entry.name); |
39 EXPECT_EQ(test_case.size, entry.size); | 48 EXPECT_EQ(test_case.size, entry.size); |
40 | 49 |
41 base::Time::Exploded time_exploded; | 50 base::Time::Exploded time_exploded; |
42 entry.last_modified.LocalExplode(&time_exploded); | 51 entry.last_modified.LocalExplode(&time_exploded); |
43 | 52 |
44 // Only test members displayed on the directory listing. | 53 // Only test members displayed on the directory listing. |
45 EXPECT_EQ(test_case.year, time_exploded.year); | 54 EXPECT_EQ(test_case.year, time_exploded.year); |
46 EXPECT_EQ(test_case.month, time_exploded.month); | 55 EXPECT_EQ(test_case.month, time_exploded.month); |
47 EXPECT_EQ(test_case.day_of_month, time_exploded.day_of_month); | 56 EXPECT_EQ(test_case.day_of_month, time_exploded.day_of_month); |
48 EXPECT_EQ(test_case.hour, time_exploded.hour); | 57 EXPECT_EQ(test_case.hour, time_exploded.hour); |
49 EXPECT_EQ(test_case.minute, time_exploded.minute); | 58 EXPECT_EQ(test_case.minute, time_exploded.minute); |
| 59 |
| 60 EXPECT_EQ(1U, entries.size()); |
50 } | 61 } |
51 | 62 |
52 base::Time GetMockCurrentTime() { | 63 base::Time GetMockCurrentTime() { |
53 base::Time::Exploded mock_current_time_exploded = { 0 }; | 64 base::Time::Exploded mock_current_time_exploded = { 0 }; |
54 mock_current_time_exploded.year = 1994; | 65 mock_current_time_exploded.year = 1994; |
55 mock_current_time_exploded.month = 11; | 66 mock_current_time_exploded.month = 11; |
56 mock_current_time_exploded.day_of_month = 15; | 67 mock_current_time_exploded.day_of_month = 15; |
57 mock_current_time_exploded.hour = 12; | 68 mock_current_time_exploded.hour = 12; |
58 mock_current_time_exploded.minute = 45; | 69 mock_current_time_exploded.minute = 45; |
59 return base::Time::FromLocalExploded(mock_current_time_exploded); | 70 return base::Time::FromLocalExploded(mock_current_time_exploded); |
60 } | 71 } |
61 | |
62 private: | |
63 DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingParserTest); | |
64 }; | 72 }; |
65 | 73 |
66 } // namespace net | 74 } // namespace net |
67 | 75 |
68 #endif // NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_ | 76 #endif // NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_ |
69 | 77 |
OLD | NEW |