Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Name : tzlibcases.cpp
22 #define CHECK_ERR(err, msg) { \
24 INFO_PRINTF2(_L("Error: %d"), err); \
30 TInt CTestZlib::PreDeflateInit( Byte * compr, uLong comprLen, TInt flush, TInt compression)
32 z_stream c_stream; // compression stream
34 const char hello[] = "hello, hello!";
35 uLong len = (uLong)strlen(hello)+1;
37 c_stream.zalloc = (alloc_func)0;
38 c_stream.zfree = (free_func)0;
39 c_stream.opaque = (voidpf)0;
41 err = deflateInit(&c_stream,compression);// Z_DEFAULT_COMPRESSION);
45 INFO_PRINTF2(_L("deflateInit error: %d"), err);
49 c_stream.next_in = (Bytef*)hello;
50 c_stream.next_out = compr;
52 while (c_stream.total_in != len && c_stream.total_out < comprLen)
54 c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers
55 err = deflate(&c_stream, flush);
58 INFO_PRINTF2(_L("deflate return code: %d"), err);
59 deflateEnd(&c_stream);
63 // Finish the stream, still forcing small buffers:
66 c_stream.avail_out = 1;
67 err = deflate(&c_stream, Z_FINISH);
68 if (err == Z_STREAM_END) break;
71 INFO_PRINTF2(_L("deflate error: %d"), err);
72 deflateEnd(&c_stream);
77 deflateEnd(&c_stream);
82 * Function Name : TestDeflateTest01
83 * TestCase Description: 1. Reads flush value more than Z_FINISH [i.e, 4]
84 * 2. Reads negative flush value
86 TInt CTestZlib::TestDeflateTest01( )
88 INFO_PRINTF1(_L("Zlib Test deflate"));
89 TInt flush, compression, expRet;
94 comp = (Byte*)calloc((uInt)compLen, 1);
97 ReadIntParam(compression);
100 z_stream c_stream; // compression stream
102 const char hello[] = "hello, hello!";
103 uLong len = (uLong)strlen(hello)+1;
105 c_stream.zalloc = (alloc_func)0;
106 c_stream.zfree = (free_func)0;
107 c_stream.opaque = (voidpf)0;
109 err = deflateInit(&c_stream,compression);// Z_DEFAULT_COMPRESSION);
113 INFO_PRINTF2(_L("deflateInit error: %d"), err);
118 c_stream.next_in = (Bytef*)hello;
119 c_stream.next_out = comp;
121 while (c_stream.total_in != len && c_stream.total_out < compLen)
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)
127 INFO_PRINTF1(_L("Negative test case passed"));
128 deflateEnd(&c_stream);
139 * Function Name : TestDeflatecopyDestNull
140 * TestCase Description: Deflate copy with Destination as NULL
142 TInt CTestZlib::TestDeflatecopyDestNull()
144 uLong len = (uLong)strlen(hello)+1;
146 Byte *compr, *uncompr;
147 uLong comprLen = 20*sizeof(int);
148 uLong uncomprLen = comprLen;
149 compr = (Byte*)calloc((uInt)comprLen, 1);
155 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
156 if (uncompr == Z_NULL)
166 stream.zalloc = (alloc_func)0;
167 stream.zfree = (free_func)0;
168 stream.opaque = (voidpf)0;
170 stream.next_in = (Bytef*)hello;
171 stream.avail_in = (uInt)len;
173 stream.next_out = compr;
174 stream.avail_out = (uInt)comprLen;
176 err = deflateInit(&stream, Z_DEFAULT_COMPRESSION);
178 err=deflateCopy(NULL , &stream);
180 if (err == Z_STREAM_ERROR )
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
196 TInt CTestZlib::TestDeflateCopyStreamStateNull()
198 uLong len = (uLong)strlen(hello)+1;
200 Byte *compr, *uncompr;
201 uLong comprLen = 20*sizeof(int);
202 uLong uncomprLen = comprLen;
203 compr = (Byte*)calloc((uInt)comprLen, 1);
209 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
210 if (uncompr == Z_NULL)
220 stream.zalloc = (alloc_func)0;
221 stream.zfree = (free_func)0;
222 stream.opaque = (voidpf)0;
224 stream.next_in = (Bytef*)hello;
225 stream.avail_in = (uInt)len;
227 stream.next_out = compr;
228 stream.avail_out = (uInt)comprLen;
230 err = deflateInit(&stream, Z_DEFAULT_COMPRESSION);
232 err=deflateCopy(&stream1, &stream);
234 deflateEnd(&stream1);
236 // Make stream state Z_NULL and call deflateCopy for coverage imrprovement
237 stream.state = Z_NULL;
238 err=deflateCopy(&stream1 , &stream);
240 if (err == Z_STREAM_ERROR )
250 * Function Name : TestDeflateInit2_WindowBits
251 * TestCase Description: 1. WindowBits value more than 15
252 * 2. WindowBits value less than 8
255 TInt CTestZlib::TestDeflateInit2_WindowBits()
260 int level=Z_DEFAULT_COMPRESSION;
263 uLong sourceLen = (uLong)strlen(hello)+1;
265 uLong comprLen = 10*sizeof(int);
266 compr = (Byte*)calloc((uInt)comprLen, 1);
272 ReadIntParam(WindowBits);
273 stream.zalloc = (alloc_func)0;
274 stream.zfree = (free_func)0;
275 stream.opaque = (voidpf)0;
278 err= deflateInit2_(&stream, level, 8, WindowBits, 8,
279 0, zlibVersion(), sizeof(z_stream));
281 if (err == Z_STREAM_ERROR)
285 else if (err == Z_OK)
302 * Function Name : TestDeflateInit2_StreamSize
303 * TestCase Description: Stream size less than sizeof(z_stream)
305 TInt CTestZlib::TestDeflateInit2_StreamSize()
307 TInt res = KErrNone ;
310 int level=Z_DEFAULT_COMPRESSION;
313 uLong sourceLen = (uLong)strlen(hello)+1;
315 uLong comprLen = 10*sizeof(int);
316 compr = (Byte*)calloc((uInt)comprLen, 1);
322 ReadIntParam(WindowBits);
323 stream.zalloc = (alloc_func)0;
324 stream.zfree = (free_func)0;
325 stream.opaque = (voidpf)0;
327 // passing stream size < sizeof(z_stream)
328 err= deflateInit2_(&stream, level, 8, 15, 8,
329 0, zlibVersion(), sizeof(z_stream)-10);
331 if (err == Z_VERSION_ERROR)
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]
349 TInt CTestZlib::TestDeflateInit2_MemLevel()
351 TInt res = KErrNone ;
354 int level=Z_DEFAULT_COMPRESSION;
357 uLong sourceLen = (uLong)strlen(hello)+1;
359 uLong comprLen = 10*sizeof(int);
360 compr = (Byte*)calloc((uInt)comprLen, 1);
366 ReadIntParam(MemLevel);
367 stream.zalloc = (alloc_func)0;
368 stream.zfree = (free_func)0;
369 stream.opaque = (voidpf)0;
372 err= deflateInit2_(&stream, level, 3, 15, MemLevel,
373 0, zlibVersion(), sizeof(z_stream));
375 if (err == Z_STREAM_ERROR)
384 //deflateEnd(&stream);
390 * Function Name : TestDeflateInit2_Level
391 * TestCase Description: 1. Level value less than 0
392 * 2. Level value more than 9
394 TInt CTestZlib::TestDeflateInit2_Level()
396 TInt res = KErrNone ;
401 uLong sourceLen = (uLong)strlen(hello)+1;
403 uLong comprLen = 10*sizeof(int);
404 compr = (Byte*)calloc((uInt)comprLen, 1);
411 stream.zalloc = (alloc_func)0;
412 stream.zfree = (free_func)0;
413 stream.opaque = (voidpf)0;
416 err= deflateInit2_(&stream, level, 8, 15, 8,
417 0, zlibVersion(), sizeof(z_stream));
419 if (err == Z_STREAM_ERROR)
428 //deflateEnd(&stream);
434 * Function Name : TestDeflateInit2_Strategy
435 * TestCase Description: 1. Strategy value less than 0
436 * 2. Strategy value more than Z_FIXED
438 TInt CTestZlib::TestDeflateInit2_Strategy()
440 TInt res = KErrNone ;
443 int level=Z_DEFAULT_COMPRESSION;
446 uLong sourceLen = (uLong)strlen(hello)+1;
448 uLong comprLen = 10*sizeof(int);
449 compr = (Byte*)calloc((uInt)comprLen, 1);
455 ReadIntParam(strategy);
456 stream.zalloc = (alloc_func)0;
457 stream.zfree = (free_func)0;
458 stream.opaque = (voidpf)0;
461 err= deflateInit2_(&stream, level, 8, 15, 8,
462 strategy, zlibVersion(), sizeof(z_stream));
464 if (err == Z_STREAM_ERROR)
478 * Function Name : TestDeflateInit2_Version
479 * TestCase Description: Invalid version value
480 * Return Value: returns Z_VERSION_ERROR
482 TInt CTestZlib::TestDeflateInit2_Version()
484 TInt res = KErrNone ;
487 int level=Z_DEFAULT_COMPRESSION;
490 uLong sourceLen = (uLong)strlen(hello)+1;
492 uLong comprLen = 10*sizeof(int);
493 compr = (Byte*)calloc((uInt)comprLen, 1);
499 ReadStringParam(version);
500 stream.zalloc = (alloc_func)0;
501 stream.zfree = (free_func)0;
502 stream.opaque = (voidpf)0;
505 err= deflateInit2_(&stream, level, 8, 15, 8,
506 0, version, sizeof(z_stream));
508 if (err == Z_VERSION_ERROR)
522 * Function Name : TestDeflateInit2_VersionNull
523 * TestCase Description: version value is Z_NULL
524 * Return Value: Z_VERSION_ERROR
526 TInt CTestZlib::TestDeflateInit2_VersionNull()
528 TInt res = KErrNone ;
531 int level=Z_DEFAULT_COMPRESSION;
533 uLong sourceLen = (uLong)strlen(hello)+1;
535 uLong comprLen = 10*sizeof(int);
536 compr = (Byte*)calloc((uInt)comprLen, 1);
542 stream.zalloc = (alloc_func)0;
543 stream.zfree = (free_func)0;
544 stream.opaque = (voidpf)0;
547 err= deflateInit2_(&stream, level, 8, 15, 8,
548 0, Z_NULL, sizeof(z_stream));
550 if (err == Z_VERSION_ERROR)
565 * Function Name : TestDeflateInit2_StreamNull
566 * TestCase Description: Pass Z_NULL stream
568 TInt CTestZlib::TestDeflateInit2_StreamNull()
570 TInt res = KErrNone ;
573 int level=Z_DEFAULT_COMPRESSION;
575 uLong sourceLen = (uLong)strlen(hello)+1;
577 uLong comprLen = 10*sizeof(int);
578 compr = (Byte*)calloc((uInt)comprLen, 1);
584 //stream.zalloc = (alloc_func)0;
585 //stream.zfree = (free_func)0;
586 //stream.opaque = (voidpf)0;
588 err= deflateInit2_(Z_NULL, level, 8, 15, 8,
589 0, zlibVersion(), sizeof(z_stream));
591 if (err == Z_STREAM_ERROR)
605 * Function Name : TestInflateInit2_Version
606 * TestCase Description: Invalid version value
607 * Return Value: returns Z_VERSION_ERROR
609 TInt CTestZlib::TestInflateInit2_Version()
611 TInt res = KErrNone ;
613 z_stream d_stream; // decompression stream
615 d_stream.zalloc = (alloc_func)0;
616 d_stream.zfree = (free_func)0;
617 d_stream.opaque = (voidpf)0;
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);
627 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
628 if (uncompr == Z_NULL)
633 res = Test_deflate(compr, comprLen);
640 d_stream.next_in = compr;
641 d_stream.avail_in = 0;
642 d_stream.next_out = uncompr;
644 //Reading invalid version from ini file
645 ReadStringParam(version);
647 int ret = inflateInit2_(&d_stream, 15, version, sizeof(d_stream));
648 if(ret == Z_VERSION_ERROR)
662 * Function Name : TestInflateInit2_VersionNull
663 * TestCase Description: version value is Z_NULL
664 * Return Value: Z_VERSION_ERROR
666 TInt CTestZlib::TestInflateInit2_VersionNull()
668 TInt res = KErrNone ;
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;
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);
683 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
684 if (uncompr == Z_NULL)
689 res = Test_deflate(compr, comprLen);
696 d_stream.next_in = compr;
697 d_stream.avail_in = 0;
698 d_stream.next_out = uncompr;
700 int ret = inflateInit2_(&d_stream, 15, Z_NULL, sizeof(d_stream));
701 if(ret == Z_VERSION_ERROR)
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
719 TInt CTestZlib::TestInflateInit2_WindowBits()
721 TInt res = KErrNone ;
723 z_stream d_stream; // decompression stream
725 d_stream.zalloc = (alloc_func)0;
726 d_stream.zfree = (free_func)0;
727 d_stream.opaque = (voidpf)0;
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);
737 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
738 if (uncompr == Z_NULL)
743 res = Test_deflate(compr, comprLen);
750 d_stream.next_in = compr;
751 d_stream.avail_in = 0;
752 d_stream.next_out = uncompr;
754 //Reading window bits from ini file
755 ReadIntParam(WindowBits);
757 int ret = inflateInit2_(&d_stream, WindowBits, "1.2.4", sizeof(d_stream));
758 if(ret == Z_STREAM_ERROR)
772 * Function Name : TestInflateInit2_StreamNull
773 * TestCase Description: Stream NULL
774 * Return Value: returns Z_STREAM_ERROR
776 TInt CTestZlib::TestInflateInit2_StreamNull()
778 TInt res = KErrNone ;
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;
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);
793 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
794 if (uncompr == Z_NULL)
799 res = Test_deflate(compr, comprLen);
806 //d_stream.next_in = compr;
807 //d_stream.avail_in = 0;
808 //d_stream.next_out = uncompr;
810 int ret = inflateInit2_(Z_NULL, 15, "1.2.4", sizeof(d_stream));
811 if(ret == Z_STREAM_ERROR)
825 * Function Name : TestDeflate_HuffmanStrategy
826 * TestCase Description: Strategy is HUFFMAN
829 TInt CTestZlib::TestDeflate_HuffmanStrategy()
831 TInt res = KErrNone ;
834 int level=Z_DEFAULT_COMPRESSION;
836 uLong sourceLen = (uLong)strlen(hello)+1;
838 uLong comprLen = 20*sizeof(int);
839 compr = (Byte*)calloc((uInt)comprLen, 1);
845 stream.zalloc = (alloc_func)0;
846 stream.zfree = (free_func)0;
847 stream.opaque = (voidpf)0;
850 err= deflateInit2_(&stream, level, 8, 15, 8,
851 2, zlibVersion(), sizeof(z_stream));
862 stream.next_in = (Bytef*)hello;
863 stream.next_out = compr;
865 while (stream.total_in != sourceLen && stream.total_out < comprLen)
867 stream.avail_in = stream.avail_out = 1; /* force small buffers */
868 err = deflate(&stream, Z_NO_FLUSH);
870 /* Finish the stream, still forcing small buffers: */
873 stream.avail_out = 1;
874 err = deflate(&stream, Z_FINISH);
875 if (err == Z_STREAM_END) break;
882 err = deflateEnd(&stream);
893 * Function Name : TestDeflate_AvailInZero
894 * TestCase Description: avail_in value is set to 0
895 * Return Value: Z_STREAM_ERROR
897 TInt CTestZlib::TestDeflate_AvailInZero()
899 TInt res = KErrNone ;
902 int level=Z_DEFAULT_COMPRESSION;
904 uLong sourceLen = (uLong)strlen(hello)+1;
906 uLong comprLen = 20*sizeof(int);
907 compr = (Byte*)calloc((uInt)comprLen, 1);
913 stream.zalloc = (alloc_func)0;
914 stream.zfree = (free_func)0;
915 stream.opaque = (voidpf)0;
918 err= deflateInit2_(&stream, level, 8, 15, 8,
919 0, zlibVersion(), sizeof(z_stream));
930 stream.next_in = Z_NULL;
931 stream.next_out = Z_NULL;
933 while (stream.total_in != sourceLen && stream.total_out < comprLen)
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);
942 if (err == Z_STREAM_ERROR)
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
964 TInt CTestZlib::TestGzsetparamDefaultCompression()
966 TInt res = KErrNone ;
968 int len = (int)strlen(hello)+1;
971 const char * fname = TESTFILE;
973 file = gzopen(fname, "wb");
976 int u = gzsetparams(file, Z_DEFAULT_COMPRESSION, 8);
977 if(u == Z_STREAM_ERROR)
981 int err= gzclose(file);
991 * Function Name : TestDeflateResetNullStream
992 * TestCase Description: Pass NULL stream
993 * Return Value: Z_STREAM_ERROR
995 TInt CTestZlib::TestDeflateResetNullStream()
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;
1006 compr = (Byte*)calloc((uInt)comprLen, 1);
1007 if (compr == Z_NULL)
1009 return KErrNoMemory;
1011 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1012 if (uncompr == Z_NULL)
1015 return KErrNoMemory;
1018 stream.zalloc = (alloc_func)0;
1019 stream.zfree = (free_func)0;
1020 stream.opaque = (voidpf)0;
1022 err = deflateInit(&stream, level);
1030 Bytef *dest = compr ;
1031 uLongf *destLen = &comprLen;
1032 const Bytef *source = (const Bytef*)hello;
1033 uLong sourceLen = len;
1035 stream.next_in = (Bytef*)source;
1036 stream.avail_in = (uInt)sourceLen;
1039 /* Check for source > 64K on 16-bit machine: */
1040 if ((uLong)stream.avail_in != sourceLen)
1046 stream.next_out = dest;
1047 stream.avail_out = (uInt)*destLen;
1049 if ((uLong)stream.avail_out != *destLen)
1054 err=deflateReset(Z_NULL/*&stream*/);
1055 if (err == Z_STREAM_ERROR)
1063 deflateEnd(&stream);
1070 * Function Name : TestDeflateResetStreamStateNull
1071 * TestCase Description: Pass NULL stream state
1072 * Return Value: Z_STREAM_ERROR
1074 TInt CTestZlib::TestDeflateResetStreamStateNull()
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;
1084 compr = (Byte*)calloc((uInt)comprLen, 1);
1085 if (compr == Z_NULL)
1087 return KErrNoMemory;
1089 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1090 if (uncompr == Z_NULL)
1093 return KErrNoMemory;
1096 stream.zalloc = (alloc_func)0;
1097 stream.zfree = (free_func)0;
1098 stream.opaque = (voidpf)0;
1100 err = deflateInit(&stream, level);
1108 Bytef *dest = compr ;
1109 uLongf *destLen = &comprLen;
1110 const Bytef *source = (const Bytef*)hello;
1111 uLong sourceLen = len;
1113 stream.next_in = (Bytef*)source;
1114 stream.avail_in = (uInt)sourceLen;
1117 /* Check for source > 64K on 16-bit machine: */
1118 if ((uLong)stream.avail_in != sourceLen)
1124 stream.next_out = dest;
1125 stream.avail_out = (uInt)*destLen;
1127 if ((uLong)stream.avail_out != *destLen)
1132 err=deflateReset(&stream);
1133 deflateEnd(&stream);
1135 //equate stream state to Z_NULL for coverage improvement
1136 stream.state = Z_NULL;
1137 err=deflateReset(&stream);
1139 if (err == Z_STREAM_ERROR)
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
1161 TInt CTestZlib::TestDeflate_Scenarios()
1163 TInt res = KErrNone ;
1169 uLong sourceLen = (uLong)strlen(hello)+1;
1171 uLong comprLen = 20*sizeof(int);
1172 compr = (Byte*)calloc((uInt)comprLen, 1);
1173 if (compr == Z_NULL)
1175 return KErrNoMemory;
1178 stream.zalloc = (alloc_func)0;
1179 stream.zfree = (free_func)0;
1180 stream.opaque = (voidpf)0;
1182 ReadIntParam(level);
1183 ReadIntParam(strategy);
1184 err= deflateInit2_(&stream, level, 8, 15, 8,
1185 strategy, zlibVersion(), sizeof(z_stream));
1196 stream.next_in = (Bytef*)hello;
1197 stream.next_out = compr;
1199 while (stream.total_in != sourceLen && stream.total_out < comprLen)
1201 stream.avail_in = stream.avail_out = 1; /* force small buffers */
1202 err = deflate(&stream, Z_NO_FLUSH);
1204 /* Finish the stream, still forcing small buffers: */
1207 stream.avail_out = 1;
1208 err = deflate(&stream, Z_FINISH);
1209 if (err == Z_STREAM_END) break;
1216 err = deflateEnd(&stream);
1227 * Function Name : TestDeflate_NullStream
1228 * TestCase Description: NULL stream is passed for deflate
1229 * Return Value: Z_STREAM_ERROR
1231 TInt CTestZlib::TestDeflate_NullStream()
1233 TInt res = KErrNone ;
1236 int level=Z_DEFAULT_COMPRESSION;
1238 uLong sourceLen = (uLong)strlen(hello)+1;
1240 uLong comprLen = 20*sizeof(int);
1241 compr = (Byte*)calloc((uInt)comprLen, 1);
1242 if (compr == Z_NULL)
1244 return KErrNoMemory;
1247 stream.zalloc = (alloc_func)0;
1248 stream.zfree = (free_func)0;
1249 stream.opaque = (voidpf)0;
1252 err= deflateInit2_(&stream, level, 8, 15, 8,
1253 0, zlibVersion(), sizeof(z_stream));
1264 stream.next_in = (Bytef*)hello;
1265 stream.next_out = compr;
1267 while (stream.total_in != sourceLen && stream.total_out < comprLen)
1269 stream.avail_in = stream.avail_out = 1; // force small buffers
1270 err = deflate(Z_NULL, Z_NO_FLUSH);
1275 if (err == Z_STREAM_ERROR)
1278 deflateEnd(&stream);
1291 * Function Name : TestDeflate_StreamStateNull
1292 * TestCase Description: stream state is made Z_NULL before calling deflate
1293 * Return Value: Z_STREAM_ERROR
1295 TInt CTestZlib::TestDeflate_StreamStateNull()
1297 TInt res = KErrNone ;
1300 int level=Z_DEFAULT_COMPRESSION;
1302 uLong sourceLen = (uLong)strlen(hello)+1;
1304 uLong comprLen = 20*sizeof(int);
1305 compr = (Byte*)calloc((uInt)comprLen, 1);
1306 if (compr == Z_NULL)
1308 return KErrNoMemory;
1311 stream.zalloc = (alloc_func)0;
1312 stream.zfree = (free_func)0;
1313 stream.opaque = (voidpf)0;
1315 err= deflateInit2_(&stream, level, 8, 15, 8,
1316 0, zlibVersion(), sizeof(z_stream));
1327 stream.next_in = (Bytef*)hello;
1328 stream.next_out = compr;
1330 while (stream.total_in != sourceLen && stream.total_out < comprLen)
1332 stream.avail_in = stream.avail_out = 1; // force small buffers
1333 err = deflate(&stream, Z_NO_FLUSH);
1335 deflateEnd(&stream);
1337 //equate stream state to Z_NULL for voverage improvement
1338 stream.state = Z_NULL;
1339 err = deflate(&stream, Z_NO_FLUSH);
1341 if (err == Z_STREAM_ERROR)
1354 * Function Name : TestDeflateEndNull
1355 * TestCase Description: Pass Z_NULL to deflateEnd
1356 * Return Value: Z_STREAM_ERROR
1358 TInt CTestZlib::TestDeflateEndNull()
1360 TInt res = KErrNone ;
1363 int level=Z_DEFAULT_COMPRESSION;
1364 int strategy=Z_DEFAULT_STRATEGY;
1366 uLong sourceLen = (uLong)strlen(hello)+1;
1368 uLong comprLen = 20*sizeof(int);
1369 compr = (Byte*)calloc((uInt)comprLen, 1);
1370 if (compr == Z_NULL)
1372 return KErrNoMemory;
1375 stream.zalloc = (alloc_func)0;
1376 stream.zfree = (free_func)0;
1377 stream.opaque = (voidpf)0;
1379 err= deflateInit2_(&stream, level, 8, 15, 8,
1380 strategy, zlibVersion(), sizeof(z_stream));
1391 stream.next_in = (Bytef*)hello;
1392 stream.next_out = compr;
1394 while (stream.total_in != sourceLen && stream.total_out < comprLen)
1396 stream.avail_in = stream.avail_out = 1; /* force small buffers */
1397 err = deflate(&stream, Z_NO_FLUSH);
1399 /* Finish the stream, still forcing small buffers: */
1402 stream.avail_out = 1;
1403 err = deflate(&stream, Z_FINISH);
1404 if (err == Z_STREAM_END) break;
1412 err = deflateEnd(&stream);
1413 err = deflateEnd(Z_NULL); // for coverage improvement
1414 if(err == Z_STREAM_ERROR)
1428 * Function Name : TestDeflateEndStreamStateNull
1429 * TestCase Description: Make stream.state = Z_NULL
1430 * Return Value: Z_STREAM_ERROR
1432 TInt CTestZlib::TestDeflateEndStreamStateNull()
1434 TInt res = KErrNone ;
1437 int level=Z_DEFAULT_COMPRESSION;
1438 int strategy=Z_DEFAULT_STRATEGY;
1440 uLong sourceLen = (uLong)strlen(hello)+1;
1442 uLong comprLen = 20*sizeof(int);
1443 compr = (Byte*)calloc((uInt)comprLen, 1);
1444 if (compr == Z_NULL)
1446 return KErrNoMemory;
1449 stream.zalloc = (alloc_func)0;
1450 stream.zfree = (free_func)0;
1451 stream.opaque = (voidpf)0;
1453 err= deflateInit2_(&stream, level, 8, 15, 8,
1454 strategy, zlibVersion(), sizeof(z_stream));
1465 stream.next_in = (Bytef*)hello;
1466 stream.next_out = compr;
1468 while (stream.total_in != sourceLen && stream.total_out < comprLen)
1470 stream.avail_in = stream.avail_out = 1; /* force small buffers */
1471 err = deflate(&stream, Z_NO_FLUSH);
1473 /* Finish the stream, still forcing small buffers: */
1476 stream.avail_out = 1;
1477 err = deflate(&stream, Z_FINISH);
1478 if (err == Z_STREAM_END) break;
1484 err = deflateEnd(&stream);
1486 // Make state Z_NULL
1487 stream.state = Z_NULL;
1488 err = deflateEnd(&stream);
1490 if(err == Z_STREAM_ERROR)
1504 * Function Name : TestDeflate_WindowBits
1505 * TestCase Description: Window bits more than 15 is supplied for deflate init
1506 * Return Value: Z_OK
1508 TInt CTestZlib::TestDeflate_WindowBits()
1510 TInt res = KErrNone ;
1513 int level=Z_BEST_COMPRESSION;
1515 uLong sourceLen = (uLong)strlen(hello)+1;
1517 uLong comprLen = 20*sizeof(int);
1518 compr = (Byte*)calloc((uInt)comprLen, 1);
1519 if (compr == Z_NULL)
1521 return KErrNoMemory;
1524 stream.zalloc = (alloc_func)0;
1525 stream.zfree = (free_func)0;
1526 stream.opaque = (voidpf)0;
1529 err= deflateInit2_(&stream, level, 8, 25, 8,
1530 0, zlibVersion(), sizeof(z_stream));
1541 stream.next_in = (Bytef*)hello;
1542 stream.next_out = compr;
1544 while (stream.total_in != sourceLen && stream.total_out < comprLen)
1546 stream.avail_in = stream.avail_out = 1; /* force small buffers */
1547 err = deflate(&stream, Z_NO_FLUSH);
1549 /* Finish the stream, still forcing small buffers: */
1552 stream.avail_out = 1;
1553 err = deflate(&stream, Z_FINISH);
1554 if (err == Z_STREAM_END) break;
1561 err = deflateEnd(&stream);
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)
1576 TInt CTestZlib::TestDeflateBoundStreamNotNull()
1578 TInt res = KErrNone;
1581 int level=Z_DEFAULT_COMPRESSION;
1583 uLong sourceLen = (uLong)strlen(hello)+1;
1585 uLong comprLen = 20*sizeof(int);
1586 compr = (Byte*)calloc((uInt)comprLen, 1);
1587 if (compr == Z_NULL)
1589 return KErrNoMemory;
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)
1601 stream.zalloc = (alloc_func)0;
1602 stream.zfree = (free_func)0;
1603 stream.opaque = (voidpf)0;
1605 err= deflateInit2_(&stream, level, 8, 14, 7,
1606 0, zlibVersion(), sizeof(z_stream));
1610 int y= deflateBound(&stream, sourceLen);
1626 err=deflateEnd(&stream);
1636 * Function Name : TestDeflateBoundStreamNull
1637 * TestCase Description: Pass Z_NULL to deflatebound
1639 TInt CTestZlib::TestDeflateBoundStreamNull()
1641 TInt res = KErrNone;
1644 int level=Z_DEFAULT_COMPRESSION;
1646 uLong sourceLen = (uLong)strlen(hello)+1;
1648 uLong comprLen = 20*sizeof(int);
1649 compr = (Byte*)calloc((uInt)comprLen, 1);
1650 if (compr == Z_NULL)
1652 return KErrNoMemory;
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)
1664 stream.zalloc = (alloc_func)0;
1665 stream.zfree = (free_func)0;
1666 stream.opaque = (voidpf)0;
1668 err= deflateInit2_(&stream, level, 8, 15, 7,
1669 0, zlibVersion(), sizeof(z_stream));
1673 int y= deflateBound(Z_NULL, sourceLen);
1689 err=deflateEnd(&stream);
1699 * Function Name : TestDeflateBoundStreamStateNull
1700 * TestCase Description: Stream state is equated to Z_NULL
1701 * and passed to deflatebound
1703 TInt CTestZlib::TestDeflateBoundStreamStateNull()
1705 TInt res = KErrNone;
1708 int level=Z_DEFAULT_COMPRESSION;
1710 uLong sourceLen = (uLong)strlen(hello)+1;
1712 uLong comprLen = 20*sizeof(int);
1713 compr = (Byte*)calloc((uInt)comprLen, 1);
1714 if (compr == Z_NULL)
1716 return KErrNoMemory;
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)
1728 stream.zalloc = (alloc_func)0;
1729 stream.zfree = (free_func)0;
1730 stream.opaque = (voidpf)0;
1732 err= deflateInit2_(&stream, level, 8, 15, 7,
1733 0, zlibVersion(), sizeof(z_stream));
1737 //stream.state = Z_NULL;
1738 int y= deflateBound(&stream, sourceLen);
1747 err=deflateEnd(&stream);
1750 INFO_PRINTF1(_L("Error encountered in deflateEnd"));
1755 // for coverage improvement
1756 stream.state = Z_NULL;
1757 y = deflateBound(&stream, sourceLen);
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
1775 TInt CTestZlib::TestDeflateSetDictionaryWrap()
1777 int level=Z_DEFAULT_COMPRESSION;
1783 comp = (Byte*)calloc((uInt)compLen, 1);
1785 ReadIntParam(WindowBits);
1787 z_stream stream; // compression stream
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;
1796 err= deflateInit2_(&stream, level, 8, WindowBits, 8, 0, zlibVersion(), sizeof(z_stream));
1800 INFO_PRINTF2(_L("deflateInit error: %d"), err);
1804 err = deflateSetDictionary(&stream,dictionary,3);
1805 if(err == Z_STREAM_ERROR)
1808 deflateEnd(&stream);
1811 stream.next_in = (Bytef*)hello;
1812 stream.next_out = comp;
1814 while (stream.total_in != len && stream.total_out < compLen)
1816 stream.avail_in = stream.avail_out = 1; //* force small buffers
1817 err = deflate(&stream, Z_NO_FLUSH);
1820 INFO_PRINTF2(_L("deflate return code: %d"), err);
1821 deflateEnd(&stream);
1826 // Finish the stream, still forcing small buffers:
1829 stream.avail_out = 1;
1830 err = deflate(&stream, Z_FINISH);
1831 if (err == Z_STREAM_END) break;
1834 INFO_PRINTF2(_L("deflate error: %d"), err);
1835 deflateEnd(&stream);
1841 deflateEnd(&stream);
1848 * Function Name : TestDeflateSetDictionaryLen
1849 * TestCase Description: Supply dictLength > MAX_DIST(s)
1850 * Return Value: Z_OK
1852 TInt CTestZlib::TestDeflateSetDictionaryLen()
1854 int level=Z_DEFAULT_COMPRESSION;
1859 comp = (Byte*)calloc((uInt)compLen, 1);
1861 z_stream stream; // compression stream
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;
1870 err= deflateInit2_(&stream, level, 8, 9, 8, 0, zlibVersion(), sizeof(z_stream));
1874 INFO_PRINTF2(_L("deflateInit error: %d"), err);
1879 // Pass dictLength=251 which is > MAX_DIST(s) for window bits=9
1880 err = deflateSetDictionary(&stream,dictionary,251);
1884 deflateEnd(&stream);
1887 stream.next_in = (Bytef*)hello;
1888 stream.next_out = comp;
1890 while (stream.total_in != len && stream.total_out < compLen)
1892 stream.avail_in = stream.avail_out = 1; //* force small buffers
1893 err = deflate(&stream, Z_NO_FLUSH);
1896 INFO_PRINTF2(_L("deflate return code: %d"), err);
1897 deflateEnd(&stream);
1902 // Finish the stream, still forcing small buffers:
1905 stream.avail_out = 1;
1906 err = deflate(&stream, Z_FINISH);
1907 if (err == Z_STREAM_END) break;
1910 INFO_PRINTF2(_L("deflate error: %d"), err);
1911 deflateEnd(&stream);
1917 deflateEnd(&stream);
1924 * Function Name : TestInflateSetDictionaryBadMode
1925 * TestCase Description: Supply window bits=9 making state->mode = BAD
1926 * Return Value: Z_STREAM_ERROR
1928 TInt CTestZlib::TestInflateSetDictionaryBadMode()
1930 TInt res = KErrNone ;
1931 Byte *compr, *uncompr;
1932 uLong comprLen = 100*sizeof(int);
1933 uLong uncomprLen = comprLen;
1935 compr = (Byte*)calloc((uInt)comprLen, 1);
1936 if (compr == Z_NULL)
1938 return KErrNoMemory;
1940 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1941 if (uncompr == Z_NULL)
1944 return KErrNoMemory;
1946 res = Test_dict_deflate(compr, comprLen);
1958 z_stream d_stream; // decompression stream
1960 strcpy((char*)uncompr, "garbage");
1962 d_stream.zalloc = (alloc_func)0;
1963 d_stream.zfree = (free_func)0;
1964 d_stream.opaque = (voidpf)0;
1966 d_stream.next_in = compr;
1967 d_stream.avail_in = (uInt)comprLen;
1969 err = inflateInit2_(&d_stream, 9, "1.2.4", sizeof(d_stream));
1977 d_stream.next_out = uncompr;
1978 d_stream.avail_out = (uInt)uncomprLen;
1982 err = inflate(&d_stream, Z_NO_FLUSH);
1983 err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,sizeof(dictionary));
1984 if(err == Z_STREAM_ERROR)
1991 err = inflateEnd(&d_stream);
1992 } // end of outer if
2004 * Function Name : TestInflateSetDictionaryStreamStateNull
2005 * TestCase Description: Make stream->state = Z_NULL
2006 * Return Value: Z_STREAM_ERROR
2008 TInt CTestZlib::TestInflateSetDictionaryStreamStateNull()
2010 TInt res = KErrNone ;
2011 Byte *compr, *uncompr;
2012 uLong comprLen = 100*sizeof(int);
2013 uLong uncomprLen = comprLen;
2015 compr = (Byte*)calloc((uInt)comprLen, 1);
2016 if (compr == Z_NULL)
2018 return KErrNoMemory;
2020 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
2021 if (uncompr == Z_NULL)
2024 return KErrNoMemory;
2026 res = Test_dict_deflate(compr, comprLen);
2038 z_stream d_stream; // decompression stream
2040 strcpy((char*)uncompr, "garbage");
2042 d_stream.zalloc = (alloc_func)0;
2043 d_stream.zfree = (free_func)0;
2044 d_stream.opaque = (voidpf)0;
2046 d_stream.next_in = compr;
2047 d_stream.avail_in = (uInt)comprLen;
2049 err = inflateInit2_(&d_stream, 15, "1.2.4", sizeof(d_stream));
2057 d_stream.next_out = uncompr;
2058 d_stream.avail_out = (uInt)uncomprLen;
2062 err = inflate(&d_stream, Z_NO_FLUSH);
2065 INFO_PRINTF1(_L("Inflate failed"));
2069 err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,sizeof(dictionary));
2070 if(err == Z_STREAM_ERROR)
2076 err = inflateEnd(&d_stream);
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)
2085 } // end of outer if
2097 * Function Name : TestDeflateParamsStreamStateNull
2098 * TestCase Description: Make stream state Z_NULL
2099 * Return Value: Z_STREAM_ERROR
2101 TInt CTestZlib::TestDeflateParamsStreamStateNull()
2103 TInt res = KErrNone ;
2104 z_stream c_stream; // compression stream
2108 uLong comprLen = 20*sizeof(int);
2110 compr=(Byte*)calloc((uInt)comprLen, 1);
2111 if (compr == Z_NULL)
2113 return KErrNoMemory;
2116 uLong len = (uLong)strlen(hello)+1;
2118 c_stream.zalloc = (alloc_func)0;
2119 c_stream.zfree = (free_func)0;
2120 c_stream.opaque = (voidpf)0;
2122 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
2129 c_stream.next_in = (Bytef*)hello;
2130 c_stream.next_out = compr;
2132 err= deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
2133 deflateEnd(&c_stream);
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);
2139 if(err == Z_STREAM_ERROR)
2153 * Function Name : TestInflateSyncAvailInNull
2154 * TestCase Description: Make avail in Z_NULL
2155 * Return Value: Z_BUF_ERROR
2157 TInt CTestZlib::TestInflateSyncAvailInNull()
2159 TInt res = KErrNone ;
2160 uLong len = (uLong)strlen(hello)+1;
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)
2168 return KErrNoMemory;
2170 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
2171 if (uncompr == Z_NULL)
2174 return KErrNoMemory;
2178 err = compress(compr, &comprLen, (const Bytef*)hello, len);
2196 return KErrNoMemory;
2199 Test_flush(compr, &comprLen);
2201 z_stream d_stream; /* decompression stream */
2203 strcpy((char*)uncompr, "garbage");
2205 d_stream.zalloc = (alloc_func)0;
2206 d_stream.zfree = (free_func)0;
2207 d_stream.opaque = (voidpf)0;
2209 d_stream.next_in = compr;
2210 d_stream.avail_in = 2; /* just read the zlib header */
2212 err = inflateInit(&d_stream);
2219 d_stream.next_out = uncompr;
2220 d_stream.avail_out = (uInt)uncomprLen;
2222 err=inflate(&d_stream, Z_NO_FLUSH);
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)
2238 err = inflateEnd(&d_stream);
2241 INFO_PRINTF1(_L("Error encountered in inflateEnd"));
2248 * Function Name : TestInflateSyncStreamNull
2249 * TestCase Description: Pass NULL stream to InflateSync
2250 * Return Value: Z_STREAM_ERROR
2252 TInt CTestZlib::TestInflateSyncStreamNull()
2254 TInt res = KErrNone ;
2255 uLong len = (uLong)strlen(hello)+1;
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)
2263 return KErrNoMemory;
2265 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
2266 if (uncompr == Z_NULL)
2269 return KErrNoMemory;
2273 err = compress(compr, &comprLen, (const Bytef*)hello, len);
2291 return KErrNoMemory;
2294 Test_flush(compr, &comprLen);
2296 z_stream d_stream; /* decompression stream */
2298 strcpy((char*)uncompr, "garbage");
2300 d_stream.zalloc = (alloc_func)0;
2301 d_stream.zfree = (free_func)0;
2302 d_stream.opaque = (voidpf)0;
2304 d_stream.next_in = compr;
2305 d_stream.avail_in = 2; /* just read the zlib header */
2307 err = inflateInit(&d_stream);
2313 d_stream.next_out = uncompr;
2314 d_stream.avail_out = (uInt)uncomprLen;
2316 err=inflate(&d_stream, Z_NO_FLUSH);
2322 d_stream.avail_in = (uInt)comprLen-2;
2324 // Make stream Z_NULL
2325 err = inflateSync(Z_NULL);
2326 if(err == Z_STREAM_ERROR)
2330 err = inflateEnd(&d_stream);
2333 INFO_PRINTF1(_L("Error encountered in inflateEnd"));
2342 * Function Name : TestInflateSyncStreamStateNull
2343 * TestCase Description: Make stream state = Z_NULL
2344 * Return Value: Z_STREAM_ERROR
2346 TInt CTestZlib::TestInflateSyncStreamStateNull()
2348 TInt res = KErrNone ;
2349 uLong len = (uLong)strlen(hello)+1;
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)
2357 return KErrNoMemory;
2359 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
2360 if (uncompr == Z_NULL)
2363 return KErrNoMemory;
2367 err = compress(compr, &comprLen, (const Bytef*)hello, len);
2385 return KErrNoMemory;
2388 Test_flush(compr, &comprLen);
2390 z_stream d_stream; /* decompression stream */
2392 strcpy((char*)uncompr, "garbage");
2394 d_stream.zalloc = (alloc_func)0;
2395 d_stream.zfree = (free_func)0;
2396 d_stream.opaque = (voidpf)0;
2398 d_stream.next_in = compr;
2399 d_stream.avail_in = 2; /* just read the zlib header */
2401 err = inflateInit(&d_stream);
2406 d_stream.next_out = uncompr;
2407 d_stream.avail_out = (uInt)uncomprLen;
2408 err=inflate(&d_stream, Z_NO_FLUSH);
2414 d_stream.avail_in = (uInt)comprLen-2;
2415 err = inflateSync(&d_stream);
2416 err = inflateEnd(&d_stream);
2419 INFO_PRINTF1(_L("Error encountered in inflateEnd"));
2423 // for coverage improvement
2424 d_stream.state = Z_NULL;
2425 err = inflateSync(&d_stream);
2427 if(err == Z_STREAM_ERROR)
2437 * Function Name : TestInflateSyncPointStreamStateNull
2438 * TestCase Description: Make stream state = Z_NULL
2439 * Return Value: Z_STREAM_ERROR
2441 TInt CTestZlib::TestInflateSyncPointStreamStateNull()
2443 TInt res = KErrNone ;
2444 uLong len = (uLong)strlen(hello)+1;
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)
2452 return KErrNoMemory;
2454 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
2455 if (uncompr == Z_NULL)
2458 return KErrNoMemory;
2464 stream.next_in = (Bytef*)hello;
2465 stream.avail_in = (uInt)len;
2467 stream.next_out = compr;
2468 stream.avail_out = (uInt)comprLen;
2470 stream.zalloc = (alloc_func)0;
2471 stream.zfree = (free_func)0;
2472 stream.opaque = (voidpf)0;
2474 err = deflateInit(&stream, Z_DEFAULT_COMPRESSION);
2482 err = deflate(&stream, Z_FINISH);
2483 if (err != Z_STREAM_END)
2485 deflateEnd(&stream);
2488 return err == Z_OK ? Z_BUF_ERROR : err;
2490 comprLen = stream.total_out;
2492 err = inflateSyncPoint(&stream);
2493 err = deflateEnd(&stream);
2494 if(err == Z_STREAM_ERROR)
2496 INFO_PRINTF1(_L("Error encountered in inflateEnd"));
2502 //Make stream state NULL
2503 stream.state = Z_NULL;
2504 err = inflateSyncPoint(&stream);
2505 //err = inflateEnd(&stream);
2506 if(err == Z_STREAM_ERROR)
2518 * Function Name : TestAdlerScenarios
2519 * TestCase Description: 1. len = 1, adler > BASE
2520 * 2. len < 16, adler > BASE
2522 * Return Value: Adler value
2524 TInt CTestZlib::TestAdlerScenarios()
2526 TInt res = KErrNone ;
2527 //unsigned char buffer[5]="1234";
2528 unsigned char buffer[5552];
2532 _LIT(KParam1, "Param1");
2533 TBool ret = GetIntFromConfig(ConfigSection(), KParam1, adler1);
2536 INFO_PRINTF1(_L("Failed to read the values from ini file"));
2539 _LIT(KParam2, "Param2");
2540 ret = GetIntFromConfig(ConfigSection(), KParam2, len);
2543 INFO_PRINTF1(_L("Failed to read the values from ini file"));
2546 long long adler = adler32((long)adler1, &buffer[0], (unsigned int)len);
2547 INFO_PRINTF2(_L("buf %x"),adler);
2561 * Function Name : TestGzsetparamsFileNull
2562 * TestCase Description: Pass NULL pointer to gzsetparams
2563 * Return Value: Z_STREAM_ERROR
2565 TInt CTestZlib::TestGzsetparamsFileNull()
2567 TInt res = KErrNone ;
2569 int len = (int)strlen(hello)+1;
2572 const char * fname = TESTFILE;
2574 file = gzopen(fname, "wb");
2577 int err = gzsetparams(NULL, Z_BEST_SPEED, Z_DEFAULT_STRATEGY);
2578 if(err == Z_STREAM_ERROR)
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
2592 TInt CTestZlib::TestGzopenWrite()
2595 const char * fname = "c:\\file.txt";
2596 file = gzopen(fname, "wb");
2598 gzputs(file, "Coverage Improvement");
2602 file = gzopen(fname, "rb");
2606 ERR_PRINTF1(_L("gzopen error"));
2616 * Function Name : TestGzreadLargeFile
2617 * TestCase Description: Open a large gz file in read mode and read from it
2619 TInt CTestZlib::TestGzreadLargeFile()
2623 uInt len = strlen(s);
2625 char *buf1 = (char*)malloc(1024);
2628 return KErrNoMemory;
2631 file = gzopen(FILETESTGZLARGE, "rb");
2634 ERR_PRINTF1(_L("gzopen error"));
2641 len = gzread(file, buf1, sizeof(buf1));
2651 * Function Name : TestGzopenWriteNoPath
2652 * TestCase Description: Open a gz file in write mode,
2653 * close it and then open again in read mode
2655 TInt CTestZlib::TestGzopenWriteNoPath()
2658 const char * fname = "c:\\file.txt";
2659 file = gzopen(fname, "wb");
2661 gzputs(file, "Coverage Improvement");
2665 file = gzopen(fname, "rb");
2669 ERR_PRINTF1(_L("gzopen error"));
2677 * Function Name : TestGzreadLenZero
2678 * TestCase Description: 1. Read from a gz file specifying read buffer length=0
2680 TInt CTestZlib::TestGzreadLenZero()
2682 char * buf1 = (char*)malloc(1024);
2685 ERR_PRINTF1(_L("Heap out of memory"));
2686 return KErrNoMemory;
2689 TInt res = KErrNone ;
2692 const char * fname = "c:\\file.txt";
2694 // Write some text in gz file and close it
2695 file = gzopen(fname, "wb");
2699 ERR_PRINTF1(_L("Could not open the file"));
2703 gzputs(file, "Coverage Improvement");
2706 file = gzopen(fname, "rb");
2710 ERR_PRINTF1(_L("Could not open the file"));
2717 len = gzread(file, buf1, len);
2721 if (gzclose(file) != Z_OK)
2723 ERR_PRINTF1(_L("Could not close the file"));
2732 * Function Name : TestGzreadBufZero
2733 * TestCase Description: 1. Read from a gz file passing a NULL for read buffer
2735 TInt CTestZlib::TestGzreadBufZero()
2737 char * buf1 = (char*)malloc(1024);
2740 ERR_PRINTF1(_L("Heap out of memory"));
2741 return KErrNoMemory;
2744 TInt res = KErrNone ;
2747 const char * fname = "c:\\file.txt";
2749 // Write some text in gz file and close it
2750 file = gzopen(fname, "wb");
2754 ERR_PRINTF1(_L("Could not open the file"));
2758 gzputs(file, "Coverage Improvement");
2761 file = gzopen(fname, "rb");
2765 ERR_PRINTF1(_L("Could not open the file"));
2772 len = gzread(file, NULL, sizeof(buf1));
2776 if (gzclose(file) == Z_STREAM_ERROR)
2786 * Function Name : TestGzreadNonGzFile
2787 * TestCase Description: 1. Read from a non gz file
2789 TInt CTestZlib::TestGzreadNonGzFile()
2791 char *buf1 = (char*)malloc(1024);
2794 ERR_PRINTF1(_L("Heap out of memory"));
2795 return KErrNoMemory;
2798 TInt res = KErrNone ;
2801 const char * fname = "c:\\file.txt";
2803 // Write in txt file and close it
2804 FILE *fp = fopen(fname,"w");
2808 ERR_PRINTF1(_L("Could not open the output file."));
2816 file = gzopen(fname, "rb");
2820 ERR_PRINTF1(_L("Could not open the file"));
2827 len = gzread(file, buf1, sizeof(buf1));
2831 if (gzclose(file) == Z_STREAM_ERROR)
2840 * Function Name : TestGzrewindNonGzFile
2841 * TestCase Description: 1. Rewind in a non gz file
2843 TInt CTestZlib::TestGzrewindNonGzFile()
2845 TInt res = KErrNone ;
2847 int len = (int)strlen(hello)+1;
2849 const char * fname = "c:\\file.txt";
2852 fp=fopen(fname,"w");
2856 file = gzopen(fname, "rb");
2861 err = gzrewind(file);
2881 * Function Name : TestGzrewindFileNull
2882 * TestCase Description: Pass NULL to gzrewind
2884 TInt CTestZlib::TestGzrewindFileNull()
2886 TInt res = KErrNone ;
2888 int len = (int)strlen(hello)+1;
2891 const char * fname = TESTFILE;
2892 file = gzopen(fname, "rb");
2897 err = gzrewind(NULL);
2917 * Function Name : TestGzflushWithZFinish
2918 * TestCase Description: Flush with flush = Z_FINISH
2920 TInt CTestZlib::TestGzflushWithZFinish()
2922 TInt res = KErrNone ;
2925 const char * fname = TESTFILE ;
2926 file = gzopen(fname, "wb");
2932 int l= gzflush(file,Z_FINISH);
2947 * Function Name : TestUncompressLenSmall
2948 * TestCase Description: Supply uncompress length smaller than compress length
2949 * Return value: Z_BUF_ERROR
2951 TInt CTestZlib::TestUncompressLenSmall()
2953 TInt res = KErrNone;
2955 Byte *compr, *uncompr;
2956 uLong len = (uLong)strlen(hello)+1;
2958 uLong comprLen = 20*sizeof(int);
2959 uLong uncomprLen = 3*sizeof(int);
2960 compr = (Byte*)calloc((uInt)comprLen, 1);
2961 if (compr == Z_NULL)
2963 return KErrNoMemory;
2966 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
2967 if (uncompr == Z_NULL)
2970 return KErrNoMemory;
2973 err = compress(compr, &comprLen, (const Bytef*)hello, len);
2976 strcpy((char*)uncompr, "garbage");
2977 err = uncompress(uncompr, &uncomprLen, compr, comprLen);
2978 if(err == Z_BUF_ERROR)
2994 * Function Name : TestUncompressBufNull
2995 * TestCase Description: Supply NULL string to uncompress
2996 * Return value: Z_STREAM_ERROR
2998 TInt CTestZlib::TestUncompressBufNull()
3000 TInt res = KErrNone;
3002 Byte *compr, *uncompr;
3003 uLong len = (uLong)strlen(hello)+1;
3005 uLong comprLen = 20*sizeof(int);
3006 uLong uncomprLen = 3*sizeof(int);
3007 compr = (Byte*)calloc((uInt)comprLen, 1);
3008 if (compr == Z_NULL)
3010 return KErrNoMemory;
3013 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3014 if (uncompr == Z_NULL)
3017 return KErrNoMemory;
3020 err = compress(compr, &comprLen, (const Bytef*)hello, len);
3023 strcpy((char*)uncompr, "garbage");
3024 err = uncompress(uncompr, &uncomprLen, Z_NULL, comprLen);
3025 if(err == Z_STREAM_ERROR)
3042 * Function Name : TestUncompressLenNull
3043 * TestCase Description: Supply uncompress length=0
3044 * Return value: Z_DATA_ERROR
3046 TInt CTestZlib::TestUncompressLenNull()
3048 TInt res = KErrNone;
3050 Byte *compr, *uncompr;
3051 uLong len = (uLong)strlen(hello)+1;
3053 uLong comprLen = 20*sizeof(int);
3054 uLong uncomprLen = 3*sizeof(int);
3055 compr = (Byte*)calloc((uInt)comprLen, 1);
3056 if (compr == Z_NULL)
3058 return KErrNoMemory;
3061 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3062 if (uncompr == Z_NULL)
3065 return KErrNoMemory;
3068 err = compress(compr, &comprLen, (const Bytef*)hello, len);
3071 strcpy((char*)uncompr, "garbage");
3072 err = uncompress(uncompr, &uncomprLen, compr, 0);
3073 if(err == Z_DATA_ERROR)
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
3096 TInt CTestZlib::TestInflateScenarios()
3098 TInt res = KErrNone ;
3099 TInt WindowBits = 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)
3107 return KErrNoMemory;
3109 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3110 if (uncompr == Z_NULL)
3113 return KErrNoMemory;
3115 res = Test_deflate(compr, comprLen);
3120 return KErrNoMemory;
3124 z_stream d_stream; /* decompression stream */
3126 strcpy((char*)uncompr, "garbage");
3128 d_stream.zalloc = (alloc_func)0;
3129 d_stream.zfree = (free_func)0;
3130 d_stream.opaque = (voidpf)0;
3132 d_stream.next_in = compr;
3133 d_stream.avail_in = 0;
3134 d_stream.next_out = uncompr;
3136 ReadIntParam(WindowBits);
3137 res = inflateInit2_(&d_stream, WindowBits, "1.2.4", sizeof(d_stream));
3143 return KErrNoMemory;
3146 ReadIntParam(flush);
3147 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
3149 d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
3150 err = inflate(&d_stream, flush);
3152 if (err == Z_STREAM_END || err == Z_MEM_ERROR || err == Z_DATA_ERROR) break;
3154 if(err == Z_MEM_ERROR)
3156 err = inflateEnd(&d_stream);
3163 err = inflateEnd(&d_stream);
3180 * Function Name : TestInflateStreamStateNull
3181 * TestCase Description: Make stream.state = NULL and call inflate
3182 * Return Value: Z_STREAM_ERROR
3184 TInt CTestZlib::TestInflateStreamStateNull()
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)
3193 return KErrNoMemory;
3195 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3196 if (uncompr == Z_NULL)
3199 return KErrNoMemory;
3201 res = Test_deflate(compr, comprLen);
3206 return KErrNoMemory;
3210 z_stream d_stream; /* decompression stream */
3212 strcpy((char*)uncompr, "garbage");
3214 d_stream.zalloc = (alloc_func)0;
3215 d_stream.zfree = (free_func)0;
3216 d_stream.opaque = (voidpf)0;
3218 d_stream.next_in = compr;
3219 d_stream.avail_in = 0;
3220 d_stream.next_out = uncompr;
3222 res = inflateInit2_(&d_stream, 15, "1.2.4", sizeof(d_stream));
3228 return KErrNoMemory;
3231 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
3233 d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
3234 err = inflate(&d_stream, Z_SYNC_FLUSH);
3236 if (err == Z_STREAM_END || err == Z_STREAM_ERROR || err == Z_MEM_ERROR) break;
3239 if(err == Z_STREAM_ERROR)
3243 err = inflateEnd(&d_stream);
3244 if (err == Z_STREAM_ERROR)
3249 d_stream.state = Z_NULL;
3250 err = inflate(&d_stream, Z_SYNC_FLUSH);
3251 if (err == Z_STREAM_ERROR)
3262 * Function Name : TestInflateResetStreamStateNull
3263 * TestCase Description: Make stream.state = NULL and call inflateReset
3264 * Return Value: Z_STREAM_ERROR
3266 TInt CTestZlib::TestInflateResetStreamStateNull()
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;
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)
3281 return KErrNoMemory;
3283 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3284 if (uncompr == Z_NULL)
3287 return KErrNoMemory;
3290 res = Test_deflate(compr, comprLen);
3295 return KErrNoMemory;
3297 d_stream.next_in = compr;
3298 d_stream.avail_in = 0;
3299 d_stream.next_out = uncompr;
3300 version=zlibVersion();
3302 err = inflateInit_(&d_stream,(char*)version, sizeof(d_stream));
3308 return KErrNoMemory;
3311 err=inflateReset(&d_stream);
3312 err=inflateEnd(&d_stream);
3316 // for coverage improvement
3317 d_stream.state = Z_NULL;
3318 err=inflateReset(&d_stream);
3320 if(err == Z_STREAM_ERROR)