@@ -163,6 +163,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
163
163
ZSTD_inBuffer inBuff , inBuff2 ;
164
164
ZSTD_outBuffer outBuff ;
165
165
buffer_t dictionary = g_nullBuffer ;
166
+ size_t const dictSize = 128 KB ;
166
167
unsigned dictID = 0 ;
167
168
168
169
/* Create compressible test buffer */
@@ -188,7 +189,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
188
189
189
190
/* Basic compression test */
190
191
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 );
192
193
outBuff .dst = (char * )(compressedBuffer )+ cSize ;
193
194
outBuff .size = compressedBufferSize ;
194
195
outBuff .pos = 0 ;
@@ -203,7 +204,16 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
203
204
cSize += outBuff .pos ;
204
205
DISPLAYLEVEL (3 , "OK (%u bytes : %.2f%%)\n" , (U32 )cSize , (double )cSize /COMPRESSIBLE_NOISE_LENGTH * 100 );
205
206
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 ++ );
207
217
{ size_t const s = ZSTD_sizeof_CStream (zc );
208
218
if (ZSTD_isError (s )) goto _output_error ;
209
219
DISPLAYLEVEL (3 , "OK (%u bytes) \n" , (U32 )s );
@@ -221,7 +231,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
221
231
222
232
/* skippable frame test */
223
233
DISPLAYLEVEL (3 , "test%3i : decompress skippable frame : " , testNb ++ );
224
- ZSTD_initDStream_usingDict (zd , CNBuffer , 128 KB );
234
+ ZSTD_initDStream_usingDict (zd , CNBuffer , dictSize );
225
235
inBuff .src = compressedBuffer ;
226
236
inBuff .size = cSize ;
227
237
inBuff .pos = 0 ;
@@ -236,7 +246,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
236
246
/* Basic decompression test */
237
247
inBuff2 = inBuff ;
238
248
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 );
240
250
{ size_t const r = ZSTD_setDStreamParameter (zd , DStream_p_maxWindowSize , 1000000000 ); /* large limit */
241
251
if (ZSTD_isError (r )) goto _output_error ; }
242
252
{ size_t const remaining = ZSTD_decompressStream (zd , & outBuff , & inBuff );
@@ -270,7 +280,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
270
280
if (gfhError != 0 ) goto _output_error ;
271
281
DISPLAYLEVEL (5 , " (windowSize : %u) " , fhi .windowSize );
272
282
{ size_t const s = ZSTD_estimateDStreamSize (fhi )
273
- + ZSTD_estimateDDictSize (128 KB ); /* uses ZSTD_initDStream_usingDict() */
283
+ + ZSTD_estimateDDictSize (dictSize ); /* uses ZSTD_initDStream_usingDict() */
274
284
if (ZSTD_isError (s )) goto _output_error ;
275
285
DISPLAYLEVEL (3 , "OK (%u bytes) \n" , (U32 )s );
276
286
} }
@@ -285,7 +295,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
285
295
DISPLAYLEVEL (3 , "test%3i : decompress byte-by-byte : " , testNb ++ );
286
296
{ /* skippable frame */
287
297
size_t r = 1 ;
288
- ZSTD_initDStream_usingDict (zd , CNBuffer , 128 KB );
298
+ ZSTD_initDStream_usingDict (zd , CNBuffer , dictSize );
289
299
inBuff .src = compressedBuffer ;
290
300
outBuff .dst = decodedBuffer ;
291
301
inBuff .pos = 0 ;
@@ -297,7 +307,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
297
307
if (ZSTD_isError (r )) goto _output_error ;
298
308
}
299
309
/* normal frame */
300
- ZSTD_initDStream_usingDict (zd , CNBuffer , 128 KB );
310
+ ZSTD_initDStream_usingDict (zd , CNBuffer , dictSize );
301
311
r = 1 ;
302
312
while (r ) {
303
313
inBuff .size = inBuff .pos + 1 ;
@@ -456,7 +466,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
456
466
457
467
/* Memory restriction */
458
468
DISPLAYLEVEL (3 , "test%3i : maxWindowSize < frame requirement : " , testNb ++ );
459
- ZSTD_initDStream_usingDict (zd , CNBuffer , 128 KB );
469
+ ZSTD_initDStream_usingDict (zd , CNBuffer , dictSize );
460
470
{ size_t const r = ZSTD_setDStreamParameter (zd , DStream_p_maxWindowSize , 1000 ); /* too small limit */
461
471
if (ZSTD_isError (r )) goto _output_error ; }
462
472
inBuff .src = compressedBuffer ;
0 commit comments