From f2c5f3124e385ac5f4f72d40f28b485c6484b624 Mon Sep 17 00:00:00 2001 From: Fedor Chelnokov Date: Fri, 24 Apr 2026 16:18:45 +0300 Subject: [PATCH] test: make MRMesh.ZlibCompressStats engine-agnostic The test currently compares `stats.compressedSize` and `out.str().size()` against `sizeof( cRawLevel* )` / `sizeof( cWrappedLevel* )`. Those reference blobs were captured from stock zlib, and the exact compressed byte count drifts from one deflate implementation to another (stock zlib vs zlib-ng compat vs zlib-ng native vs libdeflate -- all lossless, but each picks its own block-split / Huffman / match-length heuristics). Once we swap any part of the compress path to a non-zlib engine, this assertion fails for reasons that have nothing to do with correctness. Replace with engine-agnostic assertions: - CRC matches the reference CRC of the input (decoder-defined, engine- independent). - Uncompressed size matches the input size (tautology that still guards against stats wiring regressions). - `stats.compressedSize == out.str().size()` -- API consistency between the stats block and the actual stream, regardless of engine. - `0 < stats.compressedSize < sizeof( cInput )` -- sanity: we produced a non-empty payload smaller than the input. Split out of #5959 so the test relaxation can land independently of the zlib-ng routing. Pure test change -- no source / build / CI impact. Co-Authored-By: Claude Opus 4.7 (1M context) --- source/MRTest/MRZlibTests.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/source/MRTest/MRZlibTests.cpp b/source/MRTest/MRZlibTests.cpp index c4b6bf1724b9..d72e75f24528 100644 --- a/source/MRTest/MRZlibTests.cpp +++ b/source/MRTest/MRZlibTests.cpp @@ -138,12 +138,12 @@ TEST( MRMesh, ZlibCompressStats ) const std::string inputStr( reinterpret_cast( cInput ), sizeof( cInput ) ); const uint32_t expectedCrc = crc32Ref( cInput, sizeof( cInput ) ); - struct Case { bool rawDeflate; int level; size_t expectedCompSize; }; + struct Case { bool rawDeflate; int level; }; const Case cases[] = { - { true, 1, sizeof( cRawLevel1 ) }, - { true, 9, sizeof( cRawLevel9 ) }, - { false, 1, sizeof( cWrappedLevel1 ) }, - { false, 9, sizeof( cWrappedLevel9 ) }, + { true, 1 }, + { true, 9 }, + { false, 1 }, + { false, 9 }, }; for ( const auto& c : cases ) @@ -155,10 +155,19 @@ TEST( MRMesh, ZlibCompressStats ) MR::ZlibCompressParams{ { .rawDeflate = c.rawDeflate }, c.level, &stats } ); EXPECT_TRUE( res.has_value() ); + // Engine-agnostic assertions: CRC and uncompressed size are defined by + // the input; stats.compressedSize must equal out.str().size() (API + // consistency); compressed output must be non-empty and smaller than + // the input. We deliberately do NOT pin stats.compressedSize to the + // size of cRawLevel*/cWrappedLevel* -- those reference blobs were + // captured from stock zlib, and the exact compressed byte count drifts + // from one deflate implementation to another (stock zlib vs zlib-ng + // compat vs zlib-ng native vs libdeflate, all lossless). EXPECT_EQ( stats.crc32, expectedCrc ); EXPECT_EQ( stats.uncompressedSize, sizeof( cInput ) ); - EXPECT_EQ( stats.compressedSize, c.expectedCompSize ); - EXPECT_EQ( out.str().size(), c.expectedCompSize ); + EXPECT_EQ( stats.compressedSize, out.str().size() ); + EXPECT_GT( stats.compressedSize, 0u ); + EXPECT_LT( stats.compressedSize, sizeof( cInput ) ); } }