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

Side by Side 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: review comments 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 unified diff | Download patch
« no previous file with comments | « third_party/zlib/google/zip_reader.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "third_party/zlib/google/zip_reader.h" 5 #include "third_party/zlib/google/zip_reader.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file.h" 12 #include "base/files/file.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/md5.h" 15 #include "base/md5.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "base/time/time.h" 20 #include "base/time/time.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 #include "testing/platform_test.h" 22 #include "testing/platform_test.h"
22 #include "third_party/zlib/google/zip_internal.h" 23 #include "third_party/zlib/google/zip_internal.h"
23 24
24 namespace { 25 namespace {
25 26
26 const static std::string kQuuxExpectedMD5 = "d1ae4ac8a17a0e09317113ab284b57a6"; 27 const static std::string kQuuxExpectedMD5 = "d1ae4ac8a17a0e09317113ab284b57a6";
27 28
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 528
528 base::RunLoop().RunUntilIdle(); 529 base::RunLoop().RunUntilIdle();
529 530
530 EXPECT_EQ(1, listener.success_calls()); 531 EXPECT_EQ(1, listener.success_calls());
531 EXPECT_EQ(0, listener.failure_calls()); 532 EXPECT_EQ(0, listener.failure_calls());
532 EXPECT_GE(0, listener.progress_calls()); 533 EXPECT_GE(0, listener.progress_calls());
533 534
534 ASSERT_TRUE(base::DirectoryExists(target_file)); 535 ASSERT_TRUE(base::DirectoryExists(target_file));
535 } 536 }
536 537
538 TEST_F(ZipReaderTest, ExtractCurrentEntryToString) {
539 // test_mismatch_size.zip contains files with names from 0.txt to 7.txt with
540 // sizes from 0 to 7 bytes respectively, being the contents of each file a
541 // substring of "0123456" starting at '0'.
542 base::FilePath test_zip_file =
543 test_data_dir_.AppendASCII("test_mismatch_size.zip");
544
545 ZipReader reader;
546 std::string contents;
547 ASSERT_TRUE(reader.Open(test_zip_file));
548
549 for (size_t i = 0; i < 8; i++) {
550 SCOPED_TRACE(base::StringPrintf("Processing %d.txt", static_cast<int>(i)));
551
552 base::FilePath file_name = base::FilePath(
553 base::StringPrintf(FILE_PATH_LITERAL("%d.txt"), static_cast<int>(i)));
satorux1 2014/06/03 08:17:40 This looks tricky. FILE_PATH_LITERAL() returns a w
João Eiras 2014/06/03 14:39:02 There is an overload for string and wstring. Works
satorux1 2014/06/03 21:30:15 i think relying on the overload is not obvious hen
João Eiras 2014/06/19 14:00:43 OK, changed.
554 ASSERT_TRUE(reader.LocateAndOpenEntry(file_name));
555
556 if (i > 1) {
557 // Off by one byte read limit: must fail.
558 EXPECT_FALSE(reader.ExtractCurrentEntryToString(i - 1, &contents));
559 }
560
561 if (i > 0) {
562 // Exact byte read limit: must pass.
563 EXPECT_TRUE(reader.ExtractCurrentEntryToString(i, &contents));
564 EXPECT_EQ(i, contents.size());
565 EXPECT_EQ(0, memcmp(contents.c_str(), "0123456", i));
566 }
567
568 // More than necessary byte read limit: must pass.
569 EXPECT_TRUE(reader.ExtractCurrentEntryToString(16, &contents));
570 EXPECT_EQ(i, contents.size());
571 EXPECT_EQ(0, memcmp(contents.c_str(), "0123456", i));
572 }
573 reader.Close();
574 }
575
537 } // namespace zip 576 } // namespace zip
OLDNEW
« 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