OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" |
17 #include "third_party/zlib/google/zip.h" | 18 #include "third_party/zlib/google/zip.h" |
18 #include "third_party/zlib/google/zip_reader.h" | 19 #include "third_party/zlib/google/zip_reader.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Make the test a PlatformTest to setup autorelease pools properly on Mac. | 23 // Make the test a PlatformTest to setup autorelease pools properly on Mac. |
23 class ZipTest : public PlatformTest { | 24 class ZipTest : public PlatformTest { |
24 protected: | 25 protected: |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 EXPECT_EQ(zip_file_list_.size(), static_cast<size_t>(reader.num_entries())); | 295 EXPECT_EQ(zip_file_list_.size(), static_cast<size_t>(reader.num_entries())); |
295 for (size_t i = 0; i < zip_file_list_.size(); ++i) { | 296 for (size_t i = 0; i < zip_file_list_.size(); ++i) { |
296 EXPECT_TRUE(reader.LocateAndOpenEntry(zip_file_list_[i])); | 297 EXPECT_TRUE(reader.LocateAndOpenEntry(zip_file_list_[i])); |
297 // Check the path in the entry just in case. | 298 // Check the path in the entry just in case. |
298 const zip::ZipReader::EntryInfo* entry_info = reader.current_entry_info(); | 299 const zip::ZipReader::EntryInfo* entry_info = reader.current_entry_info(); |
299 EXPECT_EQ(entry_info->file_path(), zip_file_list_[i]); | 300 EXPECT_EQ(entry_info->file_path(), zip_file_list_[i]); |
300 } | 301 } |
301 } | 302 } |
302 #endif // defined(OS_POSIX) | 303 #endif // defined(OS_POSIX) |
303 | 304 |
| 305 TEST_F(ZipTest, UnzipFilesWithIncorrectSize) { |
| 306 base::FilePath test_data_folder; |
| 307 ASSERT_TRUE(GetTestDataDirectory(&test_data_folder)); |
| 308 |
| 309 // test_mismatch_size.zip contains files with names from 0.txt to 7.txt with |
| 310 // sizes from 0 to 7 respectively, but the metadata in the zip file says the |
| 311 // size is 3 bytes. The reader code needs to be clever enough to get all the |
| 312 // data out. |
| 313 base::FilePath test_zip_file = |
| 314 test_data_folder.AppendASCII("test_mismatch_size.zip"); |
| 315 |
| 316 base::ScopedTempDir scoped_temp_dir; |
| 317 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 318 const base::FilePath& temp_dir = scoped_temp_dir.path(); |
| 319 |
| 320 ASSERT_TRUE(zip::Unzip(test_zip_file, temp_dir)); |
| 321 |
| 322 EXPECT_TRUE(base::DirectoryExists(temp_dir.AppendASCII("d"))); |
| 323 |
| 324 for (int k = 0; k < 8; k++) { |
| 325 SCOPED_TRACE(base::StringPrintf("<loop:%d>", static_cast<int>(k))); |
| 326 base::FilePath file_path = temp_dir.AppendASCII( |
| 327 base::StringPrintf(FILE_PATH_LITERAL("%d.txt"), static_cast<int>(k))); |
| 328 int64 file_size = -1; |
| 329 EXPECT_TRUE(base::GetFileSize(file_path, &file_size)); |
| 330 EXPECT_EQ(file_size, static_cast<int64>(k)); |
| 331 } |
| 332 } |
| 333 |
304 } // namespace | 334 } // namespace |
305 | 335 |
OLD | NEW |