From f349dc4e2c7da40a9326212cdb1505858af4c5aa Mon Sep 17 00:00:00 2001 From: Oz Date: Sat, 2 Nov 2024 12:36:14 +0100 Subject: [PATCH] Add tests for reading zip archives using a different codepage encoding --- tests/CMakeLists.txt | 2 +- tests/src/test_bitinputarchive.cpp | 33 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e65e1c62..9d3caecc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -54,7 +54,7 @@ target_include_directories( ${TESTS_BASE_TARGET} INTERFACE if( BIT7Z_TESTS_FILESYSTEM ) CPMAddPackage( NAME bit7z_test_data GITHUB_REPOSITORY "rikyoz/bit7z-test-data" - VERSION 1.11 + VERSION 1.12 DOWNLOAD_ONLY YES GIT_PROGRESS ON ) if( bit7z_test_data_ADDED ) diff --git a/tests/src/test_bitinputarchive.cpp b/tests/src/test_bitinputarchive.cpp index 5de6c824..f37dc91a 100644 --- a/tests/src/test_bitinputarchive.cpp +++ b/tests/src/test_bitinputarchive.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -1537,4 +1538,36 @@ TEMPLATE_TEST_CASE( "BitInputArchive: Reading a nested zip archive", REQUIRE_NOTHROW( reader.test() ); REQUIRE( reader.contains( italy.name ) ); } +} + +TEMPLATE_TEST_CASE( "BitInputArchive: Reading a zip archive using a different encoding", + "[bitinputarchive]", tstring, buffer_t, stream_t ) { + const TestDirectory testDir{ fs::path{ test_archives_dir } / "metadata" / "unicode" }; + + const fs::path arcFileName = "codepage.zip"; + + TestType inputArchive{}; + getInputArchive( arcFileName, inputArchive ); + const Bit7zLibrary lib{ test::sevenzip_lib_path() }; + const BitArchiveReader reader{ lib, inputArchive, BitFormat::Zip }; + REQUIRE( reader.itemsCount() == 1 ); + + constexpr auto expectedItemName = BIT7Z_STRING( "ユニコード.pdf" ); + + // The archive uses the Shift-JS encoding (Codepage 932) for the file names. + // If we do not set the codepage to be used, 7-Zip will report a wrongly-encoded string for the name. + REQUIRE_FALSE( reader.itemAt( 0 ).name() == expectedItemName ); + + // Setting the correct codepage will make 7-Zip correctly encode the string. + reader.useFormatProperty( L"cp", 932u ); + REQUIRE( reader.itemAt( 0 ).name() == expectedItemName ); + + TempTestDirectory testOutDir{ "test_bitinputarchive" }; + INFO( "Output directory: " << testOutDir ) + + REQUIRE_NOTHROW( reader.extractTo( testOutDir ) ); + + const auto extractedFilePath = tstring_to_path( expectedItemName ); + REQUIRE( fs::exists( extractedFilePath ) ); + REQUIRE( fs::remove( extractedFilePath ) ); } \ No newline at end of file