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