Skip to content

Commit

Permalink
Add tests for reading zip archives using a different codepage encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Nov 2, 2024
1 parent 26bf10f commit f349dc4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
33 changes: 33 additions & 0 deletions tests/src/test_bitinputarchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <bit7z/bitformat.hpp>
#include <bit7z/bittypes.hpp>
#include <internal/fs.hpp>
#include <internal/stringutil.hpp>

#include <algorithm>
#include <cstddef>
Expand Down Expand Up @@ -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 ) );
}

0 comments on commit f349dc4

Please sign in to comment.