Skip to content

Commit aececa3

Browse files
authored
test: round-trip decompressZip check in CompressManySmallFilesToZip (#5958)
* test: round-trip decompressZip check in CompressManySmallFilesToZip After compressing the generated 20 .bin + 20 .json source files to many.zip, also decompress the archive into a fresh temp folder and verify every original file is recovered byte-for-byte. The existing size-envelope check only proves the zip is present and not pathological; a byte-level round-trip compare catches the kinds of regressions that have shown up on this path before (wrong compression method byte on an entry, CRC-vs-data mismatch, off-by-one in a local file header, entry truncation) and would otherwise require a real reader -- 7-Zip / Python zipfile -- to detect. The loop walks srcFolder recursively, mirrors each regular file's relative path into the decompressed tree, asserts presence and size parity, then byte-compares content. The final EXPECT confirms all numBinaryFiles + numJsonFiles entries (default 40) were actually seen. No changes to the sphere test -- it checks a single .mrmesh file that MeshLib's own loader already round-trips in other tests. * test: iterate with DirectoryRecursive instead of std::filesystem iterator Match the style already used in MRZip.cpp. Unlike the std library's recursive_directory_iterator, MRMesh's DirectoryRecursive accepts an error_code at construction and saves errors into it rather than throwing, so the loop cannot raise std::filesystem_error on a transient permission glitch, a removed file, etc. No behavioural change for the happy path; same iteration order, same directory_entry values, same is_regular_file / relative calls.
1 parent 775f1fc commit aececa3

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

source/MRTest/MRZipCompressTests.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <MRMesh/MRDirectory.h>
12
#include <MRMesh/MRGTest.h>
23
#include <MRMesh/MRMakeSphereMesh.h>
34
#include <MRMesh/MRMesh.h>
@@ -194,6 +195,50 @@ TEST( MRMesh, CompressManySmallFilesToZip )
194195

195196
// Sanity envelope: same bound as the sphere test.
196197
EXPECT_LT( zipSize, totalInput * 2u );
198+
199+
// Round-trip: decompress the archive into a fresh temp folder and verify
200+
// every original file comes back byte-for-byte. Catches subtle regressions
201+
// in the compressZip -> decompressZip path that the size envelope above
202+
// would miss (entry truncation, wrong method byte, CRC-vs-data mismatch,
203+
// off-by-one in a local file header, etc.).
204+
UniqueTemporaryFolder roundtripFolder;
205+
ASSERT_TRUE( bool( roundtripFolder ) );
206+
const auto decompressRes = decompressZip( zipPath, roundtripFolder );
207+
ASSERT_TRUE( decompressRes.has_value() ) << decompressRes.error();
208+
209+
auto readAllBytes = []( const std::filesystem::path& p ) -> std::vector<char>
210+
{
211+
std::ifstream in( p, std::ios::binary | std::ios::ate );
212+
if ( !in )
213+
return {};
214+
const std::streamoff sz = in.tellg();
215+
in.seekg( 0 );
216+
std::vector<char> buf( sz < 0 ? 0 : size_t( sz ) );
217+
if ( !buf.empty() )
218+
in.read( buf.data(), std::streamsize( buf.size() ) );
219+
return buf;
220+
};
221+
222+
int verified = 0;
223+
const std::filesystem::path srcRoot = srcFolder;
224+
const std::filesystem::path rtRoot = roundtripFolder;
225+
for ( auto entry : DirectoryRecursive{ srcRoot, ec } )
226+
{
227+
if ( !entry.is_regular_file( ec ) )
228+
continue;
229+
const auto rel = std::filesystem::relative( entry.path(), srcRoot, ec );
230+
const auto dst = rtRoot / rel;
231+
ASSERT_TRUE( std::filesystem::exists( dst, ec ) )
232+
<< "missing in roundtrip: " << rel.generic_string();
233+
const auto origBytes = readAllBytes( entry.path() );
234+
const auto rtBytes = readAllBytes( dst );
235+
ASSERT_EQ( origBytes.size(), rtBytes.size() )
236+
<< "size mismatch: " << rel.generic_string();
237+
EXPECT_EQ( origBytes, rtBytes )
238+
<< "content mismatch: " << rel.generic_string();
239+
++verified;
240+
}
241+
EXPECT_EQ( verified, numBinaryFiles + numJsonFiles );
197242
}
198243

199244
} // namespace MR

0 commit comments

Comments
 (0)