|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : tzlibcases.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include "tzlib.h" |
|
19 |
|
20 //uLong dictId; |
|
21 |
|
22 #define CHECK_ERR(err, msg) { \ |
|
23 if (err != Z_OK) { \ |
|
24 INFO_PRINTF2(_L("Error: %d"), err); \ |
|
25 return err; \ |
|
26 } \ |
|
27 } |
|
28 |
|
29 |
|
30 TInt CTestZlib::PreDeflateInit( Byte * compr, uLong comprLen, TInt flush, TInt compression) |
|
31 { |
|
32 z_stream c_stream; // compression stream |
|
33 int err; |
|
34 const char hello[] = "hello, hello!"; |
|
35 uLong len = (uLong)strlen(hello)+1; |
|
36 |
|
37 c_stream.zalloc = (alloc_func)0; |
|
38 c_stream.zfree = (free_func)0; |
|
39 c_stream.opaque = (voidpf)0; |
|
40 |
|
41 err = deflateInit(&c_stream,compression);// Z_DEFAULT_COMPRESSION); |
|
42 |
|
43 if (err != Z_OK) |
|
44 { |
|
45 INFO_PRINTF2(_L("deflateInit error: %d"), err); |
|
46 return err; |
|
47 } |
|
48 |
|
49 c_stream.next_in = (Bytef*)hello; |
|
50 c_stream.next_out = compr; |
|
51 |
|
52 while (c_stream.total_in != len && c_stream.total_out < comprLen) |
|
53 { |
|
54 c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers |
|
55 err = deflate(&c_stream, flush); |
|
56 if (err != Z_OK) |
|
57 { |
|
58 INFO_PRINTF2(_L("deflate return code: %d"), err); |
|
59 deflateEnd(&c_stream); |
|
60 return err; |
|
61 } |
|
62 } |
|
63 // Finish the stream, still forcing small buffers: |
|
64 for (;;) |
|
65 { |
|
66 c_stream.avail_out = 1; |
|
67 err = deflate(&c_stream, Z_FINISH); |
|
68 if (err == Z_STREAM_END) break; |
|
69 if (err != Z_OK) |
|
70 { |
|
71 INFO_PRINTF2(_L("deflate error: %d"), err); |
|
72 deflateEnd(&c_stream); |
|
73 return err; |
|
74 } |
|
75 } |
|
76 |
|
77 deflateEnd(&c_stream); |
|
78 return KErrNone; |
|
79 } |
|
80 |
|
81 /** |
|
82 * Function Name : TestDeflateTest01 |
|
83 * TestCase Description: 1. Reads flush value more than Z_FINISH [i.e, 4] |
|
84 * 2. Reads negative flush value |
|
85 */ |
|
86 TInt CTestZlib::TestDeflateTest01( ) |
|
87 { |
|
88 INFO_PRINTF1(_L("Zlib Test deflate")); |
|
89 TInt flush, compression, expRet; |
|
90 |
|
91 Byte *comp; |
|
92 uLong compLen; |
|
93 compLen = 30; |
|
94 comp = (Byte*)calloc((uInt)compLen, 1); |
|
95 |
|
96 ReadIntParam(flush); |
|
97 ReadIntParam(compression); |
|
98 ReadIntParam(expRet); |
|
99 |
|
100 z_stream c_stream; // compression stream |
|
101 int err; |
|
102 const char hello[] = "hello, hello!"; |
|
103 uLong len = (uLong)strlen(hello)+1; |
|
104 |
|
105 c_stream.zalloc = (alloc_func)0; |
|
106 c_stream.zfree = (free_func)0; |
|
107 c_stream.opaque = (voidpf)0; |
|
108 |
|
109 err = deflateInit(&c_stream,compression);// Z_DEFAULT_COMPRESSION); |
|
110 |
|
111 if (err != Z_OK) |
|
112 { |
|
113 INFO_PRINTF2(_L("deflateInit error: %d"), err); |
|
114 free(comp); |
|
115 return err; |
|
116 } |
|
117 |
|
118 c_stream.next_in = (Bytef*)hello; |
|
119 c_stream.next_out = comp; |
|
120 |
|
121 while (c_stream.total_in != len && c_stream.total_out < compLen) |
|
122 { |
|
123 c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers |
|
124 err = deflate(&c_stream, flush); |
|
125 if (err == Z_STREAM_ERROR) |
|
126 { |
|
127 INFO_PRINTF1(_L("Negative test case passed")); |
|
128 deflateEnd(&c_stream); |
|
129 free(comp); |
|
130 return KErrNone; |
|
131 } |
|
132 } |
|
133 |
|
134 return KErrNone; |
|
135 |
|
136 } |
|
137 |
|
138 /** |
|
139 * Function Name : TestDeflatecopyDestNull |
|
140 * TestCase Description: Deflate copy with Destination as NULL |
|
141 */ |
|
142 TInt CTestZlib::TestDeflatecopyDestNull() |
|
143 { |
|
144 uLong len = (uLong)strlen(hello)+1; |
|
145 TInt retVal=0; |
|
146 Byte *compr, *uncompr; |
|
147 uLong comprLen = 20*sizeof(int); |
|
148 uLong uncomprLen = comprLen; |
|
149 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
150 if (compr == Z_NULL) |
|
151 { |
|
152 return KErrNoMemory; |
|
153 } |
|
154 |
|
155 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
156 if (uncompr == Z_NULL) |
|
157 { |
|
158 free(compr); |
|
159 return KErrNoMemory; |
|
160 } |
|
161 |
|
162 |
|
163 z_stream stream; |
|
164 int err; |
|
165 |
|
166 stream.zalloc = (alloc_func)0; |
|
167 stream.zfree = (free_func)0; |
|
168 stream.opaque = (voidpf)0; |
|
169 |
|
170 stream.next_in = (Bytef*)hello; |
|
171 stream.avail_in = (uInt)len; |
|
172 |
|
173 stream.next_out = compr; |
|
174 stream.avail_out = (uInt)comprLen; |
|
175 |
|
176 err = deflateInit(&stream, Z_DEFAULT_COMPRESSION); |
|
177 |
|
178 err=deflateCopy(NULL , &stream); |
|
179 |
|
180 if (err == Z_STREAM_ERROR ) |
|
181 { |
|
182 deflateEnd(&stream); |
|
183 free(compr); |
|
184 free(uncompr); |
|
185 retVal = KErrNone; |
|
186 } |
|
187 |
|
188 return retVal; |
|
189 } |
|
190 |
|
191 /** |
|
192 * Function Name : TestDeflateCopyStreamStateNull |
|
193 * TestCase Description: Deflate copy with source stream state as Z_NULL |
|
194 * Return value: KErrNone on deflateCopy retruning Z_STREAM_ERROR |
|
195 */ |
|
196 TInt CTestZlib::TestDeflateCopyStreamStateNull() |
|
197 { |
|
198 uLong len = (uLong)strlen(hello)+1; |
|
199 TInt retVal=0; |
|
200 Byte *compr, *uncompr; |
|
201 uLong comprLen = 20*sizeof(int); |
|
202 uLong uncomprLen = comprLen; |
|
203 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
204 if (compr == Z_NULL) |
|
205 { |
|
206 return KErrNoMemory; |
|
207 } |
|
208 |
|
209 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
210 if (uncompr == Z_NULL) |
|
211 { |
|
212 free(compr); |
|
213 return KErrNoMemory; |
|
214 } |
|
215 |
|
216 z_stream stream; |
|
217 z_stream stream1; |
|
218 int err = KErrNone; |
|
219 |
|
220 stream.zalloc = (alloc_func)0; |
|
221 stream.zfree = (free_func)0; |
|
222 stream.opaque = (voidpf)0; |
|
223 |
|
224 stream.next_in = (Bytef*)hello; |
|
225 stream.avail_in = (uInt)len; |
|
226 |
|
227 stream.next_out = compr; |
|
228 stream.avail_out = (uInt)comprLen; |
|
229 |
|
230 err = deflateInit(&stream, Z_DEFAULT_COMPRESSION); |
|
231 |
|
232 err=deflateCopy(&stream1, &stream); |
|
233 deflateEnd(&stream); |
|
234 deflateEnd(&stream1); |
|
235 |
|
236 // Make stream state Z_NULL and call deflateCopy for coverage imrprovement |
|
237 stream.state = Z_NULL; |
|
238 err=deflateCopy(&stream1 , &stream); |
|
239 |
|
240 if (err == Z_STREAM_ERROR ) |
|
241 { |
|
242 retVal = KErrNone; |
|
243 } |
|
244 free(compr); |
|
245 free(uncompr); |
|
246 return retVal; |
|
247 } |
|
248 |
|
249 /** |
|
250 * Function Name : TestDeflateInit2_WindowBits |
|
251 * TestCase Description: 1. WindowBits value more than 15 |
|
252 * 2. WindowBits value less than 8 |
|
253 * 3. WindowBits 8 |
|
254 */ |
|
255 TInt CTestZlib::TestDeflateInit2_WindowBits() |
|
256 { |
|
257 TInt res = KErrNone; |
|
258 z_stream stream; |
|
259 int err; |
|
260 int level=Z_DEFAULT_COMPRESSION; |
|
261 int WindowBits=0; |
|
262 |
|
263 uLong sourceLen = (uLong)strlen(hello)+1; |
|
264 Byte *compr; |
|
265 uLong comprLen = 10*sizeof(int); |
|
266 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
267 if (compr == Z_NULL) |
|
268 { |
|
269 return KErrNoMemory; |
|
270 } |
|
271 |
|
272 ReadIntParam(WindowBits); |
|
273 stream.zalloc = (alloc_func)0; |
|
274 stream.zfree = (free_func)0; |
|
275 stream.opaque = (voidpf)0; |
|
276 |
|
277 |
|
278 err= deflateInit2_(&stream, level, 8, WindowBits, 8, |
|
279 0, zlibVersion(), sizeof(z_stream)); |
|
280 |
|
281 if (err == Z_STREAM_ERROR) |
|
282 { |
|
283 res = KErrNone; |
|
284 } |
|
285 else if (err == Z_OK) |
|
286 { |
|
287 deflateEnd(&stream); |
|
288 res = KErrNone; |
|
289 } |
|
290 else |
|
291 { |
|
292 res = KErrGeneral; |
|
293 } |
|
294 |
|
295 free(compr); |
|
296 return res; |
|
297 } |
|
298 |
|
299 |
|
300 |
|
301 /** |
|
302 * Function Name : TestDeflateInit2_StreamSize |
|
303 * TestCase Description: Stream size less than sizeof(z_stream) |
|
304 */ |
|
305 TInt CTestZlib::TestDeflateInit2_StreamSize() |
|
306 { |
|
307 TInt res = KErrNone ; |
|
308 z_stream stream; |
|
309 int err; |
|
310 int level=Z_DEFAULT_COMPRESSION; |
|
311 int WindowBits=0; |
|
312 |
|
313 uLong sourceLen = (uLong)strlen(hello)+1; |
|
314 Byte *compr; |
|
315 uLong comprLen = 10*sizeof(int); |
|
316 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
317 if (compr == Z_NULL) |
|
318 { |
|
319 return KErrNoMemory; |
|
320 } |
|
321 |
|
322 ReadIntParam(WindowBits); |
|
323 stream.zalloc = (alloc_func)0; |
|
324 stream.zfree = (free_func)0; |
|
325 stream.opaque = (voidpf)0; |
|
326 |
|
327 // passing stream size < sizeof(z_stream) |
|
328 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
329 0, zlibVersion(), sizeof(z_stream)-10); |
|
330 |
|
331 if (err == Z_VERSION_ERROR) |
|
332 { |
|
333 res = KErrNone; |
|
334 } |
|
335 else |
|
336 { |
|
337 res = KErrGeneral; |
|
338 } |
|
339 |
|
340 free(compr); |
|
341 return res; |
|
342 } |
|
343 |
|
344 /** |
|
345 * Function Name : TestDeflateInit2_MemLevel |
|
346 * TestCase Description: 1. MemLevel value less than 1 |
|
347 * 2. MemLevel value more than MAX_MEM_LEVEL [i.e., 8] |
|
348 */ |
|
349 TInt CTestZlib::TestDeflateInit2_MemLevel() |
|
350 { |
|
351 TInt res = KErrNone ; |
|
352 z_stream stream; |
|
353 int err; |
|
354 int level=Z_DEFAULT_COMPRESSION; |
|
355 int MemLevel=0; |
|
356 |
|
357 uLong sourceLen = (uLong)strlen(hello)+1; |
|
358 Byte *compr; |
|
359 uLong comprLen = 10*sizeof(int); |
|
360 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
361 if (compr == Z_NULL) |
|
362 { |
|
363 return KErrNoMemory; |
|
364 } |
|
365 |
|
366 ReadIntParam(MemLevel); |
|
367 stream.zalloc = (alloc_func)0; |
|
368 stream.zfree = (free_func)0; |
|
369 stream.opaque = (voidpf)0; |
|
370 |
|
371 |
|
372 err= deflateInit2_(&stream, level, 3, 15, MemLevel, |
|
373 0, zlibVersion(), sizeof(z_stream)); |
|
374 |
|
375 if (err == Z_STREAM_ERROR) |
|
376 { |
|
377 res = KErrNone; |
|
378 } |
|
379 else |
|
380 { |
|
381 res = KErrGeneral; |
|
382 } |
|
383 |
|
384 //deflateEnd(&stream); |
|
385 free(compr); |
|
386 return res; |
|
387 } |
|
388 |
|
389 /** |
|
390 * Function Name : TestDeflateInit2_Level |
|
391 * TestCase Description: 1. Level value less than 0 |
|
392 * 2. Level value more than 9 |
|
393 */ |
|
394 TInt CTestZlib::TestDeflateInit2_Level() |
|
395 { |
|
396 TInt res = KErrNone ; |
|
397 z_stream stream; |
|
398 int err; |
|
399 int level=0; |
|
400 |
|
401 uLong sourceLen = (uLong)strlen(hello)+1; |
|
402 Byte *compr; |
|
403 uLong comprLen = 10*sizeof(int); |
|
404 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
405 if (compr == Z_NULL) |
|
406 { |
|
407 return KErrNoMemory; |
|
408 } |
|
409 |
|
410 ReadIntParam(level); |
|
411 stream.zalloc = (alloc_func)0; |
|
412 stream.zfree = (free_func)0; |
|
413 stream.opaque = (voidpf)0; |
|
414 |
|
415 |
|
416 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
417 0, zlibVersion(), sizeof(z_stream)); |
|
418 |
|
419 if (err == Z_STREAM_ERROR) |
|
420 { |
|
421 res = KErrNone; |
|
422 } |
|
423 else |
|
424 { |
|
425 res = KErrGeneral; |
|
426 } |
|
427 |
|
428 //deflateEnd(&stream); |
|
429 free(compr); |
|
430 return res; |
|
431 } |
|
432 |
|
433 /** |
|
434 * Function Name : TestDeflateInit2_Strategy |
|
435 * TestCase Description: 1. Strategy value less than 0 |
|
436 * 2. Strategy value more than Z_FIXED |
|
437 */ |
|
438 TInt CTestZlib::TestDeflateInit2_Strategy() |
|
439 { |
|
440 TInt res = KErrNone ; |
|
441 z_stream stream; |
|
442 int err; |
|
443 int level=Z_DEFAULT_COMPRESSION; |
|
444 int strategy=0; |
|
445 |
|
446 uLong sourceLen = (uLong)strlen(hello)+1; |
|
447 Byte *compr; |
|
448 uLong comprLen = 10*sizeof(int); |
|
449 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
450 if (compr == Z_NULL) |
|
451 { |
|
452 return KErrNoMemory; |
|
453 } |
|
454 |
|
455 ReadIntParam(strategy); |
|
456 stream.zalloc = (alloc_func)0; |
|
457 stream.zfree = (free_func)0; |
|
458 stream.opaque = (voidpf)0; |
|
459 |
|
460 |
|
461 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
462 strategy, zlibVersion(), sizeof(z_stream)); |
|
463 |
|
464 if (err == Z_STREAM_ERROR) |
|
465 { |
|
466 res = KErrNone; |
|
467 } |
|
468 else |
|
469 { |
|
470 res = KErrGeneral; |
|
471 } |
|
472 |
|
473 free(compr); |
|
474 return res; |
|
475 } |
|
476 |
|
477 /** |
|
478 * Function Name : TestDeflateInit2_Version |
|
479 * TestCase Description: Invalid version value |
|
480 * Return Value: returns Z_VERSION_ERROR |
|
481 */ |
|
482 TInt CTestZlib::TestDeflateInit2_Version() |
|
483 { |
|
484 TInt res = KErrNone ; |
|
485 z_stream stream; |
|
486 int err; |
|
487 int level=Z_DEFAULT_COMPRESSION; |
|
488 char version[5]; |
|
489 |
|
490 uLong sourceLen = (uLong)strlen(hello)+1; |
|
491 Byte *compr; |
|
492 uLong comprLen = 10*sizeof(int); |
|
493 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
494 if (compr == Z_NULL) |
|
495 { |
|
496 return KErrNoMemory; |
|
497 } |
|
498 |
|
499 ReadStringParam(version); |
|
500 stream.zalloc = (alloc_func)0; |
|
501 stream.zfree = (free_func)0; |
|
502 stream.opaque = (voidpf)0; |
|
503 |
|
504 |
|
505 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
506 0, version, sizeof(z_stream)); |
|
507 |
|
508 if (err == Z_VERSION_ERROR) |
|
509 { |
|
510 res = KErrNone; |
|
511 } |
|
512 else |
|
513 { |
|
514 res = KErrGeneral; |
|
515 } |
|
516 |
|
517 free(compr); |
|
518 return res; |
|
519 } |
|
520 |
|
521 /** |
|
522 * Function Name : TestDeflateInit2_VersionNull |
|
523 * TestCase Description: version value is Z_NULL |
|
524 * Return Value: Z_VERSION_ERROR |
|
525 */ |
|
526 TInt CTestZlib::TestDeflateInit2_VersionNull() |
|
527 { |
|
528 TInt res = KErrNone ; |
|
529 z_stream stream; |
|
530 int err; |
|
531 int level=Z_DEFAULT_COMPRESSION; |
|
532 |
|
533 uLong sourceLen = (uLong)strlen(hello)+1; |
|
534 Byte *compr; |
|
535 uLong comprLen = 10*sizeof(int); |
|
536 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
537 if (compr == Z_NULL) |
|
538 { |
|
539 return KErrNoMemory; |
|
540 } |
|
541 |
|
542 stream.zalloc = (alloc_func)0; |
|
543 stream.zfree = (free_func)0; |
|
544 stream.opaque = (voidpf)0; |
|
545 |
|
546 |
|
547 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
548 0, Z_NULL, sizeof(z_stream)); |
|
549 |
|
550 if (err == Z_VERSION_ERROR) |
|
551 { |
|
552 res = KErrNone; |
|
553 } |
|
554 else |
|
555 { |
|
556 res = KErrGeneral; |
|
557 } |
|
558 |
|
559 free(compr); |
|
560 return res; |
|
561 } |
|
562 |
|
563 |
|
564 /** |
|
565 * Function Name : TestDeflateInit2_StreamNull |
|
566 * TestCase Description: Pass Z_NULL stream |
|
567 */ |
|
568 TInt CTestZlib::TestDeflateInit2_StreamNull() |
|
569 { |
|
570 TInt res = KErrNone ; |
|
571 //z_stream stream; |
|
572 int err; |
|
573 int level=Z_DEFAULT_COMPRESSION; |
|
574 |
|
575 uLong sourceLen = (uLong)strlen(hello)+1; |
|
576 Byte *compr; |
|
577 uLong comprLen = 10*sizeof(int); |
|
578 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
579 if (compr == Z_NULL) |
|
580 { |
|
581 return KErrNoMemory; |
|
582 } |
|
583 |
|
584 //stream.zalloc = (alloc_func)0; |
|
585 //stream.zfree = (free_func)0; |
|
586 //stream.opaque = (voidpf)0; |
|
587 |
|
588 err= deflateInit2_(Z_NULL, level, 8, 15, 8, |
|
589 0, zlibVersion(), sizeof(z_stream)); |
|
590 |
|
591 if (err == Z_STREAM_ERROR) |
|
592 { |
|
593 res = KErrNone; |
|
594 } |
|
595 else |
|
596 { |
|
597 res = KErrGeneral; |
|
598 } |
|
599 |
|
600 free(compr); |
|
601 return res; |
|
602 } |
|
603 |
|
604 /** |
|
605 * Function Name : TestInflateInit2_Version |
|
606 * TestCase Description: Invalid version value |
|
607 * Return Value: returns Z_VERSION_ERROR |
|
608 */ |
|
609 TInt CTestZlib::TestInflateInit2_Version() |
|
610 { |
|
611 TInt res = KErrNone ; |
|
612 |
|
613 z_stream d_stream; // decompression stream |
|
614 char version[5]; |
|
615 d_stream.zalloc = (alloc_func)0; |
|
616 d_stream.zfree = (free_func)0; |
|
617 d_stream.opaque = (voidpf)0; |
|
618 |
|
619 Byte *compr, *uncompr; |
|
620 uLong comprLen = 20*sizeof(int); // don't overflow on MSDOS |
|
621 uLong uncomprLen = comprLen; |
|
622 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
623 if (compr == Z_NULL) |
|
624 { |
|
625 return KErrNoMemory; |
|
626 } |
|
627 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
628 if (uncompr == Z_NULL) |
|
629 { |
|
630 free(compr); |
|
631 return KErrNoMemory; |
|
632 } |
|
633 res = Test_deflate(compr, comprLen); |
|
634 if(res<0) |
|
635 { |
|
636 free(compr); |
|
637 free(uncompr); |
|
638 return KErrNoMemory; |
|
639 } |
|
640 d_stream.next_in = compr; |
|
641 d_stream.avail_in = 0; |
|
642 d_stream.next_out = uncompr; |
|
643 |
|
644 //Reading invalid version from ini file |
|
645 ReadStringParam(version); |
|
646 |
|
647 int ret = inflateInit2_(&d_stream, 15, version, sizeof(d_stream)); |
|
648 if(ret == Z_VERSION_ERROR) |
|
649 { |
|
650 res = KErrNone; |
|
651 } |
|
652 else |
|
653 { |
|
654 res = KErrGeneral; |
|
655 } |
|
656 free(compr); |
|
657 free(uncompr); |
|
658 return res; |
|
659 } |
|
660 |
|
661 /** |
|
662 * Function Name : TestInflateInit2_VersionNull |
|
663 * TestCase Description: version value is Z_NULL |
|
664 * Return Value: Z_VERSION_ERROR |
|
665 */ |
|
666 TInt CTestZlib::TestInflateInit2_VersionNull() |
|
667 { |
|
668 TInt res = KErrNone ; |
|
669 |
|
670 z_stream d_stream; // decompression stream |
|
671 d_stream.zalloc = (alloc_func)0; |
|
672 d_stream.zfree = (free_func)0; |
|
673 d_stream.opaque = (voidpf)0; |
|
674 |
|
675 Byte *compr, *uncompr; |
|
676 uLong comprLen = 20*sizeof(int); // don't overflow on MSDOS |
|
677 uLong uncomprLen = comprLen; |
|
678 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
679 if (compr == Z_NULL) |
|
680 { |
|
681 return KErrNoMemory; |
|
682 } |
|
683 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
684 if (uncompr == Z_NULL) |
|
685 { |
|
686 free(compr); |
|
687 return KErrNoMemory; |
|
688 } |
|
689 res = Test_deflate(compr, comprLen); |
|
690 if(res<0) |
|
691 { |
|
692 free(compr); |
|
693 free(uncompr); |
|
694 return KErrNoMemory; |
|
695 } |
|
696 d_stream.next_in = compr; |
|
697 d_stream.avail_in = 0; |
|
698 d_stream.next_out = uncompr; |
|
699 |
|
700 int ret = inflateInit2_(&d_stream, 15, Z_NULL, sizeof(d_stream)); |
|
701 if(ret == Z_VERSION_ERROR) |
|
702 { |
|
703 res = KErrNone; |
|
704 } |
|
705 else |
|
706 { |
|
707 res = KErrGeneral; |
|
708 } |
|
709 free(compr); |
|
710 free(uncompr); |
|
711 return res; |
|
712 } |
|
713 |
|
714 /** |
|
715 * Function Name : TestInflateInit2_WindowBits |
|
716 * TestCase Description: Window bits more than 48 to increase the conditional coverage |
|
717 * Return Value: returns Z_STREAM_ERROR |
|
718 */ |
|
719 TInt CTestZlib::TestInflateInit2_WindowBits() |
|
720 { |
|
721 TInt res = KErrNone ; |
|
722 |
|
723 z_stream d_stream; // decompression stream |
|
724 int WindowBits = 0; |
|
725 d_stream.zalloc = (alloc_func)0; |
|
726 d_stream.zfree = (free_func)0; |
|
727 d_stream.opaque = (voidpf)0; |
|
728 |
|
729 Byte *compr, *uncompr; |
|
730 uLong comprLen = 20*sizeof(int); // don't overflow on MSDOS |
|
731 uLong uncomprLen = comprLen; |
|
732 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
733 if (compr == Z_NULL) |
|
734 { |
|
735 return KErrNoMemory; |
|
736 } |
|
737 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
738 if (uncompr == Z_NULL) |
|
739 { |
|
740 free(compr); |
|
741 return KErrNoMemory; |
|
742 } |
|
743 res = Test_deflate(compr, comprLen); |
|
744 if(res<0) |
|
745 { |
|
746 free(compr); |
|
747 free(uncompr); |
|
748 return KErrNoMemory; |
|
749 } |
|
750 d_stream.next_in = compr; |
|
751 d_stream.avail_in = 0; |
|
752 d_stream.next_out = uncompr; |
|
753 |
|
754 //Reading window bits from ini file |
|
755 ReadIntParam(WindowBits); |
|
756 |
|
757 int ret = inflateInit2_(&d_stream, WindowBits, "1.2.4", sizeof(d_stream)); |
|
758 if(ret == Z_STREAM_ERROR) |
|
759 { |
|
760 res = KErrNone; |
|
761 } |
|
762 else |
|
763 { |
|
764 res = KErrGeneral; |
|
765 } |
|
766 free(compr); |
|
767 free(uncompr); |
|
768 return res; |
|
769 } |
|
770 |
|
771 /** |
|
772 * Function Name : TestInflateInit2_StreamNull |
|
773 * TestCase Description: Stream NULL |
|
774 * Return Value: returns Z_STREAM_ERROR |
|
775 */ |
|
776 TInt CTestZlib::TestInflateInit2_StreamNull() |
|
777 { |
|
778 TInt res = KErrNone ; |
|
779 |
|
780 z_stream d_stream; // decompression stream |
|
781 //d_stream.zalloc = (alloc_func)0; |
|
782 //d_stream.zfree = (free_func)0; |
|
783 //d_stream.opaque = (voidpf)0; |
|
784 |
|
785 Byte *compr, *uncompr; |
|
786 uLong comprLen = 20*sizeof(int); // don't overflow on MSDOS |
|
787 uLong uncomprLen = comprLen; |
|
788 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
789 if (compr == Z_NULL) |
|
790 { |
|
791 return KErrNoMemory; |
|
792 } |
|
793 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
794 if (uncompr == Z_NULL) |
|
795 { |
|
796 free(compr); |
|
797 return KErrNoMemory; |
|
798 } |
|
799 res = Test_deflate(compr, comprLen); |
|
800 if(res<0) |
|
801 { |
|
802 free(compr); |
|
803 free(uncompr); |
|
804 return KErrNoMemory; |
|
805 } |
|
806 //d_stream.next_in = compr; |
|
807 //d_stream.avail_in = 0; |
|
808 //d_stream.next_out = uncompr; |
|
809 |
|
810 int ret = inflateInit2_(Z_NULL, 15, "1.2.4", sizeof(d_stream)); |
|
811 if(ret == Z_STREAM_ERROR) |
|
812 { |
|
813 res = KErrNone; |
|
814 } |
|
815 else |
|
816 { |
|
817 res = KErrGeneral; |
|
818 } |
|
819 free(compr); |
|
820 free(uncompr); |
|
821 return res; |
|
822 } |
|
823 |
|
824 /** |
|
825 * Function Name : TestDeflate_HuffmanStrategy |
|
826 * TestCase Description: Strategy is HUFFMAN |
|
827 * Return Value: Z_OK |
|
828 */ |
|
829 TInt CTestZlib::TestDeflate_HuffmanStrategy() |
|
830 { |
|
831 TInt res = KErrNone ; |
|
832 z_stream stream; |
|
833 int err; |
|
834 int level=Z_DEFAULT_COMPRESSION; |
|
835 |
|
836 uLong sourceLen = (uLong)strlen(hello)+1; |
|
837 Byte *compr; |
|
838 uLong comprLen = 20*sizeof(int); |
|
839 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
840 if (compr == Z_NULL) |
|
841 { |
|
842 return KErrNoMemory; |
|
843 } |
|
844 |
|
845 stream.zalloc = (alloc_func)0; |
|
846 stream.zfree = (free_func)0; |
|
847 stream.opaque = (voidpf)0; |
|
848 |
|
849 |
|
850 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
851 2, zlibVersion(), sizeof(z_stream)); |
|
852 |
|
853 if (err == Z_OK) |
|
854 { |
|
855 res = KErrNone; |
|
856 } |
|
857 else |
|
858 { |
|
859 res = KErrGeneral; |
|
860 } |
|
861 |
|
862 stream.next_in = (Bytef*)hello; |
|
863 stream.next_out = compr; |
|
864 |
|
865 while (stream.total_in != sourceLen && stream.total_out < comprLen) |
|
866 { |
|
867 stream.avail_in = stream.avail_out = 1; /* force small buffers */ |
|
868 err = deflate(&stream, Z_NO_FLUSH); |
|
869 } |
|
870 /* Finish the stream, still forcing small buffers: */ |
|
871 for (;;) |
|
872 { |
|
873 stream.avail_out = 1; |
|
874 err = deflate(&stream, Z_FINISH); |
|
875 if (err == Z_STREAM_END) break; |
|
876 if(err!=Z_OK) |
|
877 { |
|
878 res = KErrGeneral; |
|
879 } |
|
880 } |
|
881 |
|
882 err = deflateEnd(&stream); |
|
883 if(err!=Z_OK) |
|
884 { |
|
885 res = KErrGeneral; |
|
886 } |
|
887 |
|
888 free(compr); |
|
889 return res; |
|
890 } |
|
891 |
|
892 /** |
|
893 * Function Name : TestDeflate_AvailInZero |
|
894 * TestCase Description: avail_in value is set to 0 |
|
895 * Return Value: Z_STREAM_ERROR |
|
896 */ |
|
897 TInt CTestZlib::TestDeflate_AvailInZero() |
|
898 { |
|
899 TInt res = KErrNone ; |
|
900 z_stream stream; |
|
901 int err; |
|
902 int level=Z_DEFAULT_COMPRESSION; |
|
903 |
|
904 uLong sourceLen = (uLong)strlen(hello)+1; |
|
905 Byte *compr; |
|
906 uLong comprLen = 20*sizeof(int); |
|
907 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
908 if (compr == Z_NULL) |
|
909 { |
|
910 return KErrNoMemory; |
|
911 } |
|
912 |
|
913 stream.zalloc = (alloc_func)0; |
|
914 stream.zfree = (free_func)0; |
|
915 stream.opaque = (voidpf)0; |
|
916 |
|
917 |
|
918 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
919 0, zlibVersion(), sizeof(z_stream)); |
|
920 |
|
921 if (err == Z_OK) |
|
922 { |
|
923 res = KErrNone; |
|
924 } |
|
925 else |
|
926 { |
|
927 res = KErrGeneral; |
|
928 } |
|
929 |
|
930 stream.next_in = Z_NULL; |
|
931 stream.next_out = Z_NULL; |
|
932 |
|
933 while (stream.total_in != sourceLen && stream.total_out < comprLen) |
|
934 { |
|
935 stream.avail_in = 0; // Setting avail_in to zero |
|
936 stream.avail_out = 1; // force small buffers |
|
937 err = deflate(&stream, Z_NO_FLUSH); |
|
938 if (err != Z_OK) |
|
939 break; |
|
940 } |
|
941 |
|
942 if (err == Z_STREAM_ERROR) |
|
943 { |
|
944 res = KErrNone; |
|
945 deflateEnd(&stream); |
|
946 free(compr); |
|
947 return res; |
|
948 } |
|
949 else |
|
950 { |
|
951 res = KErrGeneral; |
|
952 free(compr); |
|
953 } |
|
954 |
|
955 return res; |
|
956 } |
|
957 |
|
958 /** |
|
959 * Function Name : TestGzsetparamDefaultCompression |
|
960 * TestCase Description: This test case is intended to cover the condition in |
|
961 * deflateParams_r. Z_DEFAULT_COMPRESSION and strategy>4 is passed |
|
962 * Return Value: Z_STREAM_ERROR |
|
963 */ |
|
964 TInt CTestZlib::TestGzsetparamDefaultCompression() |
|
965 { |
|
966 TInt res = KErrNone ; |
|
967 |
|
968 int len = (int)strlen(hello)+1; |
|
969 gzFile file; |
|
970 |
|
971 const char * fname = TESTFILE; |
|
972 |
|
973 file = gzopen(fname, "wb"); |
|
974 gzputc(file, 'h'); |
|
975 |
|
976 int u = gzsetparams(file, Z_DEFAULT_COMPRESSION, 8); |
|
977 if(u == Z_STREAM_ERROR) |
|
978 { |
|
979 res=KErrNone; |
|
980 } |
|
981 int err= gzclose(file); |
|
982 if (err != Z_OK) |
|
983 { |
|
984 res = KErrGeneral; |
|
985 } |
|
986 |
|
987 return res; |
|
988 } |
|
989 |
|
990 /** |
|
991 * Function Name : TestDeflateResetNullStream |
|
992 * TestCase Description: Pass NULL stream |
|
993 * Return Value: Z_STREAM_ERROR |
|
994 */ |
|
995 TInt CTestZlib::TestDeflateResetNullStream() |
|
996 { |
|
997 INFO_PRINTF1(_L("DeflateReset test with NULL input")); |
|
998 TInt res = KErrNone ; |
|
999 int level = Z_DEFAULT_COMPRESSION ; |
|
1000 uLong len = (uLong)strlen(hello)+1; |
|
1001 Byte *compr, *uncompr; |
|
1002 uLong comprLen = 20*sizeof(int); |
|
1003 uLong uncomprLen = comprLen; |
|
1004 int err; |
|
1005 z_stream stream; |
|
1006 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1007 if (compr == Z_NULL) |
|
1008 { |
|
1009 return KErrNoMemory; |
|
1010 } |
|
1011 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
1012 if (uncompr == Z_NULL) |
|
1013 { |
|
1014 free(compr); |
|
1015 return KErrNoMemory; |
|
1016 } |
|
1017 |
|
1018 stream.zalloc = (alloc_func)0; |
|
1019 stream.zfree = (free_func)0; |
|
1020 stream.opaque = (voidpf)0; |
|
1021 |
|
1022 err = deflateInit(&stream, level); |
|
1023 if (err != Z_OK) |
|
1024 { |
|
1025 free(compr); |
|
1026 free(uncompr); |
|
1027 return err; |
|
1028 } |
|
1029 |
|
1030 Bytef *dest = compr ; |
|
1031 uLongf *destLen = &comprLen; |
|
1032 const Bytef *source = (const Bytef*)hello; |
|
1033 uLong sourceLen = len; |
|
1034 |
|
1035 stream.next_in = (Bytef*)source; |
|
1036 stream.avail_in = (uInt)sourceLen; |
|
1037 |
|
1038 #ifdef MAXSEG_64K |
|
1039 /* Check for source > 64K on 16-bit machine: */ |
|
1040 if ((uLong)stream.avail_in != sourceLen) |
|
1041 { |
|
1042 res = KErrGeneral; |
|
1043 } |
|
1044 #endif |
|
1045 |
|
1046 stream.next_out = dest; |
|
1047 stream.avail_out = (uInt)*destLen; |
|
1048 |
|
1049 if ((uLong)stream.avail_out != *destLen) |
|
1050 { |
|
1051 res = KErrGeneral; |
|
1052 } |
|
1053 |
|
1054 err=deflateReset(Z_NULL/*&stream*/); |
|
1055 if (err == Z_STREAM_ERROR) |
|
1056 { |
|
1057 res = KErrNone; |
|
1058 } |
|
1059 else |
|
1060 { |
|
1061 res = KErrGeneral; |
|
1062 } |
|
1063 deflateEnd(&stream); |
|
1064 free(compr); |
|
1065 free(uncompr); |
|
1066 return res; |
|
1067 } |
|
1068 |
|
1069 /** |
|
1070 * Function Name : TestDeflateResetStreamStateNull |
|
1071 * TestCase Description: Pass NULL stream state |
|
1072 * Return Value: Z_STREAM_ERROR |
|
1073 */ |
|
1074 TInt CTestZlib::TestDeflateResetStreamStateNull() |
|
1075 { |
|
1076 TInt res = KErrNone ; |
|
1077 int level = Z_DEFAULT_COMPRESSION ; |
|
1078 uLong len = (uLong)strlen(hello)+1; |
|
1079 Byte *compr, *uncompr; |
|
1080 uLong comprLen = 20*sizeof(int); |
|
1081 uLong uncomprLen = comprLen; |
|
1082 int err; |
|
1083 z_stream stream; |
|
1084 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1085 if (compr == Z_NULL) |
|
1086 { |
|
1087 return KErrNoMemory; |
|
1088 } |
|
1089 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
1090 if (uncompr == Z_NULL) |
|
1091 { |
|
1092 free(compr); |
|
1093 return KErrNoMemory; |
|
1094 } |
|
1095 |
|
1096 stream.zalloc = (alloc_func)0; |
|
1097 stream.zfree = (free_func)0; |
|
1098 stream.opaque = (voidpf)0; |
|
1099 |
|
1100 err = deflateInit(&stream, level); |
|
1101 if (err != Z_OK) |
|
1102 { |
|
1103 free(compr); |
|
1104 free(uncompr); |
|
1105 return err; |
|
1106 } |
|
1107 |
|
1108 Bytef *dest = compr ; |
|
1109 uLongf *destLen = &comprLen; |
|
1110 const Bytef *source = (const Bytef*)hello; |
|
1111 uLong sourceLen = len; |
|
1112 |
|
1113 stream.next_in = (Bytef*)source; |
|
1114 stream.avail_in = (uInt)sourceLen; |
|
1115 |
|
1116 #ifdef MAXSEG_64K |
|
1117 /* Check for source > 64K on 16-bit machine: */ |
|
1118 if ((uLong)stream.avail_in != sourceLen) |
|
1119 { |
|
1120 res = KErrGeneral; |
|
1121 } |
|
1122 #endif |
|
1123 |
|
1124 stream.next_out = dest; |
|
1125 stream.avail_out = (uInt)*destLen; |
|
1126 |
|
1127 if ((uLong)stream.avail_out != *destLen) |
|
1128 { |
|
1129 res = KErrGeneral; |
|
1130 } |
|
1131 |
|
1132 err=deflateReset(&stream); |
|
1133 deflateEnd(&stream); |
|
1134 |
|
1135 //equate stream state to Z_NULL for coverage improvement |
|
1136 stream.state = Z_NULL; |
|
1137 err=deflateReset(&stream); |
|
1138 |
|
1139 if (err == Z_STREAM_ERROR) |
|
1140 { |
|
1141 res = KErrNone; |
|
1142 } |
|
1143 else |
|
1144 { |
|
1145 res = KErrGeneral; |
|
1146 } |
|
1147 free(compr); |
|
1148 free(uncompr); |
|
1149 return res; |
|
1150 } |
|
1151 |
|
1152 /** |
|
1153 * Function Name : TestDeflate_Scenarios |
|
1154 * TestCase Description: 1. Compression level is Z_DEFAULT_COMPRESSION, strategy is Z_RLE |
|
1155 * 2. Compression level is Z_BEST_SPEED, strategy is Z_HUFFMAN_ONLY |
|
1156 * 3. Compression level is Z_BEST_COMPRESSION, strategy is Z_FILTERED |
|
1157 * 4. Compression level is Z_BEST_COMPRESSION, strategy is Z_HUFFMAN_ONLY |
|
1158 * 5. Compression level is Z_BEST_COMPRESSION, strategy is Z_FIXED |
|
1159 * Return Value: Z_OK |
|
1160 */ |
|
1161 TInt CTestZlib::TestDeflate_Scenarios() |
|
1162 { |
|
1163 TInt res = KErrNone ; |
|
1164 z_stream stream; |
|
1165 int err; |
|
1166 int level=0; |
|
1167 int strategy=0; |
|
1168 |
|
1169 uLong sourceLen = (uLong)strlen(hello)+1; |
|
1170 Byte *compr; |
|
1171 uLong comprLen = 20*sizeof(int); |
|
1172 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1173 if (compr == Z_NULL) |
|
1174 { |
|
1175 return KErrNoMemory; |
|
1176 } |
|
1177 |
|
1178 stream.zalloc = (alloc_func)0; |
|
1179 stream.zfree = (free_func)0; |
|
1180 stream.opaque = (voidpf)0; |
|
1181 |
|
1182 ReadIntParam(level); |
|
1183 ReadIntParam(strategy); |
|
1184 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
1185 strategy, zlibVersion(), sizeof(z_stream)); |
|
1186 |
|
1187 if (err == Z_OK) |
|
1188 { |
|
1189 res = KErrNone; |
|
1190 } |
|
1191 else |
|
1192 { |
|
1193 res = KErrGeneral; |
|
1194 } |
|
1195 |
|
1196 stream.next_in = (Bytef*)hello; |
|
1197 stream.next_out = compr; |
|
1198 |
|
1199 while (stream.total_in != sourceLen && stream.total_out < comprLen) |
|
1200 { |
|
1201 stream.avail_in = stream.avail_out = 1; /* force small buffers */ |
|
1202 err = deflate(&stream, Z_NO_FLUSH); |
|
1203 } |
|
1204 /* Finish the stream, still forcing small buffers: */ |
|
1205 for (;;) |
|
1206 { |
|
1207 stream.avail_out = 1; |
|
1208 err = deflate(&stream, Z_FINISH); |
|
1209 if (err == Z_STREAM_END) break; |
|
1210 if(err!=Z_OK) |
|
1211 { |
|
1212 res = KErrGeneral; |
|
1213 } |
|
1214 } |
|
1215 |
|
1216 err = deflateEnd(&stream); |
|
1217 if(err!=Z_OK) |
|
1218 { |
|
1219 res = KErrGeneral; |
|
1220 } |
|
1221 |
|
1222 free(compr); |
|
1223 return res; |
|
1224 } |
|
1225 |
|
1226 /** |
|
1227 * Function Name : TestDeflate_NullStream |
|
1228 * TestCase Description: NULL stream is passed for deflate |
|
1229 * Return Value: Z_STREAM_ERROR |
|
1230 */ |
|
1231 TInt CTestZlib::TestDeflate_NullStream() |
|
1232 { |
|
1233 TInt res = KErrNone ; |
|
1234 z_stream stream; |
|
1235 int err; |
|
1236 int level=Z_DEFAULT_COMPRESSION; |
|
1237 |
|
1238 uLong sourceLen = (uLong)strlen(hello)+1; |
|
1239 Byte *compr; |
|
1240 uLong comprLen = 20*sizeof(int); |
|
1241 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1242 if (compr == Z_NULL) |
|
1243 { |
|
1244 return KErrNoMemory; |
|
1245 } |
|
1246 |
|
1247 stream.zalloc = (alloc_func)0; |
|
1248 stream.zfree = (free_func)0; |
|
1249 stream.opaque = (voidpf)0; |
|
1250 |
|
1251 |
|
1252 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
1253 0, zlibVersion(), sizeof(z_stream)); |
|
1254 |
|
1255 if (err == Z_OK) |
|
1256 { |
|
1257 res = KErrNone; |
|
1258 } |
|
1259 else |
|
1260 { |
|
1261 res = KErrGeneral; |
|
1262 } |
|
1263 |
|
1264 stream.next_in = (Bytef*)hello; |
|
1265 stream.next_out = compr; |
|
1266 |
|
1267 while (stream.total_in != sourceLen && stream.total_out < comprLen) |
|
1268 { |
|
1269 stream.avail_in = stream.avail_out = 1; // force small buffers |
|
1270 err = deflate(Z_NULL, Z_NO_FLUSH); |
|
1271 if (err != Z_OK) |
|
1272 break; |
|
1273 } |
|
1274 |
|
1275 if (err == Z_STREAM_ERROR) |
|
1276 { |
|
1277 res = KErrNone; |
|
1278 deflateEnd(&stream); |
|
1279 free(compr); |
|
1280 return res; |
|
1281 } |
|
1282 else |
|
1283 { |
|
1284 res = KErrGeneral; |
|
1285 } |
|
1286 |
|
1287 return res; |
|
1288 } |
|
1289 |
|
1290 /** |
|
1291 * Function Name : TestDeflate_StreamStateNull |
|
1292 * TestCase Description: stream state is made Z_NULL before calling deflate |
|
1293 * Return Value: Z_STREAM_ERROR |
|
1294 */ |
|
1295 TInt CTestZlib::TestDeflate_StreamStateNull() |
|
1296 { |
|
1297 TInt res = KErrNone ; |
|
1298 z_stream stream; |
|
1299 int err; |
|
1300 int level=Z_DEFAULT_COMPRESSION; |
|
1301 |
|
1302 uLong sourceLen = (uLong)strlen(hello)+1; |
|
1303 Byte *compr; |
|
1304 uLong comprLen = 20*sizeof(int); |
|
1305 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1306 if (compr == Z_NULL) |
|
1307 { |
|
1308 return KErrNoMemory; |
|
1309 } |
|
1310 |
|
1311 stream.zalloc = (alloc_func)0; |
|
1312 stream.zfree = (free_func)0; |
|
1313 stream.opaque = (voidpf)0; |
|
1314 |
|
1315 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
1316 0, zlibVersion(), sizeof(z_stream)); |
|
1317 |
|
1318 if (err == Z_OK) |
|
1319 { |
|
1320 res = KErrNone; |
|
1321 } |
|
1322 else |
|
1323 { |
|
1324 res = KErrGeneral; |
|
1325 } |
|
1326 |
|
1327 stream.next_in = (Bytef*)hello; |
|
1328 stream.next_out = compr; |
|
1329 |
|
1330 while (stream.total_in != sourceLen && stream.total_out < comprLen) |
|
1331 { |
|
1332 stream.avail_in = stream.avail_out = 1; // force small buffers |
|
1333 err = deflate(&stream, Z_NO_FLUSH); |
|
1334 } |
|
1335 deflateEnd(&stream); |
|
1336 |
|
1337 //equate stream state to Z_NULL for voverage improvement |
|
1338 stream.state = Z_NULL; |
|
1339 err = deflate(&stream, Z_NO_FLUSH); |
|
1340 |
|
1341 if (err == Z_STREAM_ERROR) |
|
1342 { |
|
1343 res = KErrNone; |
|
1344 } |
|
1345 else |
|
1346 { |
|
1347 res = KErrGeneral; |
|
1348 } |
|
1349 free(compr); |
|
1350 return res; |
|
1351 } |
|
1352 |
|
1353 /** |
|
1354 * Function Name : TestDeflateEndNull |
|
1355 * TestCase Description: Pass Z_NULL to deflateEnd |
|
1356 * Return Value: Z_STREAM_ERROR |
|
1357 */ |
|
1358 TInt CTestZlib::TestDeflateEndNull() |
|
1359 { |
|
1360 TInt res = KErrNone ; |
|
1361 z_stream stream; |
|
1362 int err; |
|
1363 int level=Z_DEFAULT_COMPRESSION; |
|
1364 int strategy=Z_DEFAULT_STRATEGY; |
|
1365 |
|
1366 uLong sourceLen = (uLong)strlen(hello)+1; |
|
1367 Byte *compr; |
|
1368 uLong comprLen = 20*sizeof(int); |
|
1369 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1370 if (compr == Z_NULL) |
|
1371 { |
|
1372 return KErrNoMemory; |
|
1373 } |
|
1374 |
|
1375 stream.zalloc = (alloc_func)0; |
|
1376 stream.zfree = (free_func)0; |
|
1377 stream.opaque = (voidpf)0; |
|
1378 |
|
1379 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
1380 strategy, zlibVersion(), sizeof(z_stream)); |
|
1381 |
|
1382 if (err == Z_OK) |
|
1383 { |
|
1384 res = KErrNone; |
|
1385 } |
|
1386 else |
|
1387 { |
|
1388 res = KErrGeneral; |
|
1389 } |
|
1390 |
|
1391 stream.next_in = (Bytef*)hello; |
|
1392 stream.next_out = compr; |
|
1393 |
|
1394 while (stream.total_in != sourceLen && stream.total_out < comprLen) |
|
1395 { |
|
1396 stream.avail_in = stream.avail_out = 1; /* force small buffers */ |
|
1397 err = deflate(&stream, Z_NO_FLUSH); |
|
1398 } |
|
1399 /* Finish the stream, still forcing small buffers: */ |
|
1400 for (;;) |
|
1401 { |
|
1402 stream.avail_out = 1; |
|
1403 err = deflate(&stream, Z_FINISH); |
|
1404 if (err == Z_STREAM_END) break; |
|
1405 if(err!=Z_OK) |
|
1406 { |
|
1407 res = KErrGeneral; |
|
1408 } |
|
1409 } |
|
1410 |
|
1411 // Pass Z_NULL |
|
1412 err = deflateEnd(&stream); |
|
1413 err = deflateEnd(Z_NULL); // for coverage improvement |
|
1414 if(err == Z_STREAM_ERROR) |
|
1415 { |
|
1416 res = KErrNone; |
|
1417 } |
|
1418 else |
|
1419 { |
|
1420 res = KErrGeneral; |
|
1421 } |
|
1422 |
|
1423 free(compr); |
|
1424 return res; |
|
1425 } |
|
1426 |
|
1427 /** |
|
1428 * Function Name : TestDeflateEndStreamStateNull |
|
1429 * TestCase Description: Make stream.state = Z_NULL |
|
1430 * Return Value: Z_STREAM_ERROR |
|
1431 */ |
|
1432 TInt CTestZlib::TestDeflateEndStreamStateNull() |
|
1433 { |
|
1434 TInt res = KErrNone ; |
|
1435 z_stream stream; |
|
1436 int err; |
|
1437 int level=Z_DEFAULT_COMPRESSION; |
|
1438 int strategy=Z_DEFAULT_STRATEGY; |
|
1439 |
|
1440 uLong sourceLen = (uLong)strlen(hello)+1; |
|
1441 Byte *compr; |
|
1442 uLong comprLen = 20*sizeof(int); |
|
1443 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1444 if (compr == Z_NULL) |
|
1445 { |
|
1446 return KErrNoMemory; |
|
1447 } |
|
1448 |
|
1449 stream.zalloc = (alloc_func)0; |
|
1450 stream.zfree = (free_func)0; |
|
1451 stream.opaque = (voidpf)0; |
|
1452 |
|
1453 err= deflateInit2_(&stream, level, 8, 15, 8, |
|
1454 strategy, zlibVersion(), sizeof(z_stream)); |
|
1455 |
|
1456 if (err == Z_OK) |
|
1457 { |
|
1458 res = KErrNone; |
|
1459 } |
|
1460 else |
|
1461 { |
|
1462 res = KErrGeneral; |
|
1463 } |
|
1464 |
|
1465 stream.next_in = (Bytef*)hello; |
|
1466 stream.next_out = compr; |
|
1467 |
|
1468 while (stream.total_in != sourceLen && stream.total_out < comprLen) |
|
1469 { |
|
1470 stream.avail_in = stream.avail_out = 1; /* force small buffers */ |
|
1471 err = deflate(&stream, Z_NO_FLUSH); |
|
1472 } |
|
1473 /* Finish the stream, still forcing small buffers: */ |
|
1474 for (;;) |
|
1475 { |
|
1476 stream.avail_out = 1; |
|
1477 err = deflate(&stream, Z_FINISH); |
|
1478 if (err == Z_STREAM_END) break; |
|
1479 if(err!=Z_OK) |
|
1480 { |
|
1481 res = KErrGeneral; |
|
1482 } |
|
1483 } |
|
1484 err = deflateEnd(&stream); |
|
1485 |
|
1486 // Make state Z_NULL |
|
1487 stream.state = Z_NULL; |
|
1488 err = deflateEnd(&stream); |
|
1489 |
|
1490 if(err == Z_STREAM_ERROR) |
|
1491 { |
|
1492 res = KErrNone; |
|
1493 } |
|
1494 else |
|
1495 { |
|
1496 res = KErrGeneral; |
|
1497 } |
|
1498 |
|
1499 free(compr); |
|
1500 return res; |
|
1501 } |
|
1502 |
|
1503 /** |
|
1504 * Function Name : TestDeflate_WindowBits |
|
1505 * TestCase Description: Window bits more than 15 is supplied for deflate init |
|
1506 * Return Value: Z_OK |
|
1507 */ |
|
1508 TInt CTestZlib::TestDeflate_WindowBits() |
|
1509 { |
|
1510 TInt res = KErrNone ; |
|
1511 z_stream stream; |
|
1512 int err; |
|
1513 int level=Z_BEST_COMPRESSION; |
|
1514 |
|
1515 uLong sourceLen = (uLong)strlen(hello)+1; |
|
1516 Byte *compr; |
|
1517 uLong comprLen = 20*sizeof(int); |
|
1518 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1519 if (compr == Z_NULL) |
|
1520 { |
|
1521 return KErrNoMemory; |
|
1522 } |
|
1523 |
|
1524 stream.zalloc = (alloc_func)0; |
|
1525 stream.zfree = (free_func)0; |
|
1526 stream.opaque = (voidpf)0; |
|
1527 |
|
1528 |
|
1529 err= deflateInit2_(&stream, level, 8, 25, 8, |
|
1530 0, zlibVersion(), sizeof(z_stream)); |
|
1531 |
|
1532 if (err == Z_OK) |
|
1533 { |
|
1534 res = KErrNone; |
|
1535 } |
|
1536 else |
|
1537 { |
|
1538 res = KErrGeneral; |
|
1539 } |
|
1540 |
|
1541 stream.next_in = (Bytef*)hello; |
|
1542 stream.next_out = compr; |
|
1543 |
|
1544 while (stream.total_in != sourceLen && stream.total_out < comprLen) |
|
1545 { |
|
1546 stream.avail_in = stream.avail_out = 1; /* force small buffers */ |
|
1547 err = deflate(&stream, Z_NO_FLUSH); |
|
1548 } |
|
1549 /* Finish the stream, still forcing small buffers: */ |
|
1550 for (;;) |
|
1551 { |
|
1552 stream.avail_out = 1; |
|
1553 err = deflate(&stream, Z_FINISH); |
|
1554 if (err == Z_STREAM_END) break; |
|
1555 if(err!=Z_OK) |
|
1556 { |
|
1557 res = KErrGeneral; |
|
1558 } |
|
1559 } |
|
1560 |
|
1561 err = deflateEnd(&stream); |
|
1562 if(err!=Z_OK) |
|
1563 { |
|
1564 res = KErrGeneral; |
|
1565 } |
|
1566 |
|
1567 free(compr); |
|
1568 return res; |
|
1569 } |
|
1570 |
|
1571 /** |
|
1572 * Function Name : TestDeflateBoundStreamNotNull |
|
1573 * TestCase Description: Pass valid stream to deflatebound with memlevel=7, which |
|
1574 * in turn covers the decision for (s->hash_bits != 8 + 7) |
|
1575 */ |
|
1576 TInt CTestZlib::TestDeflateBoundStreamNotNull() |
|
1577 { |
|
1578 TInt res = KErrNone; |
|
1579 z_stream stream; |
|
1580 int err; |
|
1581 int level=Z_DEFAULT_COMPRESSION; |
|
1582 |
|
1583 uLong sourceLen = (uLong)strlen(hello)+1; |
|
1584 Byte *compr; |
|
1585 uLong comprLen = 20*sizeof(int); |
|
1586 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1587 if (compr == Z_NULL) |
|
1588 { |
|
1589 return KErrNoMemory; |
|
1590 } |
|
1591 |
|
1592 stream.next_in = (Bytef*)hello; |
|
1593 stream.next_out = compr; |
|
1594 stream.avail_in = (uInt)sourceLen; |
|
1595 stream.avail_out = (uInt)comprLen; |
|
1596 if ((uLong)stream.avail_out != comprLen) |
|
1597 { |
|
1598 res = KErrGeneral; |
|
1599 } |
|
1600 |
|
1601 stream.zalloc = (alloc_func)0; |
|
1602 stream.zfree = (free_func)0; |
|
1603 stream.opaque = (voidpf)0; |
|
1604 |
|
1605 err= deflateInit2_(&stream, level, 8, 14, 7, |
|
1606 0, zlibVersion(), sizeof(z_stream)); |
|
1607 |
|
1608 if (err == Z_OK) |
|
1609 { |
|
1610 int y= deflateBound(&stream, sourceLen); |
|
1611 if(y > sourceLen) |
|
1612 { |
|
1613 res = KErrNone ; |
|
1614 } |
|
1615 else |
|
1616 { |
|
1617 res = KErrGeneral; |
|
1618 } |
|
1619 } |
|
1620 else |
|
1621 { |
|
1622 res = KErrGeneral; |
|
1623 return res; |
|
1624 } |
|
1625 |
|
1626 err=deflateEnd(&stream); |
|
1627 if (err != Z_OK) |
|
1628 { |
|
1629 res = KErrGeneral; |
|
1630 } |
|
1631 free(compr); |
|
1632 return res; |
|
1633 } |
|
1634 |
|
1635 /** |
|
1636 * Function Name : TestDeflateBoundStreamNull |
|
1637 * TestCase Description: Pass Z_NULL to deflatebound |
|
1638 */ |
|
1639 TInt CTestZlib::TestDeflateBoundStreamNull() |
|
1640 { |
|
1641 TInt res = KErrNone; |
|
1642 z_stream stream; |
|
1643 int err; |
|
1644 int level=Z_DEFAULT_COMPRESSION; |
|
1645 |
|
1646 uLong sourceLen = (uLong)strlen(hello)+1; |
|
1647 Byte *compr; |
|
1648 uLong comprLen = 20*sizeof(int); |
|
1649 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1650 if (compr == Z_NULL) |
|
1651 { |
|
1652 return KErrNoMemory; |
|
1653 } |
|
1654 |
|
1655 stream.next_in = (Bytef*)hello; |
|
1656 stream.next_out = compr; |
|
1657 stream.avail_in = (uInt)sourceLen; |
|
1658 stream.avail_out = (uInt)comprLen; |
|
1659 if ((uLong)stream.avail_out != comprLen) |
|
1660 { |
|
1661 res = KErrGeneral; |
|
1662 } |
|
1663 |
|
1664 stream.zalloc = (alloc_func)0; |
|
1665 stream.zfree = (free_func)0; |
|
1666 stream.opaque = (voidpf)0; |
|
1667 |
|
1668 err= deflateInit2_(&stream, level, 8, 15, 7, |
|
1669 0, zlibVersion(), sizeof(z_stream)); |
|
1670 |
|
1671 if (err == Z_OK) |
|
1672 { |
|
1673 int y= deflateBound(Z_NULL, sourceLen); |
|
1674 if(y > sourceLen) |
|
1675 { |
|
1676 res = KErrNone ; |
|
1677 } |
|
1678 else |
|
1679 { |
|
1680 res = KErrGeneral; |
|
1681 } |
|
1682 } |
|
1683 else |
|
1684 { |
|
1685 res = KErrGeneral; |
|
1686 return res; |
|
1687 } |
|
1688 |
|
1689 err=deflateEnd(&stream); |
|
1690 if (err != Z_OK) |
|
1691 { |
|
1692 res = KErrGeneral; |
|
1693 } |
|
1694 free(compr); |
|
1695 return res; |
|
1696 } |
|
1697 |
|
1698 /** |
|
1699 * Function Name : TestDeflateBoundStreamStateNull |
|
1700 * TestCase Description: Stream state is equated to Z_NULL |
|
1701 * and passed to deflatebound |
|
1702 */ |
|
1703 TInt CTestZlib::TestDeflateBoundStreamStateNull() |
|
1704 { |
|
1705 TInt res = KErrNone; |
|
1706 z_stream stream; |
|
1707 int err; |
|
1708 int level=Z_DEFAULT_COMPRESSION; |
|
1709 |
|
1710 uLong sourceLen = (uLong)strlen(hello)+1; |
|
1711 Byte *compr; |
|
1712 uLong comprLen = 20*sizeof(int); |
|
1713 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1714 if (compr == Z_NULL) |
|
1715 { |
|
1716 return KErrNoMemory; |
|
1717 } |
|
1718 |
|
1719 stream.next_in = (Bytef*)hello; |
|
1720 stream.next_out = compr; |
|
1721 stream.avail_in = (uInt)sourceLen; |
|
1722 stream.avail_out = (uInt)comprLen; |
|
1723 if ((uLong)stream.avail_out != comprLen) |
|
1724 { |
|
1725 res = KErrGeneral; |
|
1726 } |
|
1727 |
|
1728 stream.zalloc = (alloc_func)0; |
|
1729 stream.zfree = (free_func)0; |
|
1730 stream.opaque = (voidpf)0; |
|
1731 |
|
1732 err= deflateInit2_(&stream, level, 8, 15, 7, |
|
1733 0, zlibVersion(), sizeof(z_stream)); |
|
1734 |
|
1735 if (err == Z_OK) |
|
1736 { |
|
1737 //stream.state = Z_NULL; |
|
1738 int y= deflateBound(&stream, sourceLen); |
|
1739 if(y > sourceLen) |
|
1740 { |
|
1741 res = KErrNone ; |
|
1742 } |
|
1743 else |
|
1744 { |
|
1745 res = KErrGeneral; |
|
1746 } |
|
1747 err=deflateEnd(&stream); |
|
1748 if (err != Z_OK) |
|
1749 { |
|
1750 INFO_PRINTF1(_L("Error encountered in deflateEnd")); |
|
1751 free(compr); |
|
1752 return KErrNone; |
|
1753 } |
|
1754 |
|
1755 // for coverage improvement |
|
1756 stream.state = Z_NULL; |
|
1757 y = deflateBound(&stream, sourceLen); |
|
1758 } // end of if |
|
1759 else |
|
1760 { |
|
1761 res = KErrGeneral; |
|
1762 return res; |
|
1763 } |
|
1764 |
|
1765 free(compr); |
|
1766 return res; |
|
1767 } |
|
1768 |
|
1769 /** |
|
1770 * Function Name : TestDeflateSetDictionaryWrap |
|
1771 * TestCase Description: 1. Pass window bits > 15 to set the stream->wrap = 2 |
|
1772 * 2. Pass window bits < 0 to set the stream->wrap = 0 |
|
1773 * Return Value: Z_STREAM_ERROR |
|
1774 */ |
|
1775 TInt CTestZlib::TestDeflateSetDictionaryWrap() |
|
1776 { |
|
1777 int level=Z_DEFAULT_COMPRESSION; |
|
1778 int WindowBits = 0; |
|
1779 |
|
1780 Byte *comp; |
|
1781 uLong compLen; |
|
1782 compLen = 30; |
|
1783 comp = (Byte*)calloc((uInt)compLen, 1); |
|
1784 |
|
1785 ReadIntParam(WindowBits); |
|
1786 |
|
1787 z_stream stream; // compression stream |
|
1788 int err; |
|
1789 const char hello[] = "hello, hello!"; |
|
1790 uLong len = (uLong)strlen(hello)+1; |
|
1791 const Bytef* dictionary=(const Bytef *) hello; |
|
1792 stream.zalloc = (alloc_func)0; |
|
1793 stream.zfree = (free_func)0; |
|
1794 stream.opaque = (voidpf)0; |
|
1795 |
|
1796 err= deflateInit2_(&stream, level, 8, WindowBits, 8, 0, zlibVersion(), sizeof(z_stream)); |
|
1797 |
|
1798 if (err != Z_OK) |
|
1799 { |
|
1800 INFO_PRINTF2(_L("deflateInit error: %d"), err); |
|
1801 free(comp); |
|
1802 return err; |
|
1803 } |
|
1804 err = deflateSetDictionary(&stream,dictionary,3); |
|
1805 if(err == Z_STREAM_ERROR) |
|
1806 { |
|
1807 free(comp); |
|
1808 deflateEnd(&stream); |
|
1809 return KErrNone; |
|
1810 } |
|
1811 stream.next_in = (Bytef*)hello; |
|
1812 stream.next_out = comp; |
|
1813 |
|
1814 while (stream.total_in != len && stream.total_out < compLen) |
|
1815 { |
|
1816 stream.avail_in = stream.avail_out = 1; //* force small buffers |
|
1817 err = deflate(&stream, Z_NO_FLUSH); |
|
1818 if (err != Z_OK) |
|
1819 { |
|
1820 INFO_PRINTF2(_L("deflate return code: %d"), err); |
|
1821 deflateEnd(&stream); |
|
1822 free(comp); |
|
1823 return err; |
|
1824 } |
|
1825 } |
|
1826 // Finish the stream, still forcing small buffers: |
|
1827 for (;;) |
|
1828 { |
|
1829 stream.avail_out = 1; |
|
1830 err = deflate(&stream, Z_FINISH); |
|
1831 if (err == Z_STREAM_END) break; |
|
1832 if (err != Z_OK) |
|
1833 { |
|
1834 INFO_PRINTF2(_L("deflate error: %d"), err); |
|
1835 deflateEnd(&stream); |
|
1836 free(comp); |
|
1837 return err; |
|
1838 } |
|
1839 } |
|
1840 |
|
1841 deflateEnd(&stream); |
|
1842 free(comp); |
|
1843 return KErrNone; |
|
1844 |
|
1845 } |
|
1846 |
|
1847 /** |
|
1848 * Function Name : TestDeflateSetDictionaryLen |
|
1849 * TestCase Description: Supply dictLength > MAX_DIST(s) |
|
1850 * Return Value: Z_OK |
|
1851 */ |
|
1852 TInt CTestZlib::TestDeflateSetDictionaryLen() |
|
1853 { |
|
1854 int level=Z_DEFAULT_COMPRESSION; |
|
1855 |
|
1856 Byte *comp; |
|
1857 uLong compLen; |
|
1858 compLen = 30; |
|
1859 comp = (Byte*)calloc((uInt)compLen, 1); |
|
1860 |
|
1861 z_stream stream; // compression stream |
|
1862 int err; |
|
1863 const char hello[] = "hello, hello!"; |
|
1864 uLong len = (uLong)strlen(hello)+1; |
|
1865 const Bytef* dictionary=(const Bytef *) hello; |
|
1866 stream.zalloc = (alloc_func)0; |
|
1867 stream.zfree = (free_func)0; |
|
1868 stream.opaque = (voidpf)0; |
|
1869 |
|
1870 err= deflateInit2_(&stream, level, 8, 9, 8, 0, zlibVersion(), sizeof(z_stream)); |
|
1871 |
|
1872 if (err != Z_OK) |
|
1873 { |
|
1874 INFO_PRINTF2(_L("deflateInit error: %d"), err); |
|
1875 free(comp); |
|
1876 return err; |
|
1877 } |
|
1878 |
|
1879 // Pass dictLength=251 which is > MAX_DIST(s) for window bits=9 |
|
1880 err = deflateSetDictionary(&stream,dictionary,251); |
|
1881 if(err != Z_OK) |
|
1882 { |
|
1883 free(comp); |
|
1884 deflateEnd(&stream); |
|
1885 return err; |
|
1886 } |
|
1887 stream.next_in = (Bytef*)hello; |
|
1888 stream.next_out = comp; |
|
1889 |
|
1890 while (stream.total_in != len && stream.total_out < compLen) |
|
1891 { |
|
1892 stream.avail_in = stream.avail_out = 1; //* force small buffers |
|
1893 err = deflate(&stream, Z_NO_FLUSH); |
|
1894 if (err != Z_OK) |
|
1895 { |
|
1896 INFO_PRINTF2(_L("deflate return code: %d"), err); |
|
1897 deflateEnd(&stream); |
|
1898 free(comp); |
|
1899 return err; |
|
1900 } |
|
1901 } |
|
1902 // Finish the stream, still forcing small buffers: |
|
1903 for (;;) |
|
1904 { |
|
1905 stream.avail_out = 1; |
|
1906 err = deflate(&stream, Z_FINISH); |
|
1907 if (err == Z_STREAM_END) break; |
|
1908 if (err != Z_OK) |
|
1909 { |
|
1910 INFO_PRINTF2(_L("deflate error: %d"), err); |
|
1911 deflateEnd(&stream); |
|
1912 free(comp); |
|
1913 return err; |
|
1914 } |
|
1915 } |
|
1916 |
|
1917 deflateEnd(&stream); |
|
1918 free(comp); |
|
1919 return KErrNone; |
|
1920 |
|
1921 } |
|
1922 |
|
1923 /** |
|
1924 * Function Name : TestInflateSetDictionaryBadMode |
|
1925 * TestCase Description: Supply window bits=9 making state->mode = BAD |
|
1926 * Return Value: Z_STREAM_ERROR |
|
1927 */ |
|
1928 TInt CTestZlib::TestInflateSetDictionaryBadMode() |
|
1929 { |
|
1930 TInt res = KErrNone ; |
|
1931 Byte *compr, *uncompr; |
|
1932 uLong comprLen = 100*sizeof(int); |
|
1933 uLong uncomprLen = comprLen; |
|
1934 |
|
1935 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
1936 if (compr == Z_NULL) |
|
1937 { |
|
1938 return KErrNoMemory; |
|
1939 } |
|
1940 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
1941 if (uncompr == Z_NULL) |
|
1942 { |
|
1943 free(compr); |
|
1944 return KErrNoMemory; |
|
1945 } |
|
1946 res = Test_dict_deflate(compr, comprLen); |
|
1947 |
|
1948 if(res < 0) |
|
1949 { |
|
1950 free(compr); |
|
1951 free(uncompr); |
|
1952 return res; |
|
1953 } |
|
1954 if(res == 0) |
|
1955 { |
|
1956 |
|
1957 int err; |
|
1958 z_stream d_stream; // decompression stream |
|
1959 |
|
1960 strcpy((char*)uncompr, "garbage"); |
|
1961 |
|
1962 d_stream.zalloc = (alloc_func)0; |
|
1963 d_stream.zfree = (free_func)0; |
|
1964 d_stream.opaque = (voidpf)0; |
|
1965 |
|
1966 d_stream.next_in = compr; |
|
1967 d_stream.avail_in = (uInt)comprLen; |
|
1968 |
|
1969 err = inflateInit2_(&d_stream, 9, "1.2.4", sizeof(d_stream)); |
|
1970 if(err < 0 ) |
|
1971 { |
|
1972 free(compr); |
|
1973 free(uncompr); |
|
1974 return Z_MEM_ERROR; |
|
1975 } |
|
1976 |
|
1977 d_stream.next_out = uncompr; |
|
1978 d_stream.avail_out = (uInt)uncomprLen; |
|
1979 |
|
1980 for (;;) |
|
1981 { |
|
1982 err = inflate(&d_stream, Z_NO_FLUSH); |
|
1983 err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,sizeof(dictionary)); |
|
1984 if(err == Z_STREAM_ERROR) |
|
1985 { |
|
1986 res = KErrNone; |
|
1987 break; |
|
1988 } |
|
1989 } // end of for |
|
1990 |
|
1991 err = inflateEnd(&d_stream); |
|
1992 } // end of outer if |
|
1993 else |
|
1994 { |
|
1995 res=KErrGeneral; |
|
1996 } |
|
1997 |
|
1998 free(compr); |
|
1999 free(uncompr); |
|
2000 return res; |
|
2001 } |
|
2002 |
|
2003 /** |
|
2004 * Function Name : TestInflateSetDictionaryStreamStateNull |
|
2005 * TestCase Description: Make stream->state = Z_NULL |
|
2006 * Return Value: Z_STREAM_ERROR |
|
2007 */ |
|
2008 TInt CTestZlib::TestInflateSetDictionaryStreamStateNull() |
|
2009 { |
|
2010 TInt res = KErrNone ; |
|
2011 Byte *compr, *uncompr; |
|
2012 uLong comprLen = 100*sizeof(int); |
|
2013 uLong uncomprLen = comprLen; |
|
2014 |
|
2015 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
2016 if (compr == Z_NULL) |
|
2017 { |
|
2018 return KErrNoMemory; |
|
2019 } |
|
2020 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
2021 if (uncompr == Z_NULL) |
|
2022 { |
|
2023 free(compr); |
|
2024 return KErrNoMemory; |
|
2025 } |
|
2026 res = Test_dict_deflate(compr, comprLen); |
|
2027 |
|
2028 if(res < 0) |
|
2029 { |
|
2030 free(compr); |
|
2031 free(uncompr); |
|
2032 return res; |
|
2033 } |
|
2034 if(res == 0) |
|
2035 { |
|
2036 |
|
2037 int err; |
|
2038 z_stream d_stream; // decompression stream |
|
2039 |
|
2040 strcpy((char*)uncompr, "garbage"); |
|
2041 |
|
2042 d_stream.zalloc = (alloc_func)0; |
|
2043 d_stream.zfree = (free_func)0; |
|
2044 d_stream.opaque = (voidpf)0; |
|
2045 |
|
2046 d_stream.next_in = compr; |
|
2047 d_stream.avail_in = (uInt)comprLen; |
|
2048 |
|
2049 err = inflateInit2_(&d_stream, 15, "1.2.4", sizeof(d_stream)); |
|
2050 if(err < 0 ) |
|
2051 { |
|
2052 free(compr); |
|
2053 free(uncompr); |
|
2054 return Z_MEM_ERROR; |
|
2055 } |
|
2056 |
|
2057 d_stream.next_out = uncompr; |
|
2058 d_stream.avail_out = (uInt)uncomprLen; |
|
2059 |
|
2060 for (;;) |
|
2061 { |
|
2062 err = inflate(&d_stream, Z_NO_FLUSH); |
|
2063 if (err < Z_OK) |
|
2064 { |
|
2065 INFO_PRINTF1(_L("Inflate failed")); |
|
2066 res = KErrGeneral; |
|
2067 break; |
|
2068 } |
|
2069 err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,sizeof(dictionary)); |
|
2070 if(err == Z_STREAM_ERROR) |
|
2071 { |
|
2072 res = KErrNone; |
|
2073 break; |
|
2074 } |
|
2075 } |
|
2076 err = inflateEnd(&d_stream); |
|
2077 |
|
2078 //for coverage improvement |
|
2079 d_stream.state = Z_NULL; |
|
2080 err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,sizeof(dictionary)); |
|
2081 if(err == Z_STREAM_ERROR) |
|
2082 { |
|
2083 res = KErrNone; |
|
2084 } |
|
2085 } // end of outer if |
|
2086 else |
|
2087 { |
|
2088 res=KErrGeneral; |
|
2089 } |
|
2090 |
|
2091 free(compr); |
|
2092 free(uncompr); |
|
2093 return res; |
|
2094 } |
|
2095 |
|
2096 /** |
|
2097 * Function Name : TestDeflateParamsStreamStateNull |
|
2098 * TestCase Description: Make stream state Z_NULL |
|
2099 * Return Value: Z_STREAM_ERROR |
|
2100 */ |
|
2101 TInt CTestZlib::TestDeflateParamsStreamStateNull() |
|
2102 { |
|
2103 TInt res = KErrNone ; |
|
2104 z_stream c_stream; // compression stream |
|
2105 int err; |
|
2106 Byte * compr; |
|
2107 |
|
2108 uLong comprLen = 20*sizeof(int); |
|
2109 |
|
2110 compr=(Byte*)calloc((uInt)comprLen, 1); |
|
2111 if (compr == Z_NULL) |
|
2112 { |
|
2113 return KErrNoMemory; |
|
2114 } |
|
2115 |
|
2116 uLong len = (uLong)strlen(hello)+1; |
|
2117 |
|
2118 c_stream.zalloc = (alloc_func)0; |
|
2119 c_stream.zfree = (free_func)0; |
|
2120 c_stream.opaque = (voidpf)0; |
|
2121 |
|
2122 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); |
|
2123 if(err <0) |
|
2124 { |
|
2125 free(compr); |
|
2126 return err; |
|
2127 } |
|
2128 |
|
2129 c_stream.next_in = (Bytef*)hello; |
|
2130 c_stream.next_out = compr; |
|
2131 |
|
2132 err= deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY); |
|
2133 deflateEnd(&c_stream); |
|
2134 |
|
2135 // Equate the stream state to Z_NULL for coverage improvement |
|
2136 c_stream.state = Z_NULL; |
|
2137 err= deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY); |
|
2138 |
|
2139 if(err == Z_STREAM_ERROR) |
|
2140 { |
|
2141 res=KErrNone; |
|
2142 } |
|
2143 else |
|
2144 { |
|
2145 res=KErrGeneral; |
|
2146 } |
|
2147 |
|
2148 free(compr); |
|
2149 return res; |
|
2150 } |
|
2151 |
|
2152 /** |
|
2153 * Function Name : TestInflateSyncAvailInNull |
|
2154 * TestCase Description: Make avail in Z_NULL |
|
2155 * Return Value: Z_BUF_ERROR |
|
2156 */ |
|
2157 TInt CTestZlib::TestInflateSyncAvailInNull() |
|
2158 { |
|
2159 TInt res = KErrNone ; |
|
2160 uLong len = (uLong)strlen(hello)+1; |
|
2161 |
|
2162 Byte *compr, *uncompr; |
|
2163 uLong comprLen = 20*sizeof(int); |
|
2164 uLong uncomprLen = comprLen; |
|
2165 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
2166 if (compr == Z_NULL) |
|
2167 { |
|
2168 return KErrNoMemory; |
|
2169 } |
|
2170 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
2171 if (uncompr == Z_NULL) |
|
2172 { |
|
2173 free(compr); |
|
2174 return KErrNoMemory; |
|
2175 } |
|
2176 |
|
2177 int err; |
|
2178 err = compress(compr, &comprLen, (const Bytef*)hello, len); |
|
2179 if(err < 0) |
|
2180 { |
|
2181 res = KErrNoMemory; |
|
2182 } |
|
2183 else if(err == 0) |
|
2184 { |
|
2185 res = KErrNone ; |
|
2186 } |
|
2187 else |
|
2188 { |
|
2189 res = KErrGeneral; |
|
2190 } |
|
2191 |
|
2192 if(res<0) |
|
2193 { |
|
2194 free(compr); |
|
2195 free(uncompr); |
|
2196 return KErrNoMemory; |
|
2197 } |
|
2198 |
|
2199 Test_flush(compr, &comprLen); |
|
2200 |
|
2201 z_stream d_stream; /* decompression stream */ |
|
2202 |
|
2203 strcpy((char*)uncompr, "garbage"); |
|
2204 |
|
2205 d_stream.zalloc = (alloc_func)0; |
|
2206 d_stream.zfree = (free_func)0; |
|
2207 d_stream.opaque = (voidpf)0; |
|
2208 |
|
2209 d_stream.next_in = compr; |
|
2210 d_stream.avail_in = 2; /* just read the zlib header */ |
|
2211 |
|
2212 err = inflateInit(&d_stream); |
|
2213 if(err!=0) |
|
2214 { |
|
2215 res=KErrGeneral; |
|
2216 } |
|
2217 |
|
2218 |
|
2219 d_stream.next_out = uncompr; |
|
2220 d_stream.avail_out = (uInt)uncomprLen; |
|
2221 |
|
2222 err=inflate(&d_stream, Z_NO_FLUSH); |
|
2223 if(err!=0) |
|
2224 { |
|
2225 res=KErrGeneral; |
|
2226 } |
|
2227 |
|
2228 // Make avail_in Z_NULL |
|
2229 d_stream.avail_in = Z_NULL; |
|
2230 err = inflateSync(&d_stream); /* but skip the damaged part */ |
|
2231 if(err == Z_BUF_ERROR) |
|
2232 { |
|
2233 res=KErrNone; |
|
2234 } |
|
2235 |
|
2236 free(compr); |
|
2237 free(uncompr); |
|
2238 err = inflateEnd(&d_stream); |
|
2239 if(Z_OK != err) |
|
2240 { |
|
2241 INFO_PRINTF1(_L("Error encountered in inflateEnd")); |
|
2242 return KErrGeneral; |
|
2243 } |
|
2244 return res; |
|
2245 } |
|
2246 |
|
2247 /** |
|
2248 * Function Name : TestInflateSyncStreamNull |
|
2249 * TestCase Description: Pass NULL stream to InflateSync |
|
2250 * Return Value: Z_STREAM_ERROR |
|
2251 */ |
|
2252 TInt CTestZlib::TestInflateSyncStreamNull() |
|
2253 { |
|
2254 TInt res = KErrNone ; |
|
2255 uLong len = (uLong)strlen(hello)+1; |
|
2256 |
|
2257 Byte *compr, *uncompr; |
|
2258 uLong comprLen = 20*sizeof(int); |
|
2259 uLong uncomprLen = comprLen; |
|
2260 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
2261 if (compr == Z_NULL) |
|
2262 { |
|
2263 return KErrNoMemory; |
|
2264 } |
|
2265 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
2266 if (uncompr == Z_NULL) |
|
2267 { |
|
2268 free(compr); |
|
2269 return KErrNoMemory; |
|
2270 } |
|
2271 |
|
2272 int err; |
|
2273 err = compress(compr, &comprLen, (const Bytef*)hello, len); |
|
2274 if(err < 0) |
|
2275 { |
|
2276 res = KErrNoMemory; |
|
2277 } |
|
2278 else if(err == 0) |
|
2279 { |
|
2280 res = KErrNone ; |
|
2281 } |
|
2282 else |
|
2283 { |
|
2284 res = KErrGeneral; |
|
2285 } |
|
2286 |
|
2287 if(res<0) |
|
2288 { |
|
2289 free(compr); |
|
2290 free(uncompr); |
|
2291 return KErrNoMemory; |
|
2292 } |
|
2293 |
|
2294 Test_flush(compr, &comprLen); |
|
2295 |
|
2296 z_stream d_stream; /* decompression stream */ |
|
2297 |
|
2298 strcpy((char*)uncompr, "garbage"); |
|
2299 |
|
2300 d_stream.zalloc = (alloc_func)0; |
|
2301 d_stream.zfree = (free_func)0; |
|
2302 d_stream.opaque = (voidpf)0; |
|
2303 |
|
2304 d_stream.next_in = compr; |
|
2305 d_stream.avail_in = 2; /* just read the zlib header */ |
|
2306 |
|
2307 err = inflateInit(&d_stream); |
|
2308 if(err!=0) |
|
2309 { |
|
2310 res=KErrGeneral; |
|
2311 } |
|
2312 |
|
2313 d_stream.next_out = uncompr; |
|
2314 d_stream.avail_out = (uInt)uncomprLen; |
|
2315 |
|
2316 err=inflate(&d_stream, Z_NO_FLUSH); |
|
2317 if(err!=0) |
|
2318 { |
|
2319 res=KErrGeneral; |
|
2320 } |
|
2321 |
|
2322 d_stream.avail_in = (uInt)comprLen-2; |
|
2323 |
|
2324 // Make stream Z_NULL |
|
2325 err = inflateSync(Z_NULL); |
|
2326 if(err == Z_STREAM_ERROR) |
|
2327 { |
|
2328 res=KErrNone; |
|
2329 } |
|
2330 err = inflateEnd(&d_stream); |
|
2331 if(Z_OK != err) |
|
2332 { |
|
2333 INFO_PRINTF1(_L("Error encountered in inflateEnd")); |
|
2334 return KErrGeneral; |
|
2335 } |
|
2336 free(compr); |
|
2337 free(uncompr); |
|
2338 return res; |
|
2339 } |
|
2340 |
|
2341 /** |
|
2342 * Function Name : TestInflateSyncStreamStateNull |
|
2343 * TestCase Description: Make stream state = Z_NULL |
|
2344 * Return Value: Z_STREAM_ERROR |
|
2345 */ |
|
2346 TInt CTestZlib::TestInflateSyncStreamStateNull() |
|
2347 { |
|
2348 TInt res = KErrNone ; |
|
2349 uLong len = (uLong)strlen(hello)+1; |
|
2350 |
|
2351 Byte *compr, *uncompr; |
|
2352 uLong comprLen = 20*sizeof(int); |
|
2353 uLong uncomprLen = comprLen; |
|
2354 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
2355 if (compr == Z_NULL) |
|
2356 { |
|
2357 return KErrNoMemory; |
|
2358 } |
|
2359 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
2360 if (uncompr == Z_NULL) |
|
2361 { |
|
2362 free(compr); |
|
2363 return KErrNoMemory; |
|
2364 } |
|
2365 |
|
2366 int err; |
|
2367 err = compress(compr, &comprLen, (const Bytef*)hello, len); |
|
2368 if(err < 0) |
|
2369 { |
|
2370 res = KErrNoMemory; |
|
2371 } |
|
2372 else if(err == 0) |
|
2373 { |
|
2374 res = KErrNone ; |
|
2375 } |
|
2376 else |
|
2377 { |
|
2378 res = KErrGeneral; |
|
2379 } |
|
2380 |
|
2381 if(res<0) |
|
2382 { |
|
2383 free(compr); |
|
2384 free(uncompr); |
|
2385 return KErrNoMemory; |
|
2386 } |
|
2387 |
|
2388 Test_flush(compr, &comprLen); |
|
2389 |
|
2390 z_stream d_stream; /* decompression stream */ |
|
2391 |
|
2392 strcpy((char*)uncompr, "garbage"); |
|
2393 |
|
2394 d_stream.zalloc = (alloc_func)0; |
|
2395 d_stream.zfree = (free_func)0; |
|
2396 d_stream.opaque = (voidpf)0; |
|
2397 |
|
2398 d_stream.next_in = compr; |
|
2399 d_stream.avail_in = 2; /* just read the zlib header */ |
|
2400 |
|
2401 err = inflateInit(&d_stream); |
|
2402 if(err!=0) |
|
2403 { |
|
2404 res=KErrGeneral; |
|
2405 } |
|
2406 d_stream.next_out = uncompr; |
|
2407 d_stream.avail_out = (uInt)uncomprLen; |
|
2408 err=inflate(&d_stream, Z_NO_FLUSH); |
|
2409 if(err!=0) |
|
2410 { |
|
2411 res=KErrGeneral; |
|
2412 } |
|
2413 |
|
2414 d_stream.avail_in = (uInt)comprLen-2; |
|
2415 err = inflateSync(&d_stream); |
|
2416 err = inflateEnd(&d_stream); |
|
2417 if(Z_OK != err) |
|
2418 { |
|
2419 INFO_PRINTF1(_L("Error encountered in inflateEnd")); |
|
2420 return KErrGeneral; |
|
2421 } |
|
2422 |
|
2423 // for coverage improvement |
|
2424 d_stream.state = Z_NULL; |
|
2425 err = inflateSync(&d_stream); |
|
2426 |
|
2427 if(err == Z_STREAM_ERROR) |
|
2428 { |
|
2429 res=KErrNone; |
|
2430 } |
|
2431 free(compr); |
|
2432 free(uncompr); |
|
2433 return res; |
|
2434 } |
|
2435 |
|
2436 /** |
|
2437 * Function Name : TestInflateSyncPointStreamStateNull |
|
2438 * TestCase Description: Make stream state = Z_NULL |
|
2439 * Return Value: Z_STREAM_ERROR |
|
2440 */ |
|
2441 TInt CTestZlib::TestInflateSyncPointStreamStateNull() |
|
2442 { |
|
2443 TInt res = KErrNone ; |
|
2444 uLong len = (uLong)strlen(hello)+1; |
|
2445 |
|
2446 Byte *compr, *uncompr; |
|
2447 uLong comprLen = 20*sizeof(int); |
|
2448 uLong uncomprLen = comprLen; |
|
2449 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
2450 if (compr == Z_NULL) |
|
2451 { |
|
2452 return KErrNoMemory; |
|
2453 } |
|
2454 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
2455 if (uncompr == Z_NULL) |
|
2456 { |
|
2457 free(compr); |
|
2458 return KErrNoMemory; |
|
2459 } |
|
2460 |
|
2461 z_stream stream; |
|
2462 int err; |
|
2463 |
|
2464 stream.next_in = (Bytef*)hello; |
|
2465 stream.avail_in = (uInt)len; |
|
2466 |
|
2467 stream.next_out = compr; |
|
2468 stream.avail_out = (uInt)comprLen; |
|
2469 |
|
2470 stream.zalloc = (alloc_func)0; |
|
2471 stream.zfree = (free_func)0; |
|
2472 stream.opaque = (voidpf)0; |
|
2473 |
|
2474 err = deflateInit(&stream, Z_DEFAULT_COMPRESSION); |
|
2475 if (err != Z_OK) |
|
2476 { |
|
2477 free(compr); |
|
2478 free(uncompr); |
|
2479 return err; |
|
2480 } |
|
2481 |
|
2482 err = deflate(&stream, Z_FINISH); |
|
2483 if (err != Z_STREAM_END) |
|
2484 { |
|
2485 deflateEnd(&stream); |
|
2486 free(compr); |
|
2487 free(uncompr); |
|
2488 return err == Z_OK ? Z_BUF_ERROR : err; |
|
2489 } |
|
2490 comprLen = stream.total_out; |
|
2491 |
|
2492 err = inflateSyncPoint(&stream); |
|
2493 err = deflateEnd(&stream); |
|
2494 if(err == Z_STREAM_ERROR) |
|
2495 { |
|
2496 INFO_PRINTF1(_L("Error encountered in inflateEnd")); |
|
2497 free(compr); |
|
2498 free(uncompr); |
|
2499 return KErrNone; |
|
2500 } |
|
2501 |
|
2502 //Make stream state NULL |
|
2503 stream.state = Z_NULL; |
|
2504 err = inflateSyncPoint(&stream); |
|
2505 //err = inflateEnd(&stream); |
|
2506 if(err == Z_STREAM_ERROR) |
|
2507 { |
|
2508 res=KErrNone; |
|
2509 } |
|
2510 |
|
2511 free(compr); |
|
2512 free(uncompr); |
|
2513 return res; |
|
2514 } |
|
2515 |
|
2516 |
|
2517 /** |
|
2518 * Function Name : TestAdlerScenarios |
|
2519 * TestCase Description: 1. len = 1, adler > BASE |
|
2520 * 2. len < 16, adler > BASE |
|
2521 * 3. len > NMAX |
|
2522 * Return Value: Adler value |
|
2523 */ |
|
2524 TInt CTestZlib::TestAdlerScenarios() |
|
2525 { |
|
2526 TInt res = KErrNone ; |
|
2527 //unsigned char buffer[5]="1234"; |
|
2528 unsigned char buffer[5552]; |
|
2529 int len=0; |
|
2530 int adler1=0; |
|
2531 |
|
2532 _LIT(KParam1, "Param1"); |
|
2533 TBool ret = GetIntFromConfig(ConfigSection(), KParam1, adler1); |
|
2534 if(!ret) |
|
2535 { |
|
2536 INFO_PRINTF1(_L("Failed to read the values from ini file")); |
|
2537 } |
|
2538 |
|
2539 _LIT(KParam2, "Param2"); |
|
2540 ret = GetIntFromConfig(ConfigSection(), KParam2, len); |
|
2541 if(!ret) |
|
2542 { |
|
2543 INFO_PRINTF1(_L("Failed to read the values from ini file")); |
|
2544 } |
|
2545 |
|
2546 long long adler = adler32((long)adler1, &buffer[0], (unsigned int)len); |
|
2547 INFO_PRINTF2(_L("buf %x"),adler); |
|
2548 |
|
2549 if(adler > 0) |
|
2550 { |
|
2551 res=KErrNone ; |
|
2552 } |
|
2553 else |
|
2554 { |
|
2555 res = KErrGeneral; |
|
2556 } |
|
2557 return res; |
|
2558 } |
|
2559 |
|
2560 /** |
|
2561 * Function Name : TestGzsetparamsFileNull |
|
2562 * TestCase Description: Pass NULL pointer to gzsetparams |
|
2563 * Return Value: Z_STREAM_ERROR |
|
2564 */ |
|
2565 TInt CTestZlib::TestGzsetparamsFileNull() |
|
2566 { |
|
2567 TInt res = KErrNone ; |
|
2568 |
|
2569 int len = (int)strlen(hello)+1; |
|
2570 gzFile file; |
|
2571 |
|
2572 const char * fname = TESTFILE; |
|
2573 |
|
2574 file = gzopen(fname, "wb"); |
|
2575 gzputc(file, 'h'); |
|
2576 |
|
2577 int err = gzsetparams(NULL, Z_BEST_SPEED, Z_DEFAULT_STRATEGY); |
|
2578 if(err == Z_STREAM_ERROR) |
|
2579 { |
|
2580 gzclose(file); |
|
2581 res = KErrNone; |
|
2582 } |
|
2583 |
|
2584 return res; |
|
2585 } |
|
2586 |
|
2587 /** |
|
2588 * Function Name : TestGzopenWrite |
|
2589 * TestCase Description: Open a gz file in write mode, close it and |
|
2590 * and then open again in read mode |
|
2591 */ |
|
2592 TInt CTestZlib::TestGzopenWrite() |
|
2593 { |
|
2594 gzFile file; |
|
2595 const char * fname = "c:\\file.txt"; |
|
2596 file = gzopen(fname, "wb"); |
|
2597 |
|
2598 gzputs(file, "Coverage Improvement"); |
|
2599 |
|
2600 gzclose(file); |
|
2601 |
|
2602 file = gzopen(fname, "rb"); |
|
2603 |
|
2604 if (file == NULL) |
|
2605 { |
|
2606 ERR_PRINTF1(_L("gzopen error")); |
|
2607 return KErrGeneral; |
|
2608 } |
|
2609 |
|
2610 gzclose(file); |
|
2611 |
|
2612 return KErrNone; |
|
2613 } |
|
2614 |
|
2615 /** |
|
2616 * Function Name : TestGzreadLargeFile |
|
2617 * TestCase Description: Open a large gz file in read mode and read from it |
|
2618 */ |
|
2619 TInt CTestZlib::TestGzreadLargeFile() |
|
2620 { |
|
2621 gzFile file; |
|
2622 const char *s="\0"; |
|
2623 uInt len = strlen(s); |
|
2624 |
|
2625 char *buf1 = (char*)malloc(1024); |
|
2626 if (buf1 == Z_NULL) |
|
2627 { |
|
2628 return KErrNoMemory; |
|
2629 } |
|
2630 |
|
2631 file = gzopen(FILETESTGZLARGE, "rb"); |
|
2632 if (file == NULL) |
|
2633 { |
|
2634 ERR_PRINTF1(_L("gzopen error")); |
|
2635 free(buf1); |
|
2636 return KErrGeneral; |
|
2637 } |
|
2638 |
|
2639 for (;;) |
|
2640 { |
|
2641 len = gzread(file, buf1, sizeof(buf1)); |
|
2642 if(len<=0) break; |
|
2643 } |
|
2644 |
|
2645 gzclose(file); |
|
2646 free(buf1); |
|
2647 return KErrNone; |
|
2648 } |
|
2649 |
|
2650 /** |
|
2651 * Function Name : TestGzopenWriteNoPath |
|
2652 * TestCase Description: Open a gz file in write mode, |
|
2653 * close it and then open again in read mode |
|
2654 */ |
|
2655 TInt CTestZlib::TestGzopenWriteNoPath() |
|
2656 { |
|
2657 gzFile file; |
|
2658 const char * fname = "c:\\file.txt"; |
|
2659 file = gzopen(fname, "wb"); |
|
2660 |
|
2661 gzputs(file, "Coverage Improvement"); |
|
2662 |
|
2663 gzclose(file); |
|
2664 |
|
2665 file = gzopen(fname, "rb"); |
|
2666 |
|
2667 if (file == NULL) |
|
2668 { |
|
2669 ERR_PRINTF1(_L("gzopen error")); |
|
2670 return KErrGeneral; |
|
2671 } |
|
2672 |
|
2673 gzclose(file); |
|
2674 return KErrNone; |
|
2675 } |
|
2676 /** |
|
2677 * Function Name : TestGzreadLenZero |
|
2678 * TestCase Description: 1. Read from a gz file specifying read buffer length=0 |
|
2679 */ |
|
2680 TInt CTestZlib::TestGzreadLenZero() |
|
2681 { |
|
2682 char * buf1 = (char*)malloc(1024); |
|
2683 if (buf1 == Z_NULL) |
|
2684 { |
|
2685 ERR_PRINTF1(_L("Heap out of memory")); |
|
2686 return KErrNoMemory; |
|
2687 } |
|
2688 |
|
2689 TInt res = KErrNone ; |
|
2690 gzFile file; |
|
2691 uInt len=0; |
|
2692 const char * fname = "c:\\file.txt"; |
|
2693 |
|
2694 // Write some text in gz file and close it |
|
2695 file = gzopen(fname, "wb"); |
|
2696 if (file == NULL) |
|
2697 { |
|
2698 free(buf1); |
|
2699 ERR_PRINTF1(_L("Could not open the file")); |
|
2700 res = KErrGeneral; |
|
2701 return res; |
|
2702 } |
|
2703 gzputs(file, "Coverage Improvement"); |
|
2704 gzclose(file); |
|
2705 |
|
2706 file = gzopen(fname, "rb"); |
|
2707 if (file == NULL) |
|
2708 { |
|
2709 free(buf1); |
|
2710 ERR_PRINTF1(_L("Could not open the file")); |
|
2711 res = KErrGeneral; |
|
2712 return res; |
|
2713 } |
|
2714 |
|
2715 for (;;) |
|
2716 { |
|
2717 len = gzread(file, buf1, len); |
|
2718 if(len<=0) break; |
|
2719 } |
|
2720 |
|
2721 if (gzclose(file) != Z_OK) |
|
2722 { |
|
2723 ERR_PRINTF1(_L("Could not close the file")); |
|
2724 res=KErrGeneral; |
|
2725 } |
|
2726 free(buf1); |
|
2727 return res; |
|
2728 } |
|
2729 |
|
2730 |
|
2731 /** |
|
2732 * Function Name : TestGzreadBufZero |
|
2733 * TestCase Description: 1. Read from a gz file passing a NULL for read buffer |
|
2734 */ |
|
2735 TInt CTestZlib::TestGzreadBufZero() |
|
2736 { |
|
2737 char * buf1 = (char*)malloc(1024); |
|
2738 if (buf1 == Z_NULL) |
|
2739 { |
|
2740 ERR_PRINTF1(_L("Heap out of memory")); |
|
2741 return KErrNoMemory; |
|
2742 } |
|
2743 |
|
2744 TInt res = KErrNone ; |
|
2745 gzFile file; |
|
2746 uInt len=0; |
|
2747 const char * fname = "c:\\file.txt"; |
|
2748 |
|
2749 // Write some text in gz file and close it |
|
2750 file = gzopen(fname, "wb"); |
|
2751 if (file == NULL) |
|
2752 { |
|
2753 free(buf1); |
|
2754 ERR_PRINTF1(_L("Could not open the file")); |
|
2755 res = KErrGeneral; |
|
2756 return res; |
|
2757 } |
|
2758 gzputs(file, "Coverage Improvement"); |
|
2759 gzclose(file); |
|
2760 |
|
2761 file = gzopen(fname, "rb"); |
|
2762 if (file == NULL) |
|
2763 { |
|
2764 free(buf1); |
|
2765 ERR_PRINTF1(_L("Could not open the file")); |
|
2766 res = KErrGeneral; |
|
2767 return res; |
|
2768 } |
|
2769 |
|
2770 for (;;) |
|
2771 { |
|
2772 len = gzread(file, NULL, sizeof(buf1)); |
|
2773 if(len<=0) break; |
|
2774 } |
|
2775 |
|
2776 if (gzclose(file) == Z_STREAM_ERROR) |
|
2777 { |
|
2778 res=KErrNone; |
|
2779 } |
|
2780 free(buf1); |
|
2781 return res; |
|
2782 |
|
2783 } |
|
2784 |
|
2785 /** |
|
2786 * Function Name : TestGzreadNonGzFile |
|
2787 * TestCase Description: 1. Read from a non gz file |
|
2788 */ |
|
2789 TInt CTestZlib::TestGzreadNonGzFile() |
|
2790 { |
|
2791 char *buf1 = (char*)malloc(1024); |
|
2792 if (buf1 == Z_NULL) |
|
2793 { |
|
2794 ERR_PRINTF1(_L("Heap out of memory")); |
|
2795 return KErrNoMemory; |
|
2796 } |
|
2797 |
|
2798 TInt res = KErrNone ; |
|
2799 gzFile file; |
|
2800 uInt len=0; |
|
2801 const char * fname = "c:\\file.txt"; |
|
2802 |
|
2803 // Write in txt file and close it |
|
2804 FILE *fp = fopen(fname,"w"); |
|
2805 if(fp == NULL) |
|
2806 { |
|
2807 free(buf1); |
|
2808 ERR_PRINTF1(_L("Could not open the output file.")); |
|
2809 res = KErrGeneral; |
|
2810 return res; |
|
2811 } |
|
2812 |
|
2813 fputc('\n',fp); |
|
2814 fclose(fp); |
|
2815 |
|
2816 file = gzopen(fname, "rb"); |
|
2817 if (file == NULL) |
|
2818 { |
|
2819 free(buf1); |
|
2820 ERR_PRINTF1(_L("Could not open the file")); |
|
2821 res = KErrGeneral; |
|
2822 return res; |
|
2823 } |
|
2824 |
|
2825 for (;;) |
|
2826 { |
|
2827 len = gzread(file, buf1, sizeof(buf1)); |
|
2828 if(len<=0) break; |
|
2829 } |
|
2830 |
|
2831 if (gzclose(file) == Z_STREAM_ERROR) |
|
2832 { |
|
2833 res=KErrNone; |
|
2834 } |
|
2835 free(buf1); |
|
2836 return res; |
|
2837 } |
|
2838 |
|
2839 /** |
|
2840 * Function Name : TestGzrewindNonGzFile |
|
2841 * TestCase Description: 1. Rewind in a non gz file |
|
2842 */ |
|
2843 TInt CTestZlib::TestGzrewindNonGzFile() |
|
2844 { |
|
2845 TInt res = KErrNone ; |
|
2846 int err; |
|
2847 int len = (int)strlen(hello)+1; |
|
2848 gzFile file; |
|
2849 const char * fname = "c:\\file.txt"; |
|
2850 |
|
2851 FILE *fp=NULL; |
|
2852 fp=fopen(fname,"w"); |
|
2853 fputc('\n',fp); |
|
2854 fclose(fp); |
|
2855 |
|
2856 file = gzopen(fname, "rb"); |
|
2857 if (file == NULL) |
|
2858 { |
|
2859 res = KErrGeneral; |
|
2860 } |
|
2861 err = gzrewind(file); |
|
2862 |
|
2863 if(err == 0) |
|
2864 { |
|
2865 res = KErrNone ; |
|
2866 } |
|
2867 else |
|
2868 { |
|
2869 res = KErrGeneral; |
|
2870 } |
|
2871 err= gzclose(file); |
|
2872 if (err != Z_OK) |
|
2873 { |
|
2874 res = KErrGeneral; |
|
2875 } |
|
2876 |
|
2877 return res; |
|
2878 } |
|
2879 |
|
2880 /** |
|
2881 * Function Name : TestGzrewindFileNull |
|
2882 * TestCase Description: Pass NULL to gzrewind |
|
2883 */ |
|
2884 TInt CTestZlib::TestGzrewindFileNull() |
|
2885 { |
|
2886 TInt res = KErrNone ; |
|
2887 int err; |
|
2888 int len = (int)strlen(hello)+1; |
|
2889 gzFile file; |
|
2890 |
|
2891 const char * fname = TESTFILE; |
|
2892 file = gzopen(fname, "rb"); |
|
2893 if (file == NULL) |
|
2894 { |
|
2895 res = KErrGeneral; |
|
2896 } |
|
2897 err = gzrewind(NULL); |
|
2898 |
|
2899 if(err == Z_ERRNO) |
|
2900 { |
|
2901 res = KErrNone ; |
|
2902 } |
|
2903 else |
|
2904 { |
|
2905 res = KErrGeneral; |
|
2906 } |
|
2907 err= gzclose(file); |
|
2908 if (err != Z_OK) |
|
2909 { |
|
2910 res = KErrGeneral; |
|
2911 } |
|
2912 |
|
2913 return res; |
|
2914 } |
|
2915 |
|
2916 /** |
|
2917 * Function Name : TestGzflushWithZFinish |
|
2918 * TestCase Description: Flush with flush = Z_FINISH |
|
2919 */ |
|
2920 TInt CTestZlib::TestGzflushWithZFinish() |
|
2921 { |
|
2922 TInt res = KErrNone ; |
|
2923 gzFile file; |
|
2924 |
|
2925 const char * fname = TESTFILE ; |
|
2926 file = gzopen(fname, "wb"); |
|
2927 if (file == Z_NULL) |
|
2928 { |
|
2929 res = KErrNoMemory; |
|
2930 return res; |
|
2931 } |
|
2932 int l= gzflush(file,Z_FINISH); |
|
2933 if(l != Z_OK) |
|
2934 { |
|
2935 res = KErrGeneral; |
|
2936 } |
|
2937 |
|
2938 l = gzclose(file); |
|
2939 if (l != Z_OK) |
|
2940 { |
|
2941 res = KErrGeneral; |
|
2942 } |
|
2943 return res; |
|
2944 } |
|
2945 |
|
2946 /** |
|
2947 * Function Name : TestUncompressLenSmall |
|
2948 * TestCase Description: Supply uncompress length smaller than compress length |
|
2949 * Return value: Z_BUF_ERROR |
|
2950 */ |
|
2951 TInt CTestZlib::TestUncompressLenSmall() |
|
2952 { |
|
2953 TInt res = KErrNone; |
|
2954 TInt err=0; |
|
2955 Byte *compr, *uncompr; |
|
2956 uLong len = (uLong)strlen(hello)+1; |
|
2957 |
|
2958 uLong comprLen = 20*sizeof(int); |
|
2959 uLong uncomprLen = 3*sizeof(int); |
|
2960 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
2961 if (compr == Z_NULL) |
|
2962 { |
|
2963 return KErrNoMemory; |
|
2964 } |
|
2965 |
|
2966 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
2967 if (uncompr == Z_NULL) |
|
2968 { |
|
2969 free(compr); |
|
2970 return KErrNoMemory; |
|
2971 } |
|
2972 |
|
2973 err = compress(compr, &comprLen, (const Bytef*)hello, len); |
|
2974 if(err == 0) |
|
2975 { |
|
2976 strcpy((char*)uncompr, "garbage"); |
|
2977 err = uncompress(uncompr, &uncomprLen, compr, comprLen); |
|
2978 if(err == Z_BUF_ERROR) |
|
2979 { |
|
2980 res = KErrNone ; |
|
2981 } |
|
2982 else |
|
2983 { |
|
2984 res = KErrGeneral; |
|
2985 } |
|
2986 } |
|
2987 |
|
2988 free(compr); |
|
2989 free(uncompr); |
|
2990 return res; |
|
2991 } |
|
2992 |
|
2993 /** |
|
2994 * Function Name : TestUncompressBufNull |
|
2995 * TestCase Description: Supply NULL string to uncompress |
|
2996 * Return value: Z_STREAM_ERROR |
|
2997 */ |
|
2998 TInt CTestZlib::TestUncompressBufNull() |
|
2999 { |
|
3000 TInt res = KErrNone; |
|
3001 TInt err=0; |
|
3002 Byte *compr, *uncompr; |
|
3003 uLong len = (uLong)strlen(hello)+1; |
|
3004 |
|
3005 uLong comprLen = 20*sizeof(int); |
|
3006 uLong uncomprLen = 3*sizeof(int); |
|
3007 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
3008 if (compr == Z_NULL) |
|
3009 { |
|
3010 return KErrNoMemory; |
|
3011 } |
|
3012 |
|
3013 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
3014 if (uncompr == Z_NULL) |
|
3015 { |
|
3016 free(compr); |
|
3017 return KErrNoMemory; |
|
3018 } |
|
3019 |
|
3020 err = compress(compr, &comprLen, (const Bytef*)hello, len); |
|
3021 if(err == 0) |
|
3022 { |
|
3023 strcpy((char*)uncompr, "garbage"); |
|
3024 err = uncompress(uncompr, &uncomprLen, Z_NULL, comprLen); |
|
3025 if(err == Z_STREAM_ERROR) |
|
3026 { |
|
3027 res = KErrNone ; |
|
3028 } |
|
3029 else |
|
3030 { |
|
3031 res = KErrGeneral; |
|
3032 } |
|
3033 |
|
3034 } |
|
3035 |
|
3036 free(compr); |
|
3037 free(uncompr); |
|
3038 return res; |
|
3039 } |
|
3040 |
|
3041 /** |
|
3042 * Function Name : TestUncompressLenNull |
|
3043 * TestCase Description: Supply uncompress length=0 |
|
3044 * Return value: Z_DATA_ERROR |
|
3045 */ |
|
3046 TInt CTestZlib::TestUncompressLenNull() |
|
3047 { |
|
3048 TInt res = KErrNone; |
|
3049 TInt err=0; |
|
3050 Byte *compr, *uncompr; |
|
3051 uLong len = (uLong)strlen(hello)+1; |
|
3052 |
|
3053 uLong comprLen = 20*sizeof(int); |
|
3054 uLong uncomprLen = 3*sizeof(int); |
|
3055 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
3056 if (compr == Z_NULL) |
|
3057 { |
|
3058 return KErrNoMemory; |
|
3059 } |
|
3060 |
|
3061 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
3062 if (uncompr == Z_NULL) |
|
3063 { |
|
3064 free(compr); |
|
3065 return KErrNoMemory; |
|
3066 } |
|
3067 |
|
3068 err = compress(compr, &comprLen, (const Bytef*)hello, len); |
|
3069 if(err == 0) |
|
3070 { |
|
3071 strcpy((char*)uncompr, "garbage"); |
|
3072 err = uncompress(uncompr, &uncomprLen, compr, 0); |
|
3073 if(err == Z_DATA_ERROR) |
|
3074 { |
|
3075 res = KErrNone ; |
|
3076 } |
|
3077 else |
|
3078 { |
|
3079 res = KErrGeneral; |
|
3080 } |
|
3081 } |
|
3082 |
|
3083 free(compr); |
|
3084 free(uncompr); |
|
3085 return res; |
|
3086 } |
|
3087 |
|
3088 |
|
3089 /** |
|
3090 * Function Name : TestInflateScenarios |
|
3091 * TestCase Description: 1. Pass Windowbits = 15 for inflateInit2_, Z_SYNC_FLUSH for inflate |
|
3092 * 2. Pass Windowbits = -15 for inflateInit2_, Z_SYNC_FLUSH for inflate |
|
3093 * 3. Pass Windowbits = 29 for inflateInit2_, Z_BLOCK for inflate |
|
3094 * Return Value: Z_OK |
|
3095 */ |
|
3096 TInt CTestZlib::TestInflateScenarios() |
|
3097 { |
|
3098 TInt res = KErrNone ; |
|
3099 TInt WindowBits = 0; |
|
3100 TInt flush=0; |
|
3101 Byte *compr, *uncompr; |
|
3102 uLong comprLen = 20*sizeof(int); |
|
3103 uLong uncomprLen = comprLen; |
|
3104 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
3105 if (compr == Z_NULL) |
|
3106 { |
|
3107 return KErrNoMemory; |
|
3108 } |
|
3109 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
3110 if (uncompr == Z_NULL) |
|
3111 { |
|
3112 free(compr); |
|
3113 return KErrNoMemory; |
|
3114 } |
|
3115 res = Test_deflate(compr, comprLen); |
|
3116 if(res<0) |
|
3117 { |
|
3118 free(compr); |
|
3119 free(uncompr); |
|
3120 return KErrNoMemory; |
|
3121 } |
|
3122 |
|
3123 int err=0; |
|
3124 z_stream d_stream; /* decompression stream */ |
|
3125 |
|
3126 strcpy((char*)uncompr, "garbage"); |
|
3127 |
|
3128 d_stream.zalloc = (alloc_func)0; |
|
3129 d_stream.zfree = (free_func)0; |
|
3130 d_stream.opaque = (voidpf)0; |
|
3131 |
|
3132 d_stream.next_in = compr; |
|
3133 d_stream.avail_in = 0; |
|
3134 d_stream.next_out = uncompr; |
|
3135 |
|
3136 ReadIntParam(WindowBits); |
|
3137 res = inflateInit2_(&d_stream, WindowBits, "1.2.4", sizeof(d_stream)); |
|
3138 |
|
3139 if(res<0) |
|
3140 { |
|
3141 free(compr); |
|
3142 free(uncompr); |
|
3143 return KErrNoMemory; |
|
3144 } |
|
3145 |
|
3146 ReadIntParam(flush); |
|
3147 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) |
|
3148 { |
|
3149 d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ |
|
3150 err = inflate(&d_stream, flush); |
|
3151 |
|
3152 if (err == Z_STREAM_END || err == Z_MEM_ERROR || err == Z_DATA_ERROR) break; |
|
3153 } |
|
3154 if(err == Z_MEM_ERROR) |
|
3155 { |
|
3156 err = inflateEnd(&d_stream); |
|
3157 free(compr); |
|
3158 free(uncompr); |
|
3159 |
|
3160 return err; |
|
3161 } |
|
3162 |
|
3163 err = inflateEnd(&d_stream); |
|
3164 if (err != Z_OK) |
|
3165 { |
|
3166 res = KErrGeneral; |
|
3167 } |
|
3168 else |
|
3169 { |
|
3170 res=KErrNone ; |
|
3171 } |
|
3172 free(compr); |
|
3173 free(uncompr); |
|
3174 return res; |
|
3175 |
|
3176 } |
|
3177 |
|
3178 |
|
3179 /** |
|
3180 * Function Name : TestInflateStreamStateNull |
|
3181 * TestCase Description: Make stream.state = NULL and call inflate |
|
3182 * Return Value: Z_STREAM_ERROR |
|
3183 */ |
|
3184 TInt CTestZlib::TestInflateStreamStateNull() |
|
3185 { |
|
3186 TInt res = KErrNone ; |
|
3187 Byte *compr, *uncompr; |
|
3188 uLong comprLen = 20*sizeof(int); |
|
3189 uLong uncomprLen = comprLen; |
|
3190 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
3191 if (compr == Z_NULL) |
|
3192 { |
|
3193 return KErrNoMemory; |
|
3194 } |
|
3195 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
3196 if (uncompr == Z_NULL) |
|
3197 { |
|
3198 free(compr); |
|
3199 return KErrNoMemory; |
|
3200 } |
|
3201 res = Test_deflate(compr, comprLen); |
|
3202 if(res<0) |
|
3203 { |
|
3204 free(compr); |
|
3205 free(uncompr); |
|
3206 return KErrNoMemory; |
|
3207 } |
|
3208 |
|
3209 int err=0; |
|
3210 z_stream d_stream; /* decompression stream */ |
|
3211 |
|
3212 strcpy((char*)uncompr, "garbage"); |
|
3213 |
|
3214 d_stream.zalloc = (alloc_func)0; |
|
3215 d_stream.zfree = (free_func)0; |
|
3216 d_stream.opaque = (voidpf)0; |
|
3217 |
|
3218 d_stream.next_in = compr; |
|
3219 d_stream.avail_in = 0; |
|
3220 d_stream.next_out = uncompr; |
|
3221 |
|
3222 res = inflateInit2_(&d_stream, 15, "1.2.4", sizeof(d_stream)); |
|
3223 |
|
3224 if(res<0) |
|
3225 { |
|
3226 free(compr); |
|
3227 free(uncompr); |
|
3228 return KErrNoMemory; |
|
3229 } |
|
3230 |
|
3231 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) |
|
3232 { |
|
3233 d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ |
|
3234 err = inflate(&d_stream, Z_SYNC_FLUSH); |
|
3235 |
|
3236 if (err == Z_STREAM_END || err == Z_STREAM_ERROR || err == Z_MEM_ERROR) break; |
|
3237 } |
|
3238 |
|
3239 if(err == Z_STREAM_ERROR) |
|
3240 { |
|
3241 res=KErrNone; |
|
3242 } |
|
3243 err = inflateEnd(&d_stream); |
|
3244 if (err == Z_STREAM_ERROR) |
|
3245 { |
|
3246 res=KErrNone; |
|
3247 } |
|
3248 |
|
3249 d_stream.state = Z_NULL; |
|
3250 err = inflate(&d_stream, Z_SYNC_FLUSH); |
|
3251 if (err == Z_STREAM_ERROR) |
|
3252 { |
|
3253 res = KErrNone; |
|
3254 } |
|
3255 |
|
3256 free(compr); |
|
3257 free(uncompr); |
|
3258 return res; |
|
3259 } |
|
3260 |
|
3261 /** |
|
3262 * Function Name : TestInflateResetStreamStateNull |
|
3263 * TestCase Description: Make stream.state = NULL and call inflateReset |
|
3264 * Return Value: Z_STREAM_ERROR |
|
3265 */ |
|
3266 TInt CTestZlib::TestInflateResetStreamStateNull() |
|
3267 { |
|
3268 TInt res=KErrNone; |
|
3269 z_stream d_stream; /* decompression stream */ |
|
3270 const char * version; |
|
3271 d_stream.zalloc = (alloc_func)0; |
|
3272 d_stream.zfree = (free_func)0; |
|
3273 d_stream.opaque = (voidpf)0; |
|
3274 |
|
3275 Byte *compr, *uncompr; |
|
3276 uLong comprLen = 20*sizeof(int); |
|
3277 uLong uncomprLen = comprLen; |
|
3278 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
3279 if (compr == Z_NULL) |
|
3280 { |
|
3281 return KErrNoMemory; |
|
3282 } |
|
3283 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
3284 if (uncompr == Z_NULL) |
|
3285 { |
|
3286 free(compr); |
|
3287 return KErrNoMemory; |
|
3288 } |
|
3289 |
|
3290 res = Test_deflate(compr, comprLen); |
|
3291 if(res<0) |
|
3292 { |
|
3293 free(compr); |
|
3294 free(uncompr); |
|
3295 return KErrNoMemory; |
|
3296 } |
|
3297 d_stream.next_in = compr; |
|
3298 d_stream.avail_in = 0; |
|
3299 d_stream.next_out = uncompr; |
|
3300 version=zlibVersion(); |
|
3301 int err; |
|
3302 err = inflateInit_(&d_stream,(char*)version, sizeof(d_stream)); |
|
3303 |
|
3304 if(err<0) |
|
3305 { |
|
3306 free(compr); |
|
3307 free(uncompr); |
|
3308 return KErrNoMemory; |
|
3309 } |
|
3310 |
|
3311 err=inflateReset(&d_stream); |
|
3312 err=inflateEnd(&d_stream); |
|
3313 free(compr); |
|
3314 free(uncompr); |
|
3315 |
|
3316 // for coverage improvement |
|
3317 d_stream.state = Z_NULL; |
|
3318 err=inflateReset(&d_stream); |
|
3319 |
|
3320 if(err == Z_STREAM_ERROR) |
|
3321 { |
|
3322 res = KErrNone; |
|
3323 } |
|
3324 else |
|
3325 { |
|
3326 res = KErrGeneral; |
|
3327 } |
|
3328 return res; |
|
3329 } |