Home | History | Annotate | Download | only in ftp
      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 #include "net/ftp/ftp_directory_listing_parser_unittest.h"
      6 
      7 #include "base/format_macros.h"
      8 #include "base/string_util.h"
      9 #include "base/stringprintf.h"
     10 #include "base/utf_string_conversions.h"
     11 #include "net/ftp/ftp_directory_listing_parser_netware.h"
     12 
     13 namespace net {
     14 
     15 namespace {
     16 
     17 typedef FtpDirectoryListingParserTest FtpDirectoryListingParserNetwareTest;
     18 
     19 TEST_F(FtpDirectoryListingParserNetwareTest, Good) {
     20   const struct SingleLineTestData good_cases[] = {
     21     { "d [RWCEAFMS] ftpadmin 512 Jan 29  2004 pub",
     22       FtpDirectoryListingEntry::DIRECTORY, "pub", -1,
     23       2004, 1, 29, 0, 0 },
     24     { "- [RW------] ftpadmin 123 Nov 11  18:25 afile",
     25       FtpDirectoryListingEntry::FILE, "afile", 123,
     26       1994, 11, 11, 18, 25 },
     27   };
     28   for (size_t i = 0; i < arraysize(good_cases); i++) {
     29     SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
     30                                     good_cases[i].input));
     31 
     32     std::vector<string16> lines(GetSingleLineTestCase(good_cases[i].input));
     33 
     34     // The parser requires a "total n" line before accepting regular input.
     35     lines.insert(lines.begin(), ASCIIToUTF16("total 1"));
     36 
     37     std::vector<FtpDirectoryListingEntry> entries;
     38     EXPECT_TRUE(ParseFtpDirectoryListingNetware(lines,
     39                                                 GetMockCurrentTime(),
     40                                                 &entries));
     41     VerifySingleLineTestCase(good_cases[i], entries);
     42   }
     43 }
     44 
     45 TEST_F(FtpDirectoryListingParserNetwareTest, Bad) {
     46   const char* bad_cases[] = {
     47     " foo",
     48     "garbage",
     49     "d [] ftpadmin 512 Jan 29  2004 pub",
     50     "d [XGARBAGE] ftpadmin 512 Jan 29  2004 pub",
     51     "d [RWCEAFMS] 512 Jan 29  2004 pub",
     52     "d [RWCEAFMS] ftpadmin -1 Jan 29  2004 pub",
     53     "l [RW------] ftpadmin 512 Jan 29  2004 pub",
     54   };
     55   for (size_t i = 0; i < arraysize(bad_cases); i++) {
     56     SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
     57                                     bad_cases[i]));
     58 
     59     std::vector<string16> lines(GetSingleLineTestCase(bad_cases[i]));
     60 
     61     // The parser requires a "total n" line before accepting regular input.
     62     lines.insert(lines.begin(), ASCIIToUTF16("total 1"));
     63 
     64     std::vector<FtpDirectoryListingEntry> entries;
     65     EXPECT_FALSE(ParseFtpDirectoryListingNetware(lines,
     66                                                  GetMockCurrentTime(),
     67                                                  &entries));
     68   }
     69 }
     70 
     71 }  // namespace
     72 
     73 }  // namespace net
     74