chromium/third_party/zlib/google/zip_unittest.cc

// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/zlib/google/zip.h"

#include <stddef.h>
#include <stdint.h>

#include <iomanip>
#include <limits>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "third_party/zlib/google/zip_internal.h"
#include "third_party/zlib/google/zip_reader.h"

// Convenience macro to create a file path from a string literal.
#define FP(path)

namespace {

UnorderedElementsAre;
UnorderedElementsAreArray;

std::vector<std::string> GetRelativePaths(const base::FilePath& dir,
                                          base::FileEnumerator::FileType type) {}

bool CreateFile(const std::string& content,
                base::FilePath* file_path,
                base::File* file) {}

// A WriterDelegate that logs progress once per second.
class ProgressWriterDelegate : public zip::WriterDelegate {};

// A virtual file system containing:
// /test
// /test/foo.txt
// /test/bar/bar1.txt
// /test/bar/bar2.txt
// Used to test providing a custom zip::FileAccessor when unzipping.
class VirtualFileSystem : public zip::FileAccessor {};

// static
constexpr char VirtualFileSystem::kFooContent[];
constexpr char VirtualFileSystem::kBar1Content[];
constexpr char VirtualFileSystem::kBar2Content[];

// Make the test a PlatformTest to setup autorelease pools properly on Mac.
class ZipTest : public PlatformTest {};

TEST_F(ZipTest, UnzipNoSuchFile) {}

TEST_F(ZipTest, Unzip) {}

TEST_F(ZipTest, UnzipUncompressed) {}

TEST_F(ZipTest, UnzipEvil) {}

TEST_F(ZipTest, UnzipEvil2) {}

TEST_F(ZipTest, UnzipWithFilter) {}

TEST_F(ZipTest, UnzipEncryptedWithRightPassword) {}

TEST_F(ZipTest, UnzipEncryptedWithWrongPassword) {}

TEST_F(ZipTest, UnzipEncryptedWithNoPassword) {}

TEST_F(ZipTest, UnzipEncryptedContinueOnError) {}

TEST_F(ZipTest, UnzipWrongCrc) {}

TEST_F(ZipTest, UnzipRepeatedDirName) {}

TEST_F(ZipTest, UnzipRepeatedFileName) {}

TEST_F(ZipTest, UnzipCannotCreateEmptyDir) {}

TEST_F(ZipTest, UnzipCannotCreateParentDir) {}

// TODO(crbug.com/1311140) Detect and rename reserved file names on Windows.
TEST_F(ZipTest, UnzipWindowsSpecialNames) {}

TEST_F(ZipTest, UnzipDifferentCases) {}

TEST_F(ZipTest, UnzipDifferentCasesContinueOnError) {}

TEST_F(ZipTest, UnzipMixedPaths) {}

TEST_F(ZipTest, UnzipWithDelegates) {}

TEST_F(ZipTest, UnzipOnlyDirectories) {}

// Tests that a ZIP archive containing SJIS-encoded file names can be correctly
// extracted if the encoding is specified.
TEST_F(ZipTest, UnzipSjis) {}

// Tests that a ZIP archive containing SJIS-encoded file names can be extracted
// even if the encoding is not specified. In this case, file names are
// interpreted as UTF-8, which leads to garbled names where invalid UTF-8
// sequences are replaced with the character �. Nevertheless, the files are
// safely extracted and readable.
TEST_F(ZipTest, UnzipSjisAsUtf8) {}

TEST_F(ZipTest, Zip) {}

TEST_F(ZipTest, ZipIgnoreHidden) {}

TEST_F(ZipTest, ZipNonASCIIDir) {}

TEST_F(ZipTest, ZipTimeStamp) {}

#if defined(OS_POSIX) || defined(OS_FUCHSIA)
TEST_F(ZipTest, ZipFiles) {}
#endif  // defined(OS_POSIX) || defined(OS_FUCHSIA)

TEST_F(ZipTest, UnzipFilesWithIncorrectSize) {}

TEST_F(ZipTest, ZipWithFileAccessor) {}

// Tests progress reporting while zipping files.
TEST_F(ZipTest, ZipProgress) {}

// Tests throttling of progress reporting while zipping files.
TEST_F(ZipTest, ZipProgressPeriod) {}

// Tests cancellation while zipping files.
TEST_F(ZipTest, ZipCancel) {}

// Tests zip::internal::GetCompressionMethod()
TEST_F(ZipTest, GetCompressionMethod) {}

// Tests that files put inside a ZIP are effectively compressed.
TEST_F(ZipTest, Compressed) {}

// Tests that a ZIP put inside a ZIP is simply stored instead of being
// compressed.
TEST_F(ZipTest, NestedZip) {}

// Tests that there is no 2GB or 4GB limits. Tests that big files can be zipped
// (crbug.com/1207737) and that big ZIP files can be created
// (crbug.com/1221447). Tests that the big ZIP can be opened, that its entries
// are correctly enumerated (crbug.com/1298347), and that the big file can be
// extracted.
//
// Because this test is dealing with big files, it tends to take a lot of disk
// space and time (crbug.com/1299736). Therefore, it only gets run on a few bots
// (ChromeOS and Windows).
//
// This test is too slow with TSAN.
// OS Fuchsia does not seem to support large files.
// Some 32-bit Android waterfall and CQ try bots are running out of space when
// performing this test (android-asan, android-11-x86-rel,
// android-marshmallow-x86-rel-non-cq).
// Some Mac, Linux and Debug (dbg) bots tend to time out when performing this
// test (crbug.com/1299736, crbug.com/1300448, crbug.com/1369958).
#if defined(THREAD_SANITIZER) || BUILDFLAG(IS_FUCHSIA) ||                \
    BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
    BUILDFLAG(IS_CHROMEOS) || !defined(NDEBUG)
TEST_F(ZipTest, DISABLED_BigFile) {}

}  // namespace