Skip to content

Commit

Permalink
[Test] Update tests to verify BIT7Z_DETECT_FROM_EXTENSION
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Feb 26, 2025
1 parent 79133ec commit 1f268af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/src/test_bitarchivereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,13 +1115,18 @@ TEMPLATE_TEST_CASE( "BitInputArchive: Reading a nested archive with wrong extens
SECTION( "Checking archive start by scanning through the input file" ){
#ifdef BIT7Z_AUTO_FORMAT
const BitArchiveReader reader( lib, inputArchive, ArchiveStartOffset::None );
#ifdef BIT7Z_DETECT_FROM_EXTENSION
if ( reader.archivePath().empty() ) {
REQUIRE( reader.detectedFormat() == BitFormat::SevenZip );
REQUIRE_NOTHROW( reader.test() );
} else {
REQUIRE( reader.detectedFormat() == BitFormat::Zip );
REQUIRE_THROWS( reader.test() );
}
#else
REQUIRE( reader.detectedFormat() == BitFormat::SevenZip );
REQUIRE_NOTHROW( reader.test() );
#endif
#else
const BitArchiveReader reader( lib, inputArchive, ArchiveStartOffset::None, BitFormat::Zip );
REQUIRE_THROWS( reader.test() );
Expand Down
4 changes: 4 additions & 0 deletions tests/src/test_formatdetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace bit7z;
using namespace bit7z::test;
using namespace bit7z::test::filesystem;

#ifdef BIT7Z_DETECT_FROM_EXTENSION
// Note: format detection by extension doesn't actually require the file to exist.
TEST_CASE( "formatdetect: Format detection by extension", "[formatdetect]" ) {
const TestDirectory testDir{ fs::path{ test_archives_dir } / "detection" / "valid" };
Expand Down Expand Up @@ -129,6 +130,7 @@ TEST_CASE( "formatdetect: Format detection by extension", "[formatdetect]" ) {
REQUIRE( detect_format_from_extension( "valid." + test.extension ) == test.format );
}
}
#endif

TEST_CASE( "formatdetect: Format detection by signature", "[formatdetect]" ) {
const TestDirectory testDir{ fs::path{ test_archives_dir } / "detection" / "valid" };
Expand Down Expand Up @@ -286,7 +288,9 @@ TEST_CASE( "formatdetect: Format detection of archive with a wrong extension (Is
TEST_CASE( "formatdetect: Format detection of an archive file without an extension", "[formatdetect]" ) {
const TestDirectory testDir{ fs::path{ test_archives_dir } / "detection" };

#ifdef BIT7Z_DETECT_FROM_EXTENSION
REQUIRE( detect_format_from_extension( "noextension" ) == BitFormat::Auto );
#endif

const Bit7zLibrary lib{ test::sevenzip_lib_path() };
const BitArchiveReader reader{ lib, BIT7Z_STRING( "noextension" ) };
Expand Down

0 comments on commit 1f268af

Please sign in to comment.