Skip to content

Commit

Permalink
Merge pull request #3324 from eseiler/fix/zlib-ng
Browse files Browse the repository at this point in the history
[FIX,TEST] Do not check zlib output for alternative implementations
  • Loading branch information
eseiler authored Jan 21, 2025
2 parents 787d724 + 04913ed commit c8e7fdb
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/include/seqan3/test/zlib_skip.hpp
Original file line number Diff line number Diff line change
@@ -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 <enrico.seiler AT fu-berlin.de>
*/

#pragma once

#include <gtest/gtest.h>

#include <seqan3/core/platform.hpp>

#if defined(SEQAN3_HAS_ZLIB)
# include <zlib.h>
#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
5 changes: 5 additions & 0 deletions test/unit/io/sam_file/sam_file_output_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <seqan3/io/sam_file/input.hpp>
#include <seqan3/io/sam_file/output.hpp>
#include <seqan3/test/tmp_directory.hpp>
#include <seqan3/test/zlib_skip.hpp>

using seqan3::operator""_dna4;
using seqan3::operator""_dna5;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/unit/io/sequence_file/sequence_file_output_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/io/sequence_file/output.hpp>
#include <seqan3/test/tmp_directory.hpp>
#include <seqan3/test/zlib_skip.hpp>
#include <seqan3/utility/views/zip.hpp>

using seqan3::operator""_dna5;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
7 changes: 7 additions & 0 deletions test/unit/io/stream/ostream_test_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <seqan3/io/stream/concept.hpp>
#include <seqan3/test/tmp_directory.hpp>
#include <seqan3/test/zlib_skip.hpp>

template <typename T>
class ostream : public ::testing::Test
Expand Down Expand Up @@ -41,7 +42,10 @@ TYPED_TEST_P(ostream, output)
std::string buffer{std::istreambuf_iterator<char>{fi}, std::istreambuf_iterator<char>{}};

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);
}
Expand All @@ -63,7 +67,10 @@ TYPED_TEST_P(ostream, output_type_erased)
std::string buffer{std::istreambuf_iterator<char>{fi}, std::istreambuf_iterator<char>{}};

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);
}
Expand Down
5 changes: 5 additions & 0 deletions test/unit/io/structure_file/structure_file_output_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <seqan3/io/structure_file/input.hpp>
#include <seqan3/io/structure_file/output.hpp>
#include <seqan3/test/tmp_directory.hpp>
#include <seqan3/test/zlib_skip.hpp>

using seqan3::operator""_rna5;
using seqan3::operator""_wuss51;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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
Expand Down

0 comments on commit c8e7fdb

Please sign in to comment.