diff --git a/tests/fuzzer.c b/tests/fuzzer.c index b0c425e1e..e9978ed80 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -1080,12 +1080,36 @@ static int basicUnitTests(U32 seed, double compressibility) ZSTD_freeCCtx(cctx); } + /* negative compression level test : ensure simple API and advanced API produce same result */ + DISPLAYLEVEL(3, "test%3i : negative compression level : ", testNb++); + { size_t const srcSize = CNBuffSize / 5; + int const compressionLevel = -2; + size_t const cSize_1pass = ZSTD_compress(compressedBuffer, compressedBufferSize, + CNBuffer, srcSize, + compressionLevel); + if (ZSTD_isError(cSize_1pass)) goto _output_error; + { ZSTD_CCtx* const cctx = ZSTD_createCCtx(); + assert(cctx != NULL); + CHECK( ZSTD_CCtx_setParameter(cctx, ZSTD_p_compressionLevel, compressionLevel) ); + { ZSTD_inBuffer in = { CNBuffer, srcSize, 0 }; + ZSTD_outBuffer out = { compressedBuffer, compressedBufferSize, 0 }; + size_t const compressionResult = ZSTD_compress_generic(cctx, &out, &in, ZSTD_e_end); + DISPLAYLEVEL(5, "simple=%zu vs %zu=advanced : ", cSize_1pass, out.pos); + if (ZSTD_isError(compressionResult)) goto _output_error; + if (out.pos != cSize_1pass) goto _output_error; + } + ZSTD_freeCCtx(cctx); + } + } + DISPLAYLEVEL(3, "OK \n"); + /* parameters order test */ { size_t const inputSize = CNBuffSize / 2; U64 xxh64; - { ZSTD_CCtx* cctx = ZSTD_createCCtx(); + { ZSTD_CCtx* const cctx = ZSTD_createCCtx(); DISPLAYLEVEL(3, "test%3i : parameters in order : ", testNb++); + assert(cctx != NULL); CHECK( ZSTD_CCtx_setParameter(cctx, ZSTD_p_compressionLevel, 2) ); CHECK( ZSTD_CCtx_setParameter(cctx, ZSTD_p_enableLongDistanceMatching, 1) ); CHECK( ZSTD_CCtx_setParameter(cctx, ZSTD_p_windowLog, 18) );