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.h" |
10 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
12 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.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 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 274 } |
274 | 275 |
275 #if defined(OS_POSIX) | 276 #if defined(OS_POSIX) |
276 TEST_F(ZipTest, ZipFiles) { | 277 TEST_F(ZipTest, ZipFiles) { |
277 base::FilePath src_dir; | 278 base::FilePath src_dir; |
278 ASSERT_TRUE(GetTestDataDirectory(&src_dir)); | 279 ASSERT_TRUE(GetTestDataDirectory(&src_dir)); |
279 src_dir = src_dir.AppendASCII("test"); | 280 src_dir = src_dir.AppendASCII("test"); |
280 | 281 |
281 base::ScopedTempDir temp_dir; | 282 base::ScopedTempDir temp_dir; |
282 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 283 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
283 base::FilePath zip_file = temp_dir.path().AppendASCII("out.zip"); | 284 base::FilePath zip_name = temp_dir.path().AppendASCII("out.zip"); |
284 | 285 |
285 const int flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; | 286 base::File zip_file(zip_name, |
286 const base::PlatformFile zip_fd = | 287 base::File::FLAG_CREATE | base::File::FLAG_WRITE); |
287 base::CreatePlatformFile(zip_file, flags, NULL, NULL); | 288 ASSERT_TRUE(zip_file.IsValid()); |
288 ASSERT_LE(0, zip_fd); | 289 EXPECT_TRUE(zip::ZipFiles(src_dir, zip_file_list_, |
289 EXPECT_TRUE(zip::ZipFiles(src_dir, zip_file_list_, zip_fd)); | 290 zip_file.GetPlatformFile())); |
290 base::ClosePlatformFile(zip_fd); | 291 zip_file.Close(); |
291 | 292 |
292 zip::ZipReader reader; | 293 zip::ZipReader reader; |
293 EXPECT_TRUE(reader.Open(zip_file)); | 294 EXPECT_TRUE(reader.Open(zip_name)); |
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 |
304 } // namespace | 305 } // namespace |
305 | |
OLD | NEW |