Skip to content

Commit

Permalink
Rename ArchivedItem struct to ExpectedItem
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Nov 30, 2023
1 parent 1144fb6 commit e0fcbac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions tests/src/test_bitarchivereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static_assert( std::is_move_assignable< BitArchiveItemInfo >::value,

void require_archive_item( const BitInFormat& format,
const BitArchiveItem& item,
const ArchivedItem& expectedItem,
const ExpectedItem& expectedItem,
const SourceLocation& location ) {
INFO( "Failed while checking archive item " << Catch::StringMaker< tstring >::convert( item.name() ) );
INFO( " from " << location.file_name() << ":" << location.line() );
Expand Down Expand Up @@ -402,7 +402,7 @@ TEST_CASE( "BitArchiveReader: Reading metadata of multi-volume archives", "[bita
REQUIRE( info.volumesCount() == 3 );
REQUIRE( info.itemsCount() == 1 );

const ArchivedItem expectedItem{ clouds, clouds.name };
const ExpectedItem expectedItem{ clouds, clouds.name };
REQUIRE_ARCHIVE_ITEM( BitFormat::Rar5, info.items()[ 0 ], expectedItem );
}

Expand All @@ -413,7 +413,7 @@ TEST_CASE( "BitArchiveReader: Reading metadata of multi-volume archives", "[bita
REQUIRE( info.volumesCount() == 3 );
REQUIRE( info.itemsCount() == 1 );

const ArchivedItem expectedItem{ clouds, clouds.name };
const ExpectedItem expectedItem{ clouds, clouds.name };
REQUIRE_ARCHIVE_ITEM( BitFormat::Rar, info.items()[ 0 ], expectedItem );
}
}
Expand Down
44 changes: 22 additions & 22 deletions tests/src/test_bitinputarchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ using namespace bit7z;
using namespace bit7z::test;
using namespace bit7z::test::filesystem;

using ExpectedItems = std::vector< ArchivedItem >;
using ExpectedItems = std::vector< ExpectedItem >;

inline auto extracted_item( const BitArchiveReader& archive,
const ArchivedItem& expectedItem ) -> BitArchiveReader::ConstIterator {
inline auto archive_item( const BitArchiveReader& archive,
const ExpectedItem& expectedItem ) -> BitArchiveReader::ConstIterator {
if ( archive.retainDirectories() ) {
return archive.find( path_to_tstring( expectedItem.inArchivePath ) );
}
Expand All @@ -51,7 +51,7 @@ inline auto extracted_item( const BitArchiveReader& archive,
} );
}

void require_filesystem_item( const ArchivedItem& expectedItem, const SourceLocation& location ) {
void require_filesystem_item( const ExpectedItem& expectedItem, const SourceLocation& location ) {
INFO( "From " << location.file_name() << ":" << location.line() );
INFO( "Failed while checking expected item: " << expectedItem.inArchivePath.u8string() );

Expand Down Expand Up @@ -95,9 +95,9 @@ void require_extracts_items_to_filesystem( const BitArchiveReader& info, const E

const auto testPath = path_to_tstring( testDir.path() );
for ( const auto& expectedItem : expectedItems ) {
const auto extractedItem = extracted_item( info, expectedItem );
REQUIRE( extractedItem != info.cend() );
REQUIRE_NOTHROW( info.extractTo( testPath, { extractedItem->index() } ) );
const auto archiveItem = archive_item( info, expectedItem );
REQUIRE( archiveItem != info.cend() );
REQUIRE_NOTHROW( info.extractTo( testPath, { archiveItem->index() } ) );
REQUIRE_FILESYSTEM_ITEM( expectedItem );
}
REQUIRE( fs::is_empty( testDir.path() ) );
Expand Down Expand Up @@ -129,10 +129,10 @@ void require_extracts_items_to_filesystem( const BitArchiveReader& info, const E
}

for ( const auto& expectedItem : expectedItems ) {
const auto extractedItem = extracted_item( info, expectedItem );
REQUIRE( extractedItem != info.cend() );
const auto archiveItem = archive_item( info, expectedItem );
REQUIRE( archiveItem != info.cend() );
// The vector of indices contains a valid index, and an invalid one, so the extraction should fail.
REQUIRE_THROWS( info.extractTo( testPath, { extractedItem->index(), info.itemsCount() } ) );
REQUIRE_THROWS( info.extractTo( testPath, { archiveItem->index(), info.itemsCount() } ) );
REQUIRE( fs::is_empty( testDir.path() ) );
}

Expand Down Expand Up @@ -163,13 +163,13 @@ void require_extracts_to_buffers( const BitArchiveReader& info, const ExpectedIt
buffer_t outputBuffer;
for ( const auto& expectedItem : expectedItems ) {
INFO( "Failed while checking expected item '" << expectedItem.inArchivePath.u8string() << "'" );
const auto extractedItem = extracted_item( info, expectedItem );
REQUIRE( extractedItem != info.cend() );
if ( extractedItem->isDir() ) {
REQUIRE_THROWS( info.extractTo( outputBuffer, extractedItem->index() ) );
const auto archiveItem = archive_item( info, expectedItem );
REQUIRE( archiveItem != info.cend() );
if ( archiveItem->isDir() ) {
REQUIRE_THROWS( info.extractTo( outputBuffer, archiveItem->index() ) );
REQUIRE( outputBuffer.empty() );
} else {
REQUIRE_NOTHROW( info.extractTo( outputBuffer, extractedItem->index() ) );
REQUIRE_NOTHROW( info.extractTo( outputBuffer, archiveItem->index() ) );
REQUIRE( crc32( outputBuffer ) == expectedItem.fileInfo.crc32 );
outputBuffer.clear();
}
Expand All @@ -193,10 +193,10 @@ void require_extracts_to_fixed_buffers( const BitArchiveReader& info, const Expe
buffer_t outputBuffer;
for ( const auto& expectedItem : expectedItems ) {
INFO( "Failed while checking expected item '" << expectedItem.inArchivePath.u8string() << "'" );
const auto extractedItem = extracted_item( info, expectedItem );
REQUIRE( extractedItem != info.cend() );
const auto archiveItem = archive_item( info, expectedItem );
REQUIRE( archiveItem != info.cend() );

const auto itemIndex = extractedItem->index();
const auto itemIndex = archiveItem->index();
REQUIRE_THROWS( info.extractTo( nullptr, 0, itemIndex ) );
REQUIRE_THROWS( info.extractTo( nullptr, invalidBufferSize, itemIndex ) );
REQUIRE_THROWS( info.extractTo( nullptr, expectedItem.fileInfo.size, itemIndex ) );
Expand Down Expand Up @@ -257,10 +257,10 @@ void require_extracts_to_streams( const BitArchiveReader& info, const ExpectedIt
for ( const auto& expectedItem : expectedItems ) {
INFO( "Failed while checking expected item '" << expectedItem.inArchivePath.u8string() << "'" );

const auto extractedItem = extracted_item( info, expectedItem );
REQUIRE( extractedItem != info.cend() );
const auto archiveItem = archive_item( info, expectedItem );
REQUIRE( archiveItem != info.cend() );

const auto itemIndex = extractedItem->index();
const auto itemIndex = archiveItem->index();
std::ostringstream outputStream;
if ( expectedItem.fileInfo.type == fs::file_type::directory ) {
REQUIRE_THROWS( info.extractTo( outputStream, itemIndex ) );
Expand Down Expand Up @@ -824,7 +824,7 @@ TEST_CASE( "BitInputArchive: Testing and extracting an archive with a Unicode fi
const fs::path arcFileName{ BIT7Z_NATIVE_STRING( "クラウド.jpg.bz2" ) };
const BitArchiveReader info( test::sevenzip_lib(), path_to_tstring( arcFileName ), BitFormat::BZip2 );
REQUIRE_ARCHIVE_TESTS( info );
const ExpectedItems expectedItems{ ArchivedItem{ clouds, BIT7Z_NATIVE_STRING( "クラウド.jpg" ), false } };
const ExpectedItems expectedItems{ ExpectedItem{ clouds, BIT7Z_NATIVE_STRING( "クラウド.jpg" ), false } };
REQUIRE_ARCHIVE_EXTRACTS( info, expectedItems );
}

Expand Down
4 changes: 2 additions & 2 deletions tests/src/utils/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extern const FilesystemItemInfo readOnly;
extern const FilesystemItemInfo regular;
extern const FilesystemItemInfo symlink;

struct ArchivedItem {
struct ExpectedItem {
const FilesystemItemInfo& fileInfo;
fs::path inArchivePath;
bool isEncrypted;
Expand All @@ -120,7 +120,7 @@ struct ArchivedItem {
struct ArchiveContent {
std::size_t fileCount;
std::size_t size;
std::vector< ArchivedItem > items;
std::vector< ExpectedItem > items;
};

auto single_file_content() -> const ArchiveContent&;
Expand Down

0 comments on commit e0fcbac

Please sign in to comment.