From 04913ed3d211dc454c85a54f096e038cdc33c9e6 Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Tue, 21 Jan 2025 16:48:10 +0100 Subject: [PATCH] [FIX,TEST] Do not check zlib output for alternative implementations --- test/include/seqan3/test/zlib_skip.hpp | 41 +++++++++++++++++++ .../unit/io/sam_file/sam_file_output_test.cpp | 5 +++ .../sequence_file_output_test.cpp | 5 +++ test/unit/io/stream/ostream_test_template.hpp | 7 ++++ .../structure_file_output_test.cpp | 5 +++ 5 files changed, 63 insertions(+) create mode 100644 test/include/seqan3/test/zlib_skip.hpp diff --git a/test/include/seqan3/test/zlib_skip.hpp b/test/include/seqan3/test/zlib_skip.hpp new file mode 100644 index 0000000000..a5daf103d0 --- /dev/null +++ b/test/include/seqan3/test/zlib_skip.hpp @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin +// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik +// SPDX-License-Identifier: BSD-3-Clause + +/*!\file + * \brief Provides macros for skipping tests that rely on the binary compressed output of zlib. + * \author Enrico Seiler + */ + +#pragma once + +#include + +#include + +#if defined(SEQAN3_HAS_ZLIB) +# include +#endif + +// Some of our tests check the binary compressed output of zlib. This is not guaranteed to be the same for all zlib +// implementations. +// This macro should be set to 1 if the zlib implementation is not the standard zlib, for example, zlib-ng. +// zlib-ng is automatically detected if `zlib.h` resolves to zlib-ng's header. +#ifndef SEQAN3_TEST_SKIP_ZLIB_DEFLATE +# ifdef ZLIBNG_VERSION +# define SEQAN3_TEST_SKIP_ZLIB_DEFLATE 1 +# else +# define SEQAN3_TEST_SKIP_ZLIB_DEFLATE 0 +# endif +#endif + +// Defines a GTEST_SKIP macro if the zlib implementation is not the standard zlib. +// Otherwise, it does nothing. +#ifndef SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE +# if SEQAN3_TEST_SKIP_ZLIB_DEFLATE +# define SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE \ + GTEST_SKIP() << "Not testing binary compressed output for alternative zlib implementations." +# else +# define SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE +# endif +#endif diff --git a/test/unit/io/sam_file/sam_file_output_test.cpp b/test/unit/io/sam_file/sam_file_output_test.cpp index e8f2d96986..ef0e8d306e 100644 --- a/test/unit/io/sam_file/sam_file_output_test.cpp +++ b/test/unit/io/sam_file/sam_file_output_test.cpp @@ -12,6 +12,7 @@ #include #include #include +#include using seqan3::operator""_dna4; using seqan3::operator""_dna5; @@ -702,6 +703,7 @@ TEST(compression, by_filename_gz) std::string buffer = compression_by_filename_impl(filename); buffer[9] = '\x00'; // zero out OS byte. + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_gz); } @@ -715,6 +717,7 @@ TEST(compression, by_stream_gz) } std::string buffer = out.str(); buffer[9] = '\x00'; // zero out OS byte. + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_gz); } @@ -725,6 +728,7 @@ TEST(compression, by_filename_bgzf) std::string buffer = compression_by_filename_impl(filename); buffer[9] = '\x00'; // zero out OS byte. + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_bgzf); } @@ -738,6 +742,7 @@ TEST(compression, by_stream_bgzf) } std::string buffer = out.str(); buffer[9] = '\x00'; // zero out OS byte. + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_bgzf); } #endif diff --git a/test/unit/io/sequence_file/sequence_file_output_test.cpp b/test/unit/io/sequence_file/sequence_file_output_test.cpp index 01d57fd0c9..9866778159 100644 --- a/test/unit/io/sequence_file/sequence_file_output_test.cpp +++ b/test/unit/io/sequence_file/sequence_file_output_test.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include using seqan3::operator""_dna5; @@ -483,6 +484,7 @@ TEST(compression, by_filename_gz) std::string buffer = compression_by_filename_impl(filename); buffer[9] = '\x00'; // zero out OS byte + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_gz); } @@ -497,6 +499,7 @@ TEST(compression, by_stream_gz) std::string buffer = out.str(); buffer[9] = '\x00'; // zero out OS byte + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_gz); } @@ -507,6 +510,7 @@ TEST(compression, by_filename_bgzf) std::string buffer = compression_by_filename_impl(filename); buffer[9] = '\x00'; // zero out OS byte + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_bgzf); } @@ -521,6 +525,7 @@ TEST(compression, by_stream_bgzf) std::string buffer = out.str(); buffer[9] = '\x00'; // zero out OS byte + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_bgzf); } diff --git a/test/unit/io/stream/ostream_test_template.hpp b/test/unit/io/stream/ostream_test_template.hpp index d7dfbc003f..c639738b8a 100644 --- a/test/unit/io/stream/ostream_test_template.hpp +++ b/test/unit/io/stream/ostream_test_template.hpp @@ -11,6 +11,7 @@ #include #include +#include template class ostream : public ::testing::Test @@ -41,7 +42,10 @@ TYPED_TEST_P(ostream, output) std::string buffer{std::istreambuf_iterator{fi}, std::istreambuf_iterator{}}; if constexpr (TestFixture::zero_out_os_byte) + { buffer[9] = '\x00'; // zero-out the OS byte. + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; + } EXPECT_EQ(buffer, TestFixture::compressed); } @@ -63,7 +67,10 @@ TYPED_TEST_P(ostream, output_type_erased) std::string buffer{std::istreambuf_iterator{fi}, std::istreambuf_iterator{}}; if constexpr (TestFixture::zero_out_os_byte) + { buffer[9] = '\x00'; // zero-out the OS byte. + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; + } EXPECT_EQ(buffer, TestFixture::compressed); } diff --git a/test/unit/io/structure_file/structure_file_output_test.cpp b/test/unit/io/structure_file/structure_file_output_test.cpp index 2178058697..41cac85805 100644 --- a/test/unit/io/structure_file/structure_file_output_test.cpp +++ b/test/unit/io/structure_file/structure_file_output_test.cpp @@ -13,6 +13,7 @@ #include #include #include +#include using seqan3::operator""_rna5; using seqan3::operator""_wuss51; @@ -474,6 +475,7 @@ TEST_F(structure_file_output_compression, by_filename_gz) std::string buffer = compression_by_filename_impl(filename); buffer[9] = '\x00'; // zero out OS byte + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_gz); } @@ -486,6 +488,7 @@ TEST_F(structure_file_output_compression, by_stream_gz) } std::string buffer = out.str(); buffer[9] = '\x00'; // zero out OS byte + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_gz); } @@ -495,6 +498,7 @@ TEST_F(structure_file_output_compression, by_filename_bgzf) auto filename = tmp.path() / "structure_file_output_test.dbn.bgzf"; std::string buffer = compression_by_filename_impl(filename); buffer[9] = '\x00'; // zero out OS byte + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_bgzf); } @@ -507,6 +511,7 @@ TEST_F(structure_file_output_compression, by_stream_bgzf) } std::string buffer = out.str(); buffer[9] = '\x00'; // zero out OS byte + SEQAN3_TEST_GTEST_SKIP_ZLIB_DEFLATE; EXPECT_EQ(buffer, expected_bgzf); } #endif