1// Copyright (c) 2009 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#include "net/ftp/ftp_directory_listing_parser_unittest.h"
6
7#include "base/format_macros.h"
8#include "net/ftp/ftp_directory_listing_parser_windows.h"
9
10namespace {
11
12typedef net::FtpDirectoryListingParserTest FtpDirectoryListingParserWindowsTest;
13
14TEST_F(FtpDirectoryListingParserWindowsTest, Good) {
15  base::Time::Exploded now_exploded;
16  base::Time::Now().LocalExplode(&now_exploded);
17
18  const struct SingleLineTestData good_cases[] = {
19    { "11-02-09  05:32PM       <DIR>          NT",
20      net::FtpDirectoryListingEntry::DIRECTORY, "NT", -1,
21      2009, 11, 2, 17, 32 },
22    { "01-06-09  02:42PM                  458 Readme.txt",
23      net::FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
24      2009, 1, 6, 14, 42 },
25    { "01-06-09  02:42AM                  1 Readme.txt",
26      net::FtpDirectoryListingEntry::FILE, "Readme.txt", 1,
27      2009, 1, 6, 2, 42 },
28    { "01-06-01  02:42AM                  458 Readme.txt",
29      net::FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
30      2001, 1, 6, 2, 42 },
31    { "01-06-00  02:42AM                  458 Corner1.txt",
32      net::FtpDirectoryListingEntry::FILE, "Corner1.txt", 458,
33      2000, 1, 6, 2, 42 },
34    { "01-06-99  02:42AM                  458 Corner2.txt",
35      net::FtpDirectoryListingEntry::FILE, "Corner2.txt", 458,
36      1999, 1, 6, 2, 42 },
37    { "01-06-80  02:42AM                  458 Corner3.txt",
38      net::FtpDirectoryListingEntry::FILE, "Corner3.txt", 458,
39      1980, 1, 6, 2, 42 },
40#if !defined(OS_LINUX)
41    // TODO(phajdan.jr): Re-enable when 2038-year problem is fixed on Linux.
42    { "01-06-79  02:42AM                  458 Corner4",
43      net::FtpDirectoryListingEntry::FILE, "Corner4", 458,
44      2079, 1, 6, 2, 42 },
45#endif  // !defined (OS_LINUX)
46    { "01-06-1979  02:42AM                458 Readme.txt",
47      net::FtpDirectoryListingEntry::FILE, "Readme.txt", 458,
48      1979, 1, 6, 2, 42 },
49    { "11-02-09  05:32PM       <DIR>          My Directory",
50      net::FtpDirectoryListingEntry::DIRECTORY, "My Directory", -1,
51      2009, 11, 2, 17, 32 },
52  };
53  for (size_t i = 0; i < arraysize(good_cases); i++) {
54    SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, good_cases[i].input));
55
56    net::FtpDirectoryListingParserWindows parser;
57    RunSingleLineTestCase(&parser, good_cases[i]);
58  }
59}
60
61TEST_F(FtpDirectoryListingParserWindowsTest, Bad) {
62  const char* bad_cases[] = {
63    "",
64    "garbage",
65    "11-02-09  05:32PM       <GARBAGE>      NT",
66    "11-02-09  05:32         <DIR>          NT",
67    "11-FEB-09 05:32PM       <DIR>          NT",
68    "11-02     05:32PM       <DIR>          NT",
69    "11-02-09  05:32PM                 -1   NT",
70  };
71  for (size_t i = 0; i < arraysize(bad_cases); i++) {
72    net::FtpDirectoryListingParserWindows parser;
73    EXPECT_FALSE(parser.ConsumeLine(UTF8ToUTF16(bad_cases[i]))) << bad_cases[i];
74  }
75}
76
77}  // namespace
78