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

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

Issue 2961373002: Improve Zip File Scanning on Mac (Closed)
Patch Set: avoiding multiple calls to unzReadCurrentFile Created 3 years, 5 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') | no next file » | 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 3056aba8ab855d03c91d35c71e7da24db721bdaa..21dddb9aef5f78930c34b55e8f1310188900d0fe 100644
--- a/third_party/zlib/google/zip_reader_unittest.cc
+++ b/third_party/zlib/google/zip_reader_unittest.cc
@@ -588,6 +588,47 @@ TEST_F(ZipReaderTest, ExtractCurrentEntryToString) {
reader.Close();
}
+TEST_F(ZipReaderTest, ExtractPartOfCurrentEntry) {
+ // test_mismatch_size.zip contains files with names from 0.txt to 7.txt with
+ // sizes from 0 to 7 bytes respectively, being the contents of each file a
+ // substring of "0123456" starting at '0'.
+ base::FilePath test_zip_file =
+ test_data_dir_.AppendASCII("test_mismatch_size.zip");
+
+ ZipReader reader;
+ std::string contents;
+ ASSERT_TRUE(reader.Open(test_zip_file));
+
+ base::FilePath file_name0 = base::FilePath::FromUTF8Unsafe("0.txt");
+ ASSERT_TRUE(reader.LocateAndOpenEntry(file_name0));
+ EXPECT_TRUE(reader.ExtractCurrentEntryToString(0, &contents));
+ EXPECT_EQ(0, memcmp(contents.c_str(), "", 0));
satorux1 2017/08/01 08:01:09 EXPECT_EQ("", contents)?
mortonm 2017/08/01 16:16:46 Done.
+ EXPECT_TRUE(reader.ExtractCurrentEntryToString(1, &contents));
+ EXPECT_EQ(0, memcmp(contents.c_str(), "", 0));
satorux1 2017/08/01 08:01:09 EXPECT_EQ("", contents)?
mortonm 2017/08/01 16:16:46 Done.
+
+ base::FilePath file_name1 = base::FilePath::FromUTF8Unsafe("1.txt");
+ ASSERT_TRUE(reader.LocateAndOpenEntry(file_name1));
+ EXPECT_TRUE(reader.ExtractCurrentEntryToString(0, &contents));
+ EXPECT_EQ(0, memcmp(contents.c_str(), "", 0));
satorux1 2017/08/01 08:01:09 EXPECT_EQ("", contents)?
mortonm 2017/08/01 16:16:46 Done.
+ EXPECT_TRUE(reader.ExtractCurrentEntryToString(1, &contents));
+ EXPECT_EQ(0, memcmp(contents.c_str(), "0", 1));
satorux1 2017/08/01 08:01:09 EXPECT_EQ("0", contents)?
mortonm 2017/08/01 16:16:46 Done.
+ EXPECT_TRUE(reader.ExtractCurrentEntryToString(2, &contents));
+ EXPECT_EQ(0, memcmp(contents.c_str(), "0", 1));
satorux1 2017/08/01 08:01:09 EXPECT_EQ("0", contents)?
mortonm 2017/08/01 16:16:46 Done.
+
+ base::FilePath file_name4 = base::FilePath::FromUTF8Unsafe("4.txt");
+ ASSERT_TRUE(reader.LocateAndOpenEntry(file_name4));
+ EXPECT_TRUE(reader.ExtractCurrentEntryToString(0, &contents));
satorux1 2017/08/01 08:01:09 EXPECT_EQ("", contents)?
mortonm 2017/08/01 16:16:46 Done.
+ EXPECT_EQ(0, memcmp(contents.c_str(), "", 0));
+ EXPECT_FALSE(reader.ExtractCurrentEntryToString(2, &contents));
+ EXPECT_EQ(0, memcmp(contents.c_str(), "01", 2));
satorux1 2017/08/01 08:01:09 EXPECT_EQ("01", contents)?
mortonm 2017/08/01 16:16:46 Done.
+ EXPECT_TRUE(reader.ExtractCurrentEntryToString(4, &contents));
+ EXPECT_EQ(0, memcmp(contents.c_str(), "0123", 4));
satorux1 2017/08/01 08:01:09 EXPECT_EQ("0123", contents)?
mortonm 2017/08/01 16:16:46 Done.
+ EXPECT_TRUE(reader.ExtractCurrentEntryToString(5, &contents));
+ EXPECT_EQ(0, memcmp(contents.c_str(), "0123", 0));
satorux1 2017/08/01 08:01:09 0 here does not look correct. EXPECT_EQ("0123", c
mortonm 2017/08/01 16:16:46 The file is only 4 characters long. I am checking
+
+ reader.Close();
+}
+
// This test exposes http://crbug.com/430959, at least on OS X
TEST_F(ZipReaderTest, DISABLED_LeakDetectionTest) {
for (int i = 0; i < 100000; ++i) {
@@ -610,7 +651,8 @@ TEST_F(ZipReaderTest, ExtractCurrentEntryPrepareFailure) {
ASSERT_TRUE(reader.Open(test_zip_file_));
ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
- ASSERT_FALSE(reader.ExtractCurrentEntry(&mock_writer));
+ ASSERT_FALSE(reader.ExtractCurrentEntry(
+ &mock_writer, std::numeric_limits<uint64_t>::max()));
}
// Test that when WriterDelegate::WriteBytes returns false, no other methods on
@@ -628,7 +670,8 @@ TEST_F(ZipReaderTest, ExtractCurrentEntryWriteBytesFailure) {
ASSERT_TRUE(reader.Open(test_zip_file_));
ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
- ASSERT_FALSE(reader.ExtractCurrentEntry(&mock_writer));
+ ASSERT_FALSE(reader.ExtractCurrentEntry(
+ &mock_writer, std::numeric_limits<uint64_t>::max()));
}
// Test that extraction succeeds when the writer delegate reports all is well.
@@ -645,7 +688,58 @@ TEST_F(ZipReaderTest, ExtractCurrentEntrySuccess) {
ASSERT_TRUE(reader.Open(test_zip_file_));
ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
- ASSERT_TRUE(reader.ExtractCurrentEntry(&mock_writer));
+ ASSERT_TRUE(reader.ExtractCurrentEntry(&mock_writer,
+ std::numeric_limits<uint64_t>::max()));
+}
+
+// Test that when WriterDelegate::PrepareMock returns false, no other methods on
+// the delegate are called and the partial extraction fails.
+TEST_F(ZipReaderTest, ExtractFromBeginningOfCurrentEntryPrepareFailure) {
+ testing::StrictMock<MockWriterDelegate> mock_writer;
+
+ EXPECT_CALL(mock_writer, PrepareOutput()).WillOnce(Return(false));
+
+ base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
+ ZipReader reader;
+
+ ASSERT_TRUE(reader.Open(test_zip_file_));
+ ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
+ ASSERT_FALSE(reader.ExtractCurrentEntry(
+ &mock_writer, std::numeric_limits<uint64_t>::max()));
+}
+
+// Test that when WriterDelegate::WriteBytes returns false, no other methods on
+// the delegate are called and the partial extraction fails.
+TEST_F(ZipReaderTest, ExtractFromBeginningOfCurrentEntryWriteBytesFailure) {
+ testing::StrictMock<MockWriterDelegate> mock_writer;
+
+ EXPECT_CALL(mock_writer, PrepareOutput()).WillOnce(Return(true));
+ EXPECT_CALL(mock_writer, WriteBytes(_, _)).WillOnce(Return(false));
+
+ base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
+ ZipReader reader;
+
+ ASSERT_TRUE(reader.Open(test_zip_file_));
+ ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
+ ASSERT_FALSE(reader.ExtractCurrentEntry(
+ &mock_writer, std::numeric_limits<uint64_t>::max()));
+}
+
+// Test that partial extraction succeeds when the writer delegate reports all is
+// well.
+TEST_F(ZipReaderTest, ExtractFromBeginningOfCurrentEntrySuccess) {
+ testing::StrictMock<MockWriterDelegate> mock_writer;
+
+ EXPECT_CALL(mock_writer, PrepareOutput()).WillOnce(Return(true));
+ EXPECT_CALL(mock_writer, WriteBytes(_, _)).WillRepeatedly(Return(true));
+
+ base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
+ ZipReader reader;
+
+ ASSERT_TRUE(reader.Open(test_zip_file_));
+ ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
+ ASSERT_TRUE(reader.ExtractCurrentEntry(&mock_writer,
+ std::numeric_limits<uint64_t>::max()));
}
class FileWriterDelegateTest : public ::testing::Test {
« no previous file with comments | « third_party/zlib/google/zip_reader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698