]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
zstreamtest : add test which detects when ZSTD_initCStream() inflate data
authorYann Collet <cyan@fb.com>
Thu, 7 Dec 2017 08:06:01 +0000 (03:06 -0500)
committerYann Collet <cyan@fb.com>
Thu, 7 Dec 2017 08:06:01 +0000 (03:06 -0500)
as in #942, when ZSTD_initCStream() believes data is empty, instead of unknown.

tests/zstreamtest.c

index 920e988b054f9c677259d57e4d350f8ac350a583..e08a96d8fc930d106c0bf90eb917021e03664c26 100644 (file)
@@ -245,13 +245,28 @@ static int basicUnitTests(U32 seed, double compressibility)
     }
     dictID = ZDICT_getDictID(dictionary.start, dictionary.filled);
 
+    /* Basic compression test */
+    DISPLAYLEVEL(3, "test%3i : compress %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH);
+    CHECK_Z( ZSTD_initCStream(zc, 1 /* cLevel */) );
+    outBuff.dst = (char*)(compressedBuffer);
+    outBuff.size = compressedBufferSize;
+    outBuff.pos = 0;
+    inBuff.src = CNBuffer;
+    inBuff.size = CNBufferSize;
+    inBuff.pos = 0;
+    CHECK_Z( ZSTD_compressStream(zc, &outBuff, &inBuff) );
+    if (inBuff.pos != inBuff.size) goto _output_error;   /* entire input should be consumed */
+    { size_t const r = ZSTD_endStream(zc, &outBuff);
+      if (r != 0) goto _output_error; }  /* error, or some data not flushed */
+    DISPLAYLEVEL(3, "OK (%u bytes)\n", (U32)outBuff.pos);
+
     /* generate skippable frame */
     MEM_writeLE32(compressedBuffer, ZSTD_MAGIC_SKIPPABLE_START);
     MEM_writeLE32(((char*)compressedBuffer)+4, (U32)skippableFrameSize);
     cSize = skippableFrameSize + 8;
 
-    /* Basic compression test */
-    DISPLAYLEVEL(3, "test%3i : compress %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH);
+    /* Basic compression test using dict */
+    DISPLAYLEVEL(3, "test%3i : skipframe + compress %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH);
     CHECK_Z( ZSTD_initCStream_usingDict(zc, CNBuffer, dictSize, 1 /* cLevel */) );
     outBuff.dst = (char*)(compressedBuffer)+cSize;
     assert(compressedBufferSize > cSize);