mirror of
https://github.com/GerbilSoft/zlib-ng.git
synced 2025-06-18 11:35:35 -04:00
Improve dual link test to compile against zlib. Previously we were only linking against it.
This commit is contained in:
parent
428aa9ab42
commit
dda87d2b18
6
.github/workflows/cmake.yml
vendored
6
.github/workflows/cmake.yml
vendored
@ -83,12 +83,6 @@ jobs:
|
||||
cmake-args: -DWITH_OPTIM=OFF -DHAVE_BUILTIN_CTZLL=OFF -DHAVE_BUILTIN_CTZ=OFF
|
||||
codecov: ubuntu_gcc_no_ctz
|
||||
|
||||
- name: Ubuntu GCC Link Zlib
|
||||
os: ubuntu-latest
|
||||
compiler: gcc
|
||||
cxx-compiler: g++
|
||||
cmake-args: -DZLIB_DUAL_LINK=ON
|
||||
|
||||
- name: Ubuntu GCC No AVX2 UBSAN
|
||||
os: ubuntu-latest
|
||||
compiler: gcc
|
||||
|
@ -1191,12 +1191,6 @@ if(ZLIB_ENABLE_TESTS)
|
||||
target_compile_definitions(${target} PUBLIC -DWITH_GZFILEOP)
|
||||
target_sources(${target} PRIVATE ${ZLIB_GZFILE_PRIVATE_HDRS} ${ZLIB_GZFILE_SRCS})
|
||||
endif()
|
||||
if(ZLIB_DUAL_LINK)
|
||||
find_package(ZLIB)
|
||||
if(ZLIB_FOUND)
|
||||
target_link_libraries(${target} ${ZLIB_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(add_simple_test_executable target)
|
||||
|
@ -95,6 +95,21 @@ if(WITH_SANITIZER STREQUAL "Memory")
|
||||
-fsanitize-memory-track-origins)
|
||||
endif()
|
||||
|
||||
if(ZLIB_DUAL_LINK AND NOT ZLIB_COMPAT)
|
||||
find_package(ZLIB)
|
||||
if(ZLIB_FOUND)
|
||||
message(STATUS "Added dual linking tests against zlib")
|
||||
message(STATUS " Zlib include dir: ${ZLIB_INCLUDE_DIR}")
|
||||
message(STATUS " Zlib libraries: ${ZLIB_LIBRARIES}")
|
||||
|
||||
target_sources(gtest_zlib PRIVATE test_compress_dual.cc)
|
||||
target_include_directories(gtest_zlib PRIVATE ${ZLIB_INCLUDE_DIR})
|
||||
target_link_libraries(gtest_zlib ${ZLIB_LIBRARIES})
|
||||
else()
|
||||
message(WARNING "Zlib not found, skipping dual linking tests")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_link_libraries(gtest_zlib zlibstatic GTest::GTest)
|
||||
|
||||
find_package(Threads)
|
||||
|
28
test/test_compress_dual.cc
Normal file
28
test/test_compress_dual.cc
Normal file
@ -0,0 +1,28 @@
|
||||
/* test_compress_dual.cc - Test linking against both zlib and zlib-ng */
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test_shared.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(compress, basic_zlib) {
|
||||
Byte compr[128], uncompr[128];
|
||||
uLong compr_len = sizeof(compr), uncompr_len = sizeof(uncompr);
|
||||
int err;
|
||||
|
||||
err = compress(compr, &compr_len, (const unsigned char *)hello, hello_len);
|
||||
EXPECT_EQ(err, Z_OK);
|
||||
|
||||
strcpy((char*)uncompr, "garbage");
|
||||
|
||||
err = uncompress(uncompr, &uncompr_len, compr, compr_len);
|
||||
EXPECT_EQ(err, Z_OK);
|
||||
|
||||
EXPECT_STREQ((char *)uncompr, (char *)hello);
|
||||
}
|
Loading…
Reference in New Issue
Block a user