]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Improve dual link test to compile against zlib. Previously we were only linking again...
authorNathan Moinvaziri <nathan@nathanm.com>
Sun, 19 Jun 2022 16:02:27 +0000 (09:02 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 24 Jun 2022 13:15:36 +0000 (15:15 +0200)
.github/workflows/cmake.yml
CMakeLists.txt
test/CMakeLists.txt
test/test_compress_dual.cc [new file with mode: 0644]

index 9158ce7b7f89bf317f252e628fbe5dd589ed1ae4..9667d5f79b50ec73711636056cb54d0009b2268b 100644 (file)
@@ -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
index 07c7753776a1c5c8f2b43fd12235408b29c6d5b4..fae09c7c70a6ab9c527f0ad0f05bf0f02bd5300f 100644 (file)
@@ -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)
index 3a47e8b2758ec1506d866217db8d2c36109bb41f..f30f9ac3a0511209c34911efeb5b602825f1a894 100644 (file)
@@ -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)
diff --git a/test/test_compress_dual.cc b/test/test_compress_dual.cc
new file mode 100644 (file)
index 0000000..a92ab4b
--- /dev/null
@@ -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);
+}