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

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

Issue 292443006: New ZipReader::ExtractCurrentEntryToString API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src
Patch Set: rebase Created 6 years, 6 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 df20e6fe3367a93cb810dd8c5008b821bf2ad444..a137d9dd1bc0b85fb80740f12799eb44f28f9d37 100644
--- a/third_party/zlib/google/zip_reader_unittest.cc
+++ b/third_party/zlib/google/zip_reader_unittest.cc
@@ -15,6 +15,7 @@
#include "base/md5.h"
#include "base/path_service.h"
#include "base/run_loop.h"
+#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -534,4 +535,42 @@ TEST_F(ZipReaderTest, ExtractToFileAsync_Directory) {
ASSERT_TRUE(base::DirectoryExists(target_file));
}
+TEST_F(ZipReaderTest, ExtractCurrentEntryToString) {
+ // 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));
+
+ for (size_t i = 0; i < 8; i++) {
+ SCOPED_TRACE(base::StringPrintf("Processing %d.txt", static_cast<int>(i)));
+
+ base::FilePath file_name = base::FilePath::FromUTF8Unsafe(
+ base::StringPrintf("%d.txt", static_cast<int>(i)));
+ ASSERT_TRUE(reader.LocateAndOpenEntry(file_name));
+
+ if (i > 1) {
+ // Off by one byte read limit: must fail.
+ EXPECT_FALSE(reader.ExtractCurrentEntryToString(i - 1, &contents));
+ }
+
+ if (i > 0) {
+ // Exact byte read limit: must pass.
+ EXPECT_TRUE(reader.ExtractCurrentEntryToString(i, &contents));
+ EXPECT_EQ(i, contents.size());
+ EXPECT_EQ(0, memcmp(contents.c_str(), "0123456", i));
+ }
+
+ // More than necessary byte read limit: must pass.
+ EXPECT_TRUE(reader.ExtractCurrentEntryToString(16, &contents));
+ EXPECT_EQ(i, contents.size());
+ EXPECT_EQ(0, memcmp(contents.c_str(), "0123456", i));
+ }
+ reader.Close();
+}
+
} // namespace zip
« 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