Skip to content

Commit 30ab64e

Browse files
committed
added test for ZSTD_estimateCStreamSize()
1 parent cef02d9 commit 30ab64e

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

tests/zstreamtest.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
163163
ZSTD_inBuffer inBuff, inBuff2;
164164
ZSTD_outBuffer outBuff;
165165
buffer_t dictionary = g_nullBuffer;
166+
size_t const dictSize = 128 KB;
166167
unsigned dictID = 0;
167168

168169
/* Create compressible test buffer */
@@ -188,7 +189,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
188189

189190
/* Basic compression test */
190191
DISPLAYLEVEL(3, "test%3i : compress %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH);
191-
ZSTD_initCStream_usingDict(zc, CNBuffer, 128 KB, 1);
192+
ZSTD_initCStream_usingDict(zc, CNBuffer, dictSize, 1);
192193
outBuff.dst = (char*)(compressedBuffer)+cSize;
193194
outBuff.size = compressedBufferSize;
194195
outBuff.pos = 0;
@@ -203,7 +204,16 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
203204
cSize += outBuff.pos;
204205
DISPLAYLEVEL(3, "OK (%u bytes : %.2f%%)\n", (U32)cSize, (double)cSize/COMPRESSIBLE_NOISE_LENGTH*100);
205206

206-
DISPLAYLEVEL(3, "test%3i : check CStream size : ", testNb++);
207+
/* context size functions */
208+
DISPLAYLEVEL(3, "test%3i : estimate CStream size : ", testNb++);
209+
{ ZSTD_compressionParameters const cParams = ZSTD_getCParams(1, CNBufferSize, dictSize);
210+
size_t const s = ZSTD_estimateCStreamSize(cParams)
211+
+ ZSTD_estimateCDictSize(cParams, dictSize); /* uses ZSTD_initCStream_usingDict() */
212+
if (ZSTD_isError(s)) goto _output_error;
213+
DISPLAYLEVEL(3, "OK (%u bytes) \n", (U32)s);
214+
}
215+
216+
DISPLAYLEVEL(3, "test%3i : check actual CStream size : ", testNb++);
207217
{ size_t const s = ZSTD_sizeof_CStream(zc);
208218
if (ZSTD_isError(s)) goto _output_error;
209219
DISPLAYLEVEL(3, "OK (%u bytes) \n", (U32)s);
@@ -221,7 +231,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
221231

222232
/* skippable frame test */
223233
DISPLAYLEVEL(3, "test%3i : decompress skippable frame : ", testNb++);
224-
ZSTD_initDStream_usingDict(zd, CNBuffer, 128 KB);
234+
ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize);
225235
inBuff.src = compressedBuffer;
226236
inBuff.size = cSize;
227237
inBuff.pos = 0;
@@ -236,7 +246,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
236246
/* Basic decompression test */
237247
inBuff2 = inBuff;
238248
DISPLAYLEVEL(3, "test%3i : decompress %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH);
239-
ZSTD_initDStream_usingDict(zd, CNBuffer, 128 KB);
249+
ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize);
240250
{ size_t const r = ZSTD_setDStreamParameter(zd, DStream_p_maxWindowSize, 1000000000); /* large limit */
241251
if (ZSTD_isError(r)) goto _output_error; }
242252
{ size_t const remaining = ZSTD_decompressStream(zd, &outBuff, &inBuff);
@@ -270,7 +280,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
270280
if (gfhError!=0) goto _output_error;
271281
DISPLAYLEVEL(5, " (windowSize : %u) ", fhi.windowSize);
272282
{ size_t const s = ZSTD_estimateDStreamSize(fhi)
273-
+ ZSTD_estimateDDictSize(128 KB); /* uses ZSTD_initDStream_usingDict() */
283+
+ ZSTD_estimateDDictSize(dictSize); /* uses ZSTD_initDStream_usingDict() */
274284
if (ZSTD_isError(s)) goto _output_error;
275285
DISPLAYLEVEL(3, "OK (%u bytes) \n", (U32)s);
276286
} }
@@ -285,7 +295,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
285295
DISPLAYLEVEL(3, "test%3i : decompress byte-by-byte : ", testNb++);
286296
{ /* skippable frame */
287297
size_t r = 1;
288-
ZSTD_initDStream_usingDict(zd, CNBuffer, 128 KB);
298+
ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize);
289299
inBuff.src = compressedBuffer;
290300
outBuff.dst = decodedBuffer;
291301
inBuff.pos = 0;
@@ -297,7 +307,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
297307
if (ZSTD_isError(r)) goto _output_error;
298308
}
299309
/* normal frame */
300-
ZSTD_initDStream_usingDict(zd, CNBuffer, 128 KB);
310+
ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize);
301311
r=1;
302312
while (r) {
303313
inBuff.size = inBuff.pos + 1;
@@ -456,7 +466,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
456466

457467
/* Memory restriction */
458468
DISPLAYLEVEL(3, "test%3i : maxWindowSize < frame requirement : ", testNb++);
459-
ZSTD_initDStream_usingDict(zd, CNBuffer, 128 KB);
469+
ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize);
460470
{ size_t const r = ZSTD_setDStreamParameter(zd, DStream_p_maxWindowSize, 1000); /* too small limit */
461471
if (ZSTD_isError(r)) goto _output_error; }
462472
inBuff.src = compressedBuffer;

0 commit comments

Comments
 (0)