Chromium Code Reviews| Index: third_party/zlib/google/zip_unittest.cc |
| diff --git a/third_party/zlib/google/zip_unittest.cc b/third_party/zlib/google/zip_unittest.cc |
| index 1023705f1b8b33e466b5625759be42eabbf36935..80723e1c26a096878e5580736f22683ada524634 100644 |
| --- a/third_party/zlib/google/zip_unittest.cc |
| +++ b/third_party/zlib/google/zip_unittest.cc |
| @@ -3,6 +3,7 @@ |
| // found in the LICENSE file. |
| #include <set> |
| +#include <string> |
| #include <vector> |
| #include "base/file_util.h" |
| @@ -98,6 +99,43 @@ class ZipTest : public PlatformTest { |
| EXPECT_EQ(expected_count, count); |
| } |
| + void TestTimeStamp(const char* date_time, bool valid_year) { |
|
satorux1
2013/12/12 08:03:57
This function was a bit hard to follow.
Could you
|
| + SCOPED_TRACE(std::string("TestTimeStamp(") + date_time + ")"); |
| + base::ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + |
| + base::FilePath zip_file = temp_dir.path().AppendASCII("out.zip"); |
| + base::FilePath src_dir = temp_dir.path().AppendASCII("input"); |
| + base::FilePath out_dir = temp_dir.path().AppendASCII("output"); |
| + |
| + base::FilePath src_file = src_dir.AppendASCII("test.txt"); |
| + base::FilePath out_file = out_dir.AppendASCII("test.txt"); |
| + |
| + EXPECT_TRUE(base::CreateDirectory(src_dir)); |
| + EXPECT_TRUE(base::CreateDirectory(out_dir)); |
| + |
| + base::Time test_mtime; |
| + ASSERT_TRUE(base::Time::FromString(date_time, &test_mtime)); |
| + base::Time now_time = base::Time::Now() - base::TimeDelta::FromSeconds(1); |
| + |
| + EXPECT_EQ(1, file_util::WriteFile(src_file, "1", 1)); |
| + EXPECT_TRUE(base::TouchFile(src_file, base::Time::Now(), test_mtime)); |
| + |
| + EXPECT_TRUE(zip::Zip(src_dir, zip_file, true)); |
| + ASSERT_TRUE(zip::Unzip(zip_file, out_dir)); |
| + |
| + base::PlatformFileInfo file_info; |
| + EXPECT_TRUE(base::GetFileInfo(out_file, &file_info)); |
| + EXPECT_EQ(file_info.size, 1); |
| + |
| + if (valid_year) { |
| + EXPECT_EQ(file_info.last_modified, test_mtime); |
| + } else { |
| + // Invalid date means the modification time will default to 'now'. |
|
satorux1
2013/12/12 08:03:57
now? I thought it's Unix Epoch. If so, please make
|
| + EXPECT_GE(file_info.last_modified, now_time); |
| + } |
| + } |
| + |
| // The path to temporary directory used to contain the test operations. |
| base::FilePath test_dir_; |
| @@ -192,6 +230,38 @@ TEST_F(ZipTest, ZipNonASCIIDir) { |
| TestUnzipFile(zip_file, true); |
| } |
| +TEST_F(ZipTest, ZipTimeStamp) { |
| + // The dates tested are arbitrary, with some constraints. The zip format can |
| + // only store years from 1980 to 2107 and an even number of seconds, due to it |
| + // using the ms dos date format. |
| + |
| + // Valid arbitrary date. |
| + TestTimeStamp("23 Oct 1997 23:22:20", true); |
| + |
| + // Date before 1980, zip format limitation, must default to unix epoch. |
| + TestTimeStamp("29 Dec 1979 21:00:10", false); |
| + |
| + // Despite the minizip headers telling the maximum year should be 2044, it |
| + // can actually go up to 2107. Beyond that, the dos date format cannot store |
| + // the year (2107-1980=127). To test that limit, the input file needs to be |
| + // touched, but the code that modifies the file access and modification times |
| + // relies on time_t which is defined as long, therefore being in many |
| + // platforms just a 4-byte integer, like 32-bit Mac OSX or linux. As such, it |
| + // suffers from the year-2038 bug. Therefore 2038 is the highest we can test |
| + // in all platforms reliably. |
| + TestTimeStamp("02 Jan 2038 23:59:58", true); |
| + |
| + // And here the year-2038 bug is avoided. |
| +#if defined(OS_POSIX) |
| + if (sizeof(time_t) == 8) |
| +#elif defined(OS_WIN) |
| + if (true) |
| +#else |
| + if (false) |
|
satorux1
2013/12/12 08:03:57
The #if-defs are complicated. I'd suggest remove t
|
| +#endif |
| + TestTimeStamp("31 Oct 2107 23:59:58", true); |
| +} |
| + |
| #if defined(OS_POSIX) |
| TEST_F(ZipTest, ZipFiles) { |
| base::FilePath src_dir; |