forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftp_directory_listing_parser_unittest.h
76 lines (60 loc) · 2.26 KB
/
ftp_directory_listing_parser_unittest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_
#define NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_
#include <vector>
#include "base/strings/utf_string_conversions.h"
#include "net/ftp/ftp_directory_listing_parser.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
class FtpDirectoryListingParserTest : public testing::Test {
public:
struct SingleLineTestData {
const char* input;
FtpDirectoryListingEntry::Type type;
const char* filename;
int64 size;
int year;
int month;
int day_of_month;
int hour;
int minute;
};
protected:
FtpDirectoryListingParserTest() {}
std::vector<base::string16> GetSingleLineTestCase(const std::string& text) {
std::vector<base::string16> lines;
lines.push_back(UTF8ToUTF16(text));
return lines;
}
void VerifySingleLineTestCase(
const SingleLineTestData& test_case,
const std::vector<FtpDirectoryListingEntry>& entries) {
ASSERT_FALSE(entries.empty());
FtpDirectoryListingEntry entry = entries[0];
EXPECT_EQ(test_case.type, entry.type);
EXPECT_EQ(UTF8ToUTF16(test_case.filename), entry.name);
EXPECT_EQ(test_case.size, entry.size);
base::Time::Exploded time_exploded;
entry.last_modified.LocalExplode(&time_exploded);
// Only test members displayed on the directory listing.
EXPECT_EQ(test_case.year, time_exploded.year);
EXPECT_EQ(test_case.month, time_exploded.month);
EXPECT_EQ(test_case.day_of_month, time_exploded.day_of_month);
EXPECT_EQ(test_case.hour, time_exploded.hour);
EXPECT_EQ(test_case.minute, time_exploded.minute);
EXPECT_EQ(1U, entries.size());
}
base::Time GetMockCurrentTime() {
base::Time::Exploded mock_current_time_exploded = { 0 };
mock_current_time_exploded.year = 1994;
mock_current_time_exploded.month = 11;
mock_current_time_exploded.day_of_month = 15;
mock_current_time_exploded.hour = 12;
mock_current_time_exploded.minute = 45;
return base::Time::FromLocalExploded(mock_current_time_exploded);
}
};
} // namespace net
#endif // NET_FTP_FTP_DIRECTORY_LISTING_PARSER_UNITTEST_H_