Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Unified Diff: third_party/zlib/google/zip_reader_unittest.cc

Issue 166573007: Remove some PlatformFile uses from zlib (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Yet another rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/zlib/google/zip_reader.cc ('k') | third_party/zlib/google/zip_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/zlib/google/zip_reader_unittest.cc
diff --git a/third_party/zlib/google/zip_reader_unittest.cc b/third_party/zlib/google/zip_reader_unittest.cc
index 2033f9fa002c2db2de3510d39a81c5bd39ea27c5..df20e6fe3367a93cb810dd8c5008b821bf2ad444 100644
--- a/third_party/zlib/google/zip_reader_unittest.cc
+++ b/third_party/zlib/google/zip_reader_unittest.cc
@@ -9,11 +9,11 @@
#include "base/bind.h"
#include "base/file_util.h"
+#include "base/files/file.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/md5.h"
#include "base/path_service.h"
-#include "base/platform_file.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
@@ -25,44 +25,29 @@ namespace {
const static std::string kQuuxExpectedMD5 = "d1ae4ac8a17a0e09317113ab284b57a6";
-// Wrap PlatformFiles in a class so that we don't leak them in tests.
-class PlatformFileWrapper {
+class FileWrapper {
public:
typedef enum {
READ_ONLY,
READ_WRITE
} AccessMode;
- PlatformFileWrapper(const base::FilePath& file, AccessMode mode)
- : file_(base::kInvalidPlatformFileValue) {
- switch (mode) {
- case READ_ONLY:
- file_ = base::CreatePlatformFile(file,
- base::PLATFORM_FILE_OPEN |
- base::PLATFORM_FILE_READ,
- NULL, NULL);
- break;
- case READ_WRITE:
- file_ = base::CreatePlatformFile(file,
- base::PLATFORM_FILE_CREATE_ALWAYS |
- base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_WRITE,
- NULL, NULL);
- break;
- default:
- NOTREACHED();
- }
- return;
- }
+ FileWrapper(const base::FilePath& path, AccessMode mode) {
+ int flags = base::File::FLAG_READ;
+ if (mode == READ_ONLY)
+ flags |= base::File::FLAG_OPEN;
+ else
+ flags |= base::File::FLAG_WRITE | base::File::FLAG_CREATE_ALWAYS;
- ~PlatformFileWrapper() {
- base::ClosePlatformFile(file_);
+ file_.Initialize(path, flags);
}
- base::PlatformFile platform_file() { return file_; }
+ ~FileWrapper() {}
+
+ base::PlatformFile platform_file() { return file_.GetPlatformFile(); }
private:
- base::PlatformFile file_;
+ base::File file_;
};
// A mock that provides methods that can be used as callbacks in asynchronous
@@ -70,7 +55,7 @@ class PlatformFileWrapper {
// Assumes that progress callbacks will be executed in-order.
class MockUnzipListener : public base::SupportsWeakPtr<MockUnzipListener> {
public:
- MockUnzipListener()
+ MockUnzipListener()
: success_calls_(0),
failure_calls_(0),
progress_calls_(0),
@@ -195,8 +180,7 @@ TEST_F(ZipReaderTest, Open_ValidZipFile) {
TEST_F(ZipReaderTest, Open_ValidZipPlatformFile) {
ZipReader reader;
- PlatformFileWrapper zip_fd_wrapper(test_zip_file_,
- PlatformFileWrapper::READ_ONLY);
+ FileWrapper zip_fd_wrapper(test_zip_file_, FileWrapper::READ_ONLY);
ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file()));
}
@@ -233,8 +217,7 @@ TEST_F(ZipReaderTest, Iteration) {
TEST_F(ZipReaderTest, PlatformFileIteration) {
std::set<base::FilePath> actual_contents;
ZipReader reader;
- PlatformFileWrapper zip_fd_wrapper(test_zip_file_,
- PlatformFileWrapper::READ_ONLY);
+ FileWrapper zip_fd_wrapper(test_zip_file_, FileWrapper::READ_ONLY);
ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file()));
while (reader.HasMore()) {
ASSERT_TRUE(reader.OpenCurrentEntryInZip());
@@ -286,8 +269,7 @@ TEST_F(ZipReaderTest, ExtractCurrentEntryToFilePath_RegularFile) {
TEST_F(ZipReaderTest, PlatformFileExtractCurrentEntryToFilePath_RegularFile) {
ZipReader reader;
- PlatformFileWrapper zip_fd_wrapper(test_zip_file_,
- PlatformFileWrapper::READ_ONLY);
+ FileWrapper zip_fd_wrapper(test_zip_file_, FileWrapper::READ_ONLY);
ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file()));
base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
@@ -307,12 +289,11 @@ TEST_F(ZipReaderTest, PlatformFileExtractCurrentEntryToFilePath_RegularFile) {
#if defined(OS_POSIX)
TEST_F(ZipReaderTest, PlatformFileExtractCurrentEntryToFd_RegularFile) {
ZipReader reader;
- PlatformFileWrapper zip_fd_wrapper(test_zip_file_,
- PlatformFileWrapper::READ_ONLY);
+ FileWrapper zip_fd_wrapper(test_zip_file_, FileWrapper::READ_ONLY);
ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file()));
base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
base::FilePath out_path = test_dir_.AppendASCII("quux.txt");
- PlatformFileWrapper out_fd_w(out_path, PlatformFileWrapper::READ_WRITE);
+ FileWrapper out_fd_w(out_path, FileWrapper::READ_WRITE);
ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
ASSERT_TRUE(reader.ExtractCurrentEntryToFd(out_fd_w.platform_file()));
// Read the output file and compute the MD5.
« no previous file with comments | « third_party/zlib/google/zip_reader.cc ('k') | third_party/zlib/google/zip_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698