diff options
author | Haibo Huang <hhb@google.com> | 2020-04-13 19:21:23 -0700 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2020-04-13 19:21:23 -0700 |
commit | b2162831bbfe6acb742910724f95fc99c991b7c7 (patch) | |
tree | bdecddd157b0b58fbe1d391718c33070eb69b634 /contrib | |
parent | 824e8864d93488098eeaf328961c531a5734e4ab (diff) | |
parent | 61bddccfbf47b9e6bbce6e39d3f2458e27c58c6a (diff) | |
download | zlib-b2162831bbfe6acb742910724f95fc99c991b7c7.tar.gz |
Upgrade zlib to 61bddccfbf47b9e6bbce6e39d3f2458e27c58c6a
Test: None
Change-Id: I30abdd531fd89c408316b432d6ea29f5d5011908
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/minizip/iowin32.c | 8 | ||||
-rw-r--r-- | contrib/tests/utils_unittest.cc | 58 |
2 files changed, 61 insertions, 5 deletions
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c index 246ceb9..c6bc314 100644 --- a/contrib/minizip/iowin32.c +++ b/contrib/minizip/iowin32.c @@ -31,14 +31,12 @@ #define _WIN32_WINNT 0x601 #endif -#if _WIN32_WINNT >= _WIN32_WINNT_WIN8 -// see Include/shared/winapifamily.h in the Windows Kit -#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API))) -#if WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP) +#if !defined(IOWIN32_USING_WINRT_API) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +// Windows Store or Universal Windows Platform #define IOWIN32_USING_WINRT_API 1 #endif #endif -#endif voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode)); uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); diff --git a/contrib/tests/utils_unittest.cc b/contrib/tests/utils_unittest.cc new file mode 100644 index 0000000..6e1f5c9 --- /dev/null +++ b/contrib/tests/utils_unittest.cc @@ -0,0 +1,58 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the Chromium source repository LICENSE file. + +#include <cstddef> +#include <vector> + +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/zlib/google/compression_utils_portable.h" + +#include "zlib.h" + +void TestPayloads(size_t input_size, zlib_internal::WrapperType type) { + std::vector<unsigned char> input; + input.reserve(input_size); + for (size_t i = 1; i <= input_size; ++i) + input.push_back(i & 0xff); + + // If it is big enough for GZIP, will work for other wrappers. + std::vector<unsigned char> compressed( + zlib_internal::GzipExpectedCompressedSize(input.size())); + std::vector<unsigned char> decompressed(input.size()); + + // Libcores's java/util/zip/Deflater default settings: ZLIB, + // DEFAULT_COMPRESSION and DEFAULT_STRATEGY. + unsigned long compressed_size = static_cast<unsigned long>(compressed.size()); + int result = zlib_internal::CompressHelper( + type, compressed.data(), &compressed_size, input.data(), input.size(), + Z_DEFAULT_COMPRESSION, nullptr, nullptr); + ASSERT_EQ(result, Z_OK); + + unsigned long decompressed_size = + static_cast<unsigned long>(decompressed.size()); + result = zlib_internal::UncompressHelper(type, decompressed.data(), + &decompressed_size, + compressed.data(), compressed_size); + ASSERT_EQ(result, Z_OK); + EXPECT_EQ(input, decompressed); +} + +TEST(ZlibTest, ZlibWrapper) { + // Minimal ZLIB wrapped short stream size is about 8 bytes. + for (size_t i = 1; i < 1024; ++i) + TestPayloads(i, zlib_internal::WrapperType::ZLIB); +} + +TEST(ZlibTest, GzipWrapper) { + // GZIP should be 12 bytes bigger than ZLIB wrapper. + for (size_t i = 1; i < 1024; ++i) + TestPayloads(i, zlib_internal::WrapperType::GZIP); +} + +TEST(ZlibTest, RawWrapper) { + // RAW has no wrapper (V8 Blobs is a known user), size + // should be payload_size + 2 for short payloads. + for (size_t i = 1; i < 1024; ++i) + TestPayloads(i, zlib_internal::WrapperType::ZRAW); +} |