1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 2 // source code is governed by a BSD-style license that can be found in the 3 // LICENSE file. 4 5 #ifndef NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_ 6 #define NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_ 7 8 #include "base/string_util.h" 9 #include "net/ftp/ftp_directory_listing_parser.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 12 namespace net { 13 14 class FtpDirectoryListingParserTest : public testing::Test { 15 public: 16 struct SingleLineTestData { 17 const char* input; 18 FtpDirectoryListingEntry::Type type; 19 const char* filename; 20 int64 size; 21 int year; 22 int month; 23 int day_of_month; 24 int hour; 25 int minute; 26 }; 27 28 protected: 29 FtpDirectoryListingParserTest() { 30 } 31 32 void RunSingleLineTestCase(FtpDirectoryListingParser* parser, 33 const SingleLineTestData& test_case) { 34 ASSERT_TRUE(parser->ConsumeLine(UTF8ToUTF16(test_case.input))); 35 ASSERT_TRUE(parser->EntryAvailable()); 36 FtpDirectoryListingEntry entry = parser->PopEntry(); 37 EXPECT_EQ(test_case.type, entry.type); 38 EXPECT_EQ(UTF8ToUTF16(test_case.filename), entry.name); 39 EXPECT_EQ(test_case.size, entry.size); 40 41 base::Time::Exploded time_exploded; 42 entry.last_modified.LocalExplode(&time_exploded); 43 EXPECT_EQ(test_case.year, time_exploded.year); 44 EXPECT_EQ(test_case.month, time_exploded.month); 45 EXPECT_EQ(test_case.day_of_month, time_exploded.day_of_month); 46 EXPECT_EQ(test_case.hour, time_exploded.hour); 47 EXPECT_EQ(test_case.minute, time_exploded.minute); 48 EXPECT_EQ(0, time_exploded.second); 49 EXPECT_EQ(0, time_exploded.millisecond); 50 } 51 52 private: 53 DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingParserTest); 54 }; 55 56 } // namespace net 57 58 #endif // NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_ 59 60