First public contribution.
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 * Function Name : TestAdlerinit
23 * TestCase Description: Testing Adler
24 * Return Value: Return KErrNone if adler32=1, else return KErrGeneral
26 TInt CTestZlib::TestAdlerinit()
31 long adler1 = adler32(j,0, 0);
44 * Function Name : TestAdler
45 * TestCase Description: Testing Adler32
46 * Return Value: Return KErrNone if adler32>0, else return KErrGeneral
48 TInt CTestZlib::TestAdler()
51 unsigned char buffer[5]="1234";
55 long adler1 = adler32(j,0, 0);
56 long adler = adler32(adler1, &buffer[0], i);
57 INFO_PRINTF2(_L("buf %x"),adler);
71 * Function Name : TestDeflateReset
72 * TestCase Description: Call deflateReset after deflateInit
73 * Return Value: Returns KErrNone on deflateReset returning Z_OK, else KErrGeneral
75 TInt CTestZlib::TestDeflateReset()
77 INFO_PRINTF1(_L("DeflateReset test with valid input"));
79 int level = Z_DEFAULT_COMPRESSION ;
80 uLong len = (uLong)strlen(hello)+1;
81 Byte *compr, *uncompr;
82 uLong comprLen = 20*sizeof(int);
83 uLong uncomprLen = comprLen;
86 compr = (Byte*)calloc((uInt)comprLen, 1);
91 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
92 if (uncompr == Z_NULL)
98 stream.zalloc = (alloc_func)0;
99 stream.zfree = (free_func)0;
100 stream.opaque = (voidpf)0;
102 err = deflateInit(&stream, level);
110 Bytef *dest = compr ;
111 uLongf *destLen = &comprLen;
112 const Bytef *source = (const Bytef*)hello;
113 uLong sourceLen = len;
115 stream.next_in = (Bytef*)source;
116 stream.avail_in = (uInt)sourceLen;
118 /* Check for source > 64K on 16-bit machine: */
119 if ((uLong)stream.avail_in != sourceLen)
124 stream.next_out = dest;
125 stream.avail_out = (uInt)*destLen;
126 if ((uLong)stream.avail_out != *destLen)
130 err=deflateReset(&stream);
139 err = deflateEnd(&stream);
142 INFO_PRINTF1(_L("Error in deflateEnd"));
153 * Function Name : TestDeflateReset_fail
154 * TestCase Description: Call deflateReset before calling deflateInit
155 * Return Value: Return KErrNone incase of deflateReset returning Z_STREAM_ERROR, else KErrGeneral
157 TInt CTestZlib::TestDeflateReset_fail()
159 TInt res = KErrNone ;
160 uLong len = (uLong)strlen(hello)+1;
161 Byte *compr, *uncompr;
162 uLong comprLen = 20*sizeof(int);
163 uLong uncomprLen = comprLen;
166 compr = (Byte*)calloc((uInt)comprLen, 1);
171 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
172 if (uncompr == Z_NULL)
178 stream.zalloc = (alloc_func)0;
179 stream.zfree = (free_func)0;
180 stream.opaque = (voidpf)0;
181 err=deflateReset(&stream);
196 * Function Name : TestDeflateInit2_bits
197 * TestCase Description: Call deflateInit2_ with window bits = 15 as argument
198 * Return Value: Return KErrNone if deflateInit2_ returns Z_OK
200 TInt CTestZlib::TestDeflateInit2_bits()
202 TInt res = KErrNone ;
205 int level=Z_DEFAULT_COMPRESSION;
207 uLong sourceLen = (uLong)strlen(hello)+1;
209 uLong comprLen = 10*sizeof(int);
210 compr = (Byte*)calloc((uInt)comprLen, 1);
215 stream.zalloc = (alloc_func)0;
216 stream.zfree = (free_func)0;
217 stream.opaque = (voidpf)0;
219 err= deflateInit2_(&stream, level, 3, 15, 8, 0, zlibVersion(), sizeof(z_stream));
234 * Function Name : TestDeflateInit2_level
235 * TestCase Description: Call deflateInit2_ with window bits = 2 as argument
236 * Return Value: Returns KErrNone on deflateInit2_ returning Z_OK
238 TInt CTestZlib::TestDeflateInit2_level()
240 TInt res = KErrNone ;
243 int level=Z_DEFAULT_COMPRESSION;
245 uLong sourceLen = (uLong)strlen(hello)+1;
247 uLong comprLen = 10*sizeof(int);
248 compr = (Byte*)calloc((uInt)comprLen, 1);
254 stream.zalloc = (alloc_func)0;
255 stream.zfree = (free_func)0;
256 stream.opaque = (voidpf)0;
258 err= deflateInit2_(&stream, level, 3, 2, 8,
259 0, zlibVersion(), sizeof(z_stream));
274 * Function Name : TestInflateInit2_bits
275 * TestCase Description: Call inflateInit2_ with window bits = 5 as argument
276 * Return Value: Returns KErrNone on inflateInit2_ returning Z_OK
278 TInt CTestZlib::TestInflateInit2_bits()
280 TInt res = KErrNone ;
281 z_stream d_stream; // decompression stream
282 const char * version;
283 d_stream.zalloc = (alloc_func)0;
284 d_stream.zfree = (free_func)0;
285 d_stream.opaque = (voidpf)0;
287 version = zlibVersion();
288 int ret = inflateInit2_(&d_stream,5,version, sizeof(d_stream));
301 * Function Name : TestGzread
302 * TestCase Description: 1. Open a gz file in read mode
303 * 2. gzRead from the opened file. Reads the given number of uncompressed bytes from the compressed file.
304 * 3. close the gz file
305 * Return Value: Returns KErrNone on reading the gzfile successfully
307 TInt CTestZlib::TestGzread()
309 char * buf1 = (char*)malloc(1024);
312 ERR_PRINTF1(_L("Heap out of memory"));
317 TInt res = KErrNone ;
318 char *file=FILETESTGZ;
322 in = gzopen(infile, "rb");
326 ERR_PRINTF1(_L("Could not open the file"));
332 len1 = gzread(in, buf1, sizeof(buf1));
337 INFO_PRINTF1(_L("Error in reading the file"));
342 if (gzclose(in) != Z_OK)
344 ERR_PRINTF1(_L("Could not close the file"));
352 * Function Name : TestGzread_fail
353 * TestCase Description: 1. Open a gz file in write mode
354 * 2. gzRead from the file.
356 * Return Value: Returns KErrNone on gzread returning -1
358 TInt CTestZlib::TestGzread_fail()
360 char * buf1 = (char*)malloc(1024);
366 TInt res = KErrNone ;
368 in = gzopen(FILETESTGZ1, "wb");
373 return KErrNoMemory;;
376 len1 = gzread(in, buf1, sizeof(buf1));
386 if (gzclose(in) != Z_OK)
389 INFO_PRINTF1(_L("Error encountered while closing the file"));
397 * Function Name : test_uncompress
398 * TestCase Description: This is a global function used by many test functions
400 TInt test_uncompress(Byte * compr,uLong comprLen,Byte * uncompr,uLong uncomprLen)
402 TInt res = KErrNone ;
404 uLong len = (uLong)strlen(hello)+1;
406 err = compress(compr, &comprLen, (const Bytef*)hello, len);
410 strcpy((char*)uncompr, "garbage");
411 err = uncompress(uncompr, &uncomprLen, compr, comprLen);
425 * Function Name : TestUncompress
426 * TestCase Description: 1. Compress a text sample
427 * 2. Uncompress is called with appropriate lengths
428 * for compressed and uncompressed data
432 TInt CTestZlib::TestUncompress()
434 TInt res = KErrNone ;
435 Byte *compr, *uncompr;
436 uLong comprLen = 20*sizeof(int);
437 uLong uncomprLen = comprLen;
438 compr = (Byte*)calloc((uInt)comprLen, 1);
443 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
444 if (uncompr == Z_NULL)
449 res = test_uncompress(compr, comprLen, uncompr, uncomprLen);
456 * Function Name : TestUncompressfail
457 * TestCase Description: 1. Uncompress is called with uncompressed length smaller than required
459 * Return Value: Z_BUF_ERROR
461 TInt CTestZlib::TestUncompressfail()
463 TInt res = KErrNone ;
464 Byte *compr, *uncompr;
465 uLong comprLen = 1*sizeof(int);
466 uLong uncomprLen = comprLen;
467 compr = (Byte*)calloc((uInt)comprLen, 1);
472 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
473 if (uncompr == Z_NULL)
478 int err = test_uncompress(compr, comprLen, uncompr, uncomprLen);
489 * Function Name : Test_dict_deflate
490 * TestCase Description: This is a global function used by many test functions
492 TInt CTestZlib::Test_dict_deflate( Byte * compr,uLong comprLen)
494 TInt res = KErrNone ;
495 z_stream c_stream; /* compression stream */
498 c_stream.zalloc = (alloc_func)0;
499 c_stream.zfree = (free_func)0;
500 c_stream.opaque = (voidpf)0;
502 err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
509 err = deflateSetDictionary(&c_stream,
510 (const Bytef*)dictionary, sizeof(dictionary));
516 dictId = c_stream.adler;
517 c_stream.next_out = compr;
518 c_stream.avail_out = (uInt)comprLen;
520 c_stream.next_in = (Bytef*)hello;
521 c_stream.avail_in = (uInt)strlen(hello)+1;
523 err = deflate(&c_stream, Z_FINISH);
524 if (err != Z_STREAM_END)
528 err = deflateEnd(&c_stream);
538 * Function Name : Test_dict_inflate
539 * TestCase Description: This is an utility function used by many test functions
541 TInt CTestZlib::Test_dict_inflate(Byte * compr,uLong comprLen, Byte * uncompr,uLong uncomprLen)
543 TInt res = KErrNone ;
545 z_stream d_stream; /* decompression stream */
547 strcpy((char*)uncompr, "garbage");
549 d_stream.zalloc = (alloc_func)0;
550 d_stream.zfree = (free_func)0;
551 d_stream.opaque = (voidpf)0;
553 d_stream.next_in = compr;
554 d_stream.avail_in = (uInt)comprLen;
556 err = inflateInit(&d_stream);
557 if(Z_MEM_ERROR == err)
561 else if(Z_VERSION_ERROR == err)
563 return Z_VERSION_ERROR;
566 d_stream.next_out = uncompr;
567 d_stream.avail_out = (uInt)uncomprLen;
571 err = inflate(&d_stream, Z_NO_FLUSH);
572 if (err == Z_NEED_DICT)
574 if (d_stream.adler != dictId)
578 err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
582 INFO_PRINTF1(_L("Error returned by inflateSetDictionary"));
592 err = inflateEnd(&d_stream);
593 if (strcmp((char*)uncompr, hello))
595 INFO_PRINTF1(_L("Bad inflate with dictionary"));
600 INFO_PRINTF1(_L("Inflate with dictionary successful"));
606 * Function Name : TestInflateSetDictionary
607 * TestCase Description: 1. Deflate string using an existing dictionary
608 * 2. Uncompress the compressed text using an existing dictionary
609 * Return Value: Z_BUF_ERROR
611 TInt CTestZlib::TestInflateSetDictionary()
613 TInt res = KErrNone ;
614 Byte *compr, *uncompr;
615 uLong comprLen = 100*sizeof(int);
616 uLong uncomprLen = comprLen;
618 compr = (Byte*)calloc((uInt)comprLen, 1);
623 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
624 if (uncompr == Z_NULL)
629 res = Test_dict_deflate(compr, comprLen);
638 res=Test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
651 * Function Name : TestInflateSetDictionary_size
652 * TestCase Description: 1. Deflate string using an existing dictionary
653 * 2. Uncompress the compresses text using a mismatching dictionary
654 * Return Value: Z_DATA_ERROR
656 TInt CTestZlib::TestInflateSetDictionary_size()
660 Byte *compr, *uncompr;
661 uLong comprLen = 20*sizeof(int);
662 uLong uncomprLen = comprLen;
663 z_stream d_stream; /* decompression stream */
665 compr = (Byte*)calloc((uInt)comprLen, 1);
670 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
671 if (uncompr == Z_NULL)
677 res = Test_dict_deflate(compr, comprLen);
685 strcpy((char*)uncompr, "garbage");
687 d_stream.zalloc = (alloc_func)0;
688 d_stream.zfree = (free_func)0;
689 d_stream.opaque = (voidpf)0;
691 d_stream.next_in = compr;
692 d_stream.avail_in = (uInt)comprLen;
694 int err = inflateInit(&d_stream);
696 d_stream.next_out = uncompr;
697 d_stream.avail_out = (uInt)uncomprLen;
701 int err = inflate(&d_stream, Z_NO_FLUSH);
702 if (err == Z_STREAM_END || err == Z_MEM_ERROR) break;
703 err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,sizeof(dictionary)+2);
704 if(Z_DATA_ERROR == err)
715 err = inflateEnd(&d_stream);
718 INFO_PRINTF1(_L("InflateEnd failed"));
730 * Function Name : TestInflateSetDictionary_null
731 * TestCase Description: 1. Deflate string using an existing dictionary
732 * 2. Pass null pointer to inflateSetDictionary
733 * Return Value: Z_DATA_ERROR
735 TInt CTestZlib::TestInflateSetDictionary_null()
738 Byte *compr, *uncompr;
739 uLong comprLen = 20*sizeof(int);
740 uLong uncomprLen = comprLen;
742 compr = (Byte*)calloc((uInt)comprLen, 1);
747 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
748 if (uncompr == Z_NULL)
754 res= Test_dict_deflate(compr, comprLen);
755 if(res == KErrGeneral)
761 int err = inflateSetDictionary(NULL, (const Bytef*)dictionary,sizeof(dictionary));
762 if(err != Z_STREAM_ERROR)
772 * Function Name : test_compress
773 * TestCase Description: This is a global function used by many test functions
775 TInt test_compress(Byte * compr,uLong comprLen,Byte * uncompr,uLong uncomprLen)
778 uLong len = (uLong)strlen(hello)+1;
780 err = compress(compr, &comprLen, (const Bytef*)hello, len);
786 strcpy((char*)uncompr, "garbage");
788 err = uncompress(uncompr, &uncomprLen, compr, comprLen);
794 if (strcmp((char*)uncompr, hello))
796 //INFO_PRINTF1(_L("Uncompressed string does not match with original string"));
807 * Function Name : test_gzgets
808 * TestCase Description: This is a global function used by many test functions
810 int test_gzgets(const char * fname, Byte * uncompr,uLong uncomprLen)
813 int len = (int)strlen(hello)+1;
816 file = gzopen(fname, "wb");
823 if (gzputs(file, "ello") != 4)
827 if (gzprintf(file, ", %s!", "hello") != 8)
831 err = gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
834 //INFO_PRINTF1(_L("Error returned by gzssek"));
838 file = gzopen(fname, "rb");
844 strcpy((char*)uncompr, "garbage");
845 if (gzread(file, uncompr, (unsigned)uncomprLen) != len)
848 if (strcmp((char*)uncompr, hello))
857 err = gzseek(file, -8L, SEEK_CUR);
860 //INFO_PRINTF1(_L("Error returned by gzssek"));
862 gzgets(file, (char*)uncompr, (int)uncomprLen);
864 if (strlen((char*)uncompr) != 7) // " hello!"
873 * Function Name : TestGzgets
874 * TestCase Description: 1. Open a gz compressed file in read mode
875 * 2. Read certain valid number of bytes from the compressed file
876 * Return Value: Returns read buffer
878 TInt CTestZlib::TestGzgets()
880 TInt res = KErrNone ;
881 Byte *compr, *uncompr;
882 uLong comprLen = 20*sizeof(int);
884 uLong uncomprLen = comprLen;
885 compr = (Byte*)calloc((uInt)comprLen, 1);
890 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
891 if (uncompr == Z_NULL)
897 res = test_compress(compr, comprLen, uncompr, uncomprLen);
904 int err=test_gzgets(MYFILE,uncompr, uncomprLen);
915 * Function Name : test_gzgetsfail
916 * TestCase Description: This is a global function used by many test functions
918 TInt test_gzgetsfail(const char * fname, Byte * uncompr,int uncomprLen)
920 TInt res = KErrNone ;
922 int len = (int)strlen(hello)+1;
925 file = gzopen(fname, "wb");
930 err = gzgets(file, (char*)uncompr, uncomprLen);
940 int err1= gzclose(file);
950 * Function Name : TestgzgetsFail
951 * TestCase Description: 1. Open a gz compressed file in read mode
952 * 2. Invalid number of bytes (negative number) for gzgets
953 * Return Value: Z_NULL
955 TInt CTestZlib::TestgzgetsFail()
957 TInt res = KErrNone ;
958 Byte *compr, *uncompr;
959 uLong comprLen = 20*sizeof(int);
960 uLong uncomprLen = comprLen;
961 compr = (Byte*)calloc((uInt)comprLen, 1);
966 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
967 if (uncompr == Z_NULL)
972 test_compress(compr, comprLen, uncompr, uncomprLen);
973 int ret= test_gzgetsfail(TESTFILE,uncompr, -1);
990 * Function Name : TestgzgetsopenFail
991 * TestCase Description: 1. Open a gz compressed file in read mode
992 * 2. Invalid number of bytes (negative number) for gzgets
993 * Return Value: KErrNone
995 TInt CTestZlib::TestgzgetsopenFail()
997 TInt res = KErrNone ;
999 Byte *compr, *uncompr;
1000 uLong comprLen = 20*sizeof(int);
1001 uLong uncomprLen = comprLen;
1002 compr = (Byte*)calloc((uInt)comprLen, 1);
1003 if (compr == Z_NULL)
1005 return KErrNoMemory;
1007 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1008 if (uncompr == Z_NULL)
1011 return KErrNoMemory;
1013 res=test_compress(compr, comprLen, uncompr, uncomprLen);
1018 return KErrNoMemory;
1020 int err = test_gzgetsfail(NOFILE,uncompr, uncomprLen);
1037 * Function Name : Test_deflate
1038 * TestCase Description: 1. Call deflateInit with valid arguments
1039 * 2. Call deflate with necessary valid arguments
1040 * Return Value: Z_OK
1042 TInt CTestZlib::Test_deflate( Byte *compr, uLong comprLen)
1044 TInt res = KErrNone ;
1045 z_stream c_stream; /* compression stream */
1047 uLong len = (uLong)strlen(hello)+1;
1049 c_stream.zalloc = (alloc_func)0;
1050 c_stream.zfree = (free_func)0;
1051 c_stream.opaque = (voidpf)0;
1053 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
1059 c_stream.next_in = (Bytef*)hello;
1060 c_stream.next_out = compr;
1062 while (c_stream.total_in != len && c_stream.total_out < comprLen)
1064 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
1065 err = deflate(&c_stream, Z_NO_FLUSH);
1067 /* Finish the stream, still forcing small buffers: */
1070 c_stream.avail_out = 1;
1071 err = deflate(&c_stream, Z_FINISH);
1072 if (err == Z_STREAM_END) break;
1078 err = deflateEnd(&c_stream);
1088 * Function Name : TestInflate
1089 * TestCase Description: 1. Compress the data using deflate
1090 * 2. inflateInit to initialize internal stream state for decompression
1091 * 3. inflate with necessary valid arguments
1092 * Return Value: Z_OK
1094 TInt CTestZlib::TestInflate()
1096 TInt res = KErrNone ;
1097 Byte *compr, *uncompr;
1098 uLong comprLen = 20*sizeof(int);
1099 uLong uncomprLen = comprLen;
1100 compr = (Byte*)calloc((uInt)comprLen, 1);
1101 if (compr == Z_NULL)
1103 return KErrNoMemory;
1105 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1106 if (uncompr == Z_NULL)
1109 return KErrNoMemory;
1111 // test_compress_positive(compr, comprLen, uncompr, uncomprLen);
1112 res = Test_deflate(compr, comprLen);
1117 return KErrNoMemory;
1121 z_stream d_stream; /* decompression stream */
1123 strcpy((char*)uncompr, "garbage");
1125 d_stream.zalloc = (alloc_func)0;
1126 d_stream.zfree = (free_func)0;
1127 d_stream.opaque = (voidpf)0;
1129 d_stream.next_in = compr;
1130 d_stream.avail_in = 0;
1131 d_stream.next_out = uncompr;
1133 res = inflateInit(&d_stream);
1139 return KErrNoMemory;
1141 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
1143 d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
1144 err = inflate(&d_stream, Z_SYNC_FLUSH);
1146 if (err == Z_STREAM_END || err == Z_MEM_ERROR) break;
1148 //inflate() should normally be called until it returns Z_STREAM_END
1150 if(err == Z_MEM_ERROR)
1152 err = inflateEnd(&d_stream);
1157 err = inflateEnd(&d_stream);
1174 * Function Name : TestInflate_fail1
1175 * TestCase Description: 1. Compress the data using deflate
1176 * 2. inflateInit to initialize internal stream state for decompression
1177 * 3. Set avail_in = 0 and call inflate
1178 * Return Value: Z_STREAM_ERROR
1180 TInt CTestZlib::TestInflate_fail1()
1182 TInt res = KErrNone ;
1183 Byte *compr, *uncompr;
1184 uLong comprLen = 20*sizeof(int);
1185 uLong uncomprLen = comprLen;
1186 compr = (Byte*)calloc((uInt)comprLen, 1);
1187 if (compr == Z_NULL)
1189 return KErrNoMemory;
1191 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1192 if (uncompr == Z_NULL)
1195 return KErrNoMemory;
1198 // test_compress_positive(compr, comprLen, uncompr, uncomprLen);
1199 res = Test_deflate(compr, comprLen);
1204 return KErrNoMemory;
1208 z_stream d_stream; /* decompression stream */
1210 strcpy((char*)uncompr, "garbage");
1212 d_stream.zalloc = (alloc_func)0;
1213 d_stream.zfree = (free_func)0;
1214 d_stream.opaque = (voidpf)0;
1216 d_stream.next_in = compr;
1217 d_stream.avail_in = 0;
1218 d_stream.next_out = NULL;
1220 err = inflateInit(&d_stream);
1222 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
1224 d_stream.avail_in = 0;
1225 d_stream.avail_out = 1; /* force small buffers */
1226 err = inflate(&d_stream, Z_NO_FLUSH);
1227 if (err == Z_STREAM_ERROR) break;
1229 //inflate() should normally be called until it returns Z_STREAM_END
1231 err = inflateEnd(&d_stream);
1247 * Function Name : TestInflate_fail1
1248 * TestCase Description: 1. Compress the sample data using deflate
1249 * 2. Call inflateInit to initialize internal stream state for decompression
1250 * 3. Pass Z_NULL to inflate
1251 * Return Value: Z_STREAM_ERROR
1253 TInt CTestZlib::TestInflate_fail2()
1255 TInt res = KErrNone ;
1256 Byte *compr, *uncompr;
1257 uLong comprLen = 20*sizeof(int);
1258 uLong uncomprLen = comprLen;
1259 compr = (Byte*)calloc((uInt)comprLen, 1);
1260 if (compr == Z_NULL)
1262 return KErrNoMemory;
1264 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1265 if (uncompr == Z_NULL)
1268 return KErrNoMemory;
1270 res = Test_deflate(compr, comprLen);
1275 return KErrNoMemory;
1279 z_stream d_stream; /* decompression stream */
1281 strcpy((char*)uncompr, "garbage");
1283 d_stream.zalloc = (alloc_func)0;
1284 d_stream.zfree = (free_func)0;
1285 d_stream.opaque = (voidpf)0;
1287 d_stream.next_in = compr;
1288 d_stream.avail_in = 0;
1289 d_stream.next_out = uncompr;
1291 err = inflateInit(&d_stream);
1293 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
1295 d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
1296 err = inflate(NULL, Z_NO_FLUSH);
1297 if (err == Z_STREAM_ERROR) break;
1299 //inflate() should normally be called until it returns Z_STREAM_END
1300 err = inflateEnd(&d_stream);
1316 * Function Name : TestInflate_fail3
1317 * TestCase Description: 1. Compress the sample data using deflate
1318 * 2. Call inflateInit to initialize internal stream state for decompression
1319 * 3. Set avail_out = 0 and call inflate with necessary valid arguments
1320 * Return Value: Z_STREAM_ERROR
1322 TInt CTestZlib::TestInflate_fail3()
1324 TInt res = KErrNone ;
1325 Byte *compr, *uncompr;
1326 uLong comprLen = 20*sizeof(int);
1327 uLong uncomprLen = comprLen;
1328 compr = (Byte*)calloc((uInt)comprLen, 1);
1329 if (compr == Z_NULL)
1331 return KErrNoMemory;
1333 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1334 if (uncompr == Z_NULL)
1337 return KErrNoMemory;
1339 res = Test_deflate(compr, comprLen);
1344 return KErrNoMemory;
1348 z_stream d_stream; /* decompression stream */
1350 strcpy((char*)uncompr, "garbage");
1352 d_stream.zalloc = (alloc_func)0;
1353 d_stream.zfree = (free_func)0;
1354 d_stream.opaque = (voidpf)0;
1356 d_stream.next_in = NULL;
1357 d_stream.avail_in = 0;
1358 d_stream.next_out = uncompr;
1360 err = inflateInit(&d_stream);
1362 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
1364 d_stream.avail_in = 1;
1365 d_stream.avail_out = 0; /* force small buffers */
1366 err = inflate(&d_stream, Z_NO_FLUSH);
1367 if (err == Z_STREAM_ERROR) break;
1369 //inflate() should normally be called until it returns Z_STREAM_END
1371 err = inflateEnd(&d_stream);
1387 * Function Name : test_compress_positive
1388 * TestCase Description: This is a global function used by many test functions
1390 TInt test_compress_positive(Byte * compr,uLong comprLen,Byte * /*uncompr*/,uLong /*uncomprLen*/)
1392 TInt res = KErrNone ;
1394 uLong len = (uLong)strlen(hello)+1;
1396 err = compress(compr, &comprLen, (const Bytef*)hello, len);
1414 * Function Name : test_inflateend_positive
1415 * TestCase Description: This is a global function used by many test functions
1417 TInt test_inflateend_positive(Byte * compr,uLong comprLen,Byte * uncompr,uLong uncomprLen)
1419 TInt res = KErrNone ;
1421 z_stream d_stream; // decompression stream
1423 strcpy((char*)uncompr, "garbage");
1425 d_stream.zalloc = (alloc_func)0;
1426 d_stream.zfree = (free_func)0;
1427 d_stream.opaque = (voidpf)0;
1429 d_stream.next_in = compr;
1430 d_stream.avail_in = 0;
1431 d_stream.next_out = uncompr;
1433 err = inflateInit(&d_stream);
1436 return KErrNoMemory;
1439 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
1441 d_stream.avail_in = d_stream.avail_out = 1; // force small buffers
1442 err = inflate(&d_stream, Z_NO_FLUSH);
1443 if (err == Z_STREAM_END) break;
1447 err = inflateEnd(&d_stream);
1461 * Function Name : TestInflateend
1462 * TestCase Description: 1. Compress the sample data using deflate
1463 * 2. inflate to decompress the data
1465 * Return Value: Z_OK
1467 TInt CTestZlib::TestInflateend()
1469 TInt res = KErrNone ;
1470 Byte *compr, *uncompr;
1471 uLong comprLen = 20*sizeof(int);
1472 uLong uncomprLen = comprLen;
1473 compr = (Byte*)calloc((uInt)comprLen, 1);
1474 if (compr == Z_NULL)
1476 return KErrNoMemory;
1478 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1479 if (uncompr == Z_NULL)
1482 return KErrNoMemory;
1484 res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
1489 return KErrNoMemory;
1491 res = Test_deflate(compr, comprLen);
1496 return KErrNoMemory;
1498 res = test_inflateend_positive(compr, comprLen, uncompr, uncomprLen);
1519 * Function Name : TestInflateend_fail
1520 * TestCase Description: 1. Compress the sample data using deflate
1521 * 2. inflate to decompress the data
1522 * 3. Pass Z_NULL as argument to inflateEnd
1523 * Return Value: Z_STREAM_ERROR
1525 TInt CTestZlib::TestInflateend_fail()
1527 TInt res = KErrNone ;
1528 Byte *compr, *uncompr;
1529 uLong comprLen = 20*sizeof(int);
1530 uLong uncomprLen = comprLen;
1531 compr = (Byte*)calloc((uInt)comprLen, 1);
1532 if (compr == Z_NULL)
1534 return KErrNoMemory;
1536 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1537 if (uncompr == Z_NULL)
1540 return KErrNoMemory;
1542 res=test_compress(compr, comprLen, uncompr, uncomprLen);
1547 return KErrNoMemory;
1549 res = Test_deflate(compr, comprLen);
1554 return KErrNoMemory;
1556 int ret= inflateEnd(NULL);
1571 * Function Name : TestInflateReset
1572 * TestCase Description: 1. Compress the sample data using deflate
1573 * 2. Call inflateInit to initialize internal stream state for decompression
1574 * 3. Call inflateReset with valid arguments
1575 * Return Value: Z_OK
1577 TInt CTestZlib::TestInflateReset()
1580 z_stream d_stream; /* decompression stream */
1581 const char * version;
1582 d_stream.zalloc = (alloc_func)0;
1583 d_stream.zfree = (free_func)0;
1584 d_stream.opaque = (voidpf)0;
1586 Byte *compr, *uncompr;
1587 uLong comprLen = 20*sizeof(int);
1588 uLong uncomprLen = comprLen;
1589 compr = (Byte*)calloc((uInt)comprLen, 1);
1590 if (compr == Z_NULL)
1592 return KErrNoMemory;
1594 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1595 if (uncompr == Z_NULL)
1598 return KErrNoMemory;
1601 res = Test_deflate(compr, comprLen);
1606 return KErrNoMemory;
1608 d_stream.next_in = compr;
1609 d_stream.avail_in = 0;
1610 d_stream.next_out = uncompr;
1611 version=zlibVersion();
1613 err = inflateInit_(&d_stream,(char*)version, sizeof(d_stream));
1618 return KErrNoMemory;
1621 err=inflateReset(&d_stream);
1624 inflateEnd(&d_stream);
1627 return KErrNoMemory;
1635 res=inflateEnd(&d_stream);
1641 * Function Name : TestInflateResetfail1
1642 * TestCase Description: 1. Compress the sample data using deflate
1643 * 2. Call inflateInit to initialize internal stream state for decompression
1644 * 3. Pass Z_NULL as argument to inflateReset
1645 * Return Value: Z_STREAM_ERROR
1647 TInt CTestZlib::TestInflateResetfail1()
1650 z_stream d_stream; /* decompression stream */
1651 const char * version;
1652 d_stream.zalloc = (alloc_func)0;
1653 d_stream.zfree = (free_func)0;
1654 d_stream.opaque = (voidpf)0;
1656 Byte *compr, *uncompr;
1657 uLong comprLen = 20*sizeof(int);
1658 uLong uncomprLen = comprLen;
1659 compr = (Byte*)calloc((uInt)comprLen, 1);
1660 if (compr == Z_NULL)
1662 return KErrNoMemory;
1664 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1665 if (uncompr == Z_NULL)
1668 return KErrNoMemory;
1671 res = Test_deflate(compr, comprLen);
1676 return KErrNoMemory;
1678 d_stream.next_in = compr;
1679 d_stream.avail_in = 0;
1680 d_stream.next_out = uncompr;
1681 version=zlibVersion();
1682 inflateInit_(&d_stream,(char*)version, sizeof(d_stream));
1683 res=inflateReset(NULL);
1684 if(res!=Z_STREAM_ERROR)
1688 res=inflateEnd(&d_stream);
1699 * Function Name : TestInflateInit2_
1700 * TestCase Description: Test inflateInit2_
1701 * Return Value: Z_OK
1703 TInt CTestZlib::TestInflateInit2_()
1705 TInt res = KErrNone ;
1706 z_stream d_stream; // decompression stream
1707 const char * version;
1708 d_stream.zalloc = (alloc_func)0;
1709 d_stream.zfree = (free_func)0;
1710 d_stream.opaque = (voidpf)0;
1712 version = zlibVersion();
1713 TInt ret = inflateInit2_(&d_stream,15,version, sizeof(d_stream));
1722 inflateEnd(&d_stream);
1727 * Function Name : TestInflateInit_
1728 * TestCase Description: Test inflateInit_
1729 * Return Value: Z_OK
1731 TInt CTestZlib::TestInflateInit_()
1733 TInt res = KErrNone ;
1735 const char * version;
1736 d_stream.zalloc = (alloc_func)0;
1737 d_stream.zfree = (free_func)0;
1738 d_stream.opaque = (voidpf)0;
1740 Byte *compr, *uncompr;
1741 uLong comprLen = 20*sizeof(int);
1742 uLong uncomprLen = comprLen;
1743 compr = (Byte*)calloc((uInt)comprLen, 1);
1744 if (compr == Z_NULL)
1746 return KErrNoMemory;
1748 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1749 if (uncompr == Z_NULL)
1752 return KErrNoMemory;
1754 res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
1759 return KErrNoMemory;
1762 res = Test_deflate(compr, comprLen);
1767 return KErrNoMemory;
1769 d_stream.next_in = compr;
1770 d_stream.avail_in = 0;
1771 d_stream.next_out = uncompr;
1772 version=zlibVersion();
1773 int ret = inflateInit_(&d_stream,(char*)version, sizeof(d_stream));
1782 inflateEnd(&d_stream);
1789 * Function Name : TestInflateInit2_negative
1790 * TestCase Description: 1. Compress the sample data using deflate
1791 * 2. inflateInit2_ with stream size less than required
1792 * Return Value: Z_MEM_ERROR
1794 TInt CTestZlib::TestInflateInit2_negative()
1796 TInt res = KErrNone ;
1797 z_stream d_stream; // decompression stream
1798 const char * version;
1799 d_stream.zalloc = (alloc_func)0;
1800 d_stream.zfree = (free_func)0;
1801 d_stream.opaque = (voidpf)0;
1803 Byte *compr, *uncompr;
1804 uLong comprLen = 20*sizeof(int); // don't overflow on MSDOS
1805 uLong uncomprLen = comprLen;
1806 compr = (Byte*)calloc((uInt)comprLen, 1);
1807 if (compr == Z_NULL)
1809 return KErrNoMemory;
1811 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1812 if (uncompr == Z_NULL)
1815 return KErrNoMemory;
1818 res = Test_deflate(compr, comprLen);
1823 return KErrNoMemory;
1825 d_stream.next_in = compr;
1826 d_stream.avail_in = 0;
1827 d_stream.next_out = uncompr;
1828 version=zlibVersion();
1829 int ret = inflateInit2_(&d_stream, 15, version, sizeof(d_stream)-5);
1840 // inflateEnd(&d_stream);
1845 * Function Name : TestInflateInit_negative
1846 * TestCase Description: 1. Compress the sample data using deflate
1847 * 2. Call inflateInit_ with stream size less than required
1848 * Return Value: Z_MEM_ERROR
1850 TInt CTestZlib::TestInflateInit_negative()
1852 TInt res = KErrNone ;
1853 z_stream d_stream; // decompression stream
1854 const char * version;
1855 d_stream.zalloc = (alloc_func)0;
1856 d_stream.zfree = (free_func)0;
1857 d_stream.opaque = (voidpf)0;
1859 Byte *compr, *uncompr;
1860 uLong comprLen = 20*sizeof(int);
1861 uLong uncomprLen = comprLen;
1862 compr = (Byte*)calloc((uInt)comprLen, 1);
1863 if (compr == Z_NULL)
1865 return KErrNoMemory;
1867 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1868 if (uncompr == Z_NULL)
1871 return KErrNoMemory;
1873 res = Test_deflate(compr, comprLen);
1878 return KErrNoMemory;
1880 d_stream.next_in = compr;
1881 d_stream.avail_in = 0;
1882 d_stream.next_out = uncompr;
1883 version=zlibVersion();
1884 int ret = inflateInit_(&d_stream,(char*)version, sizeof(d_stream) - 5);
1893 // inflateEnd(&d_stream);
1900 * Function Name : TestInflateInit2_versioncheck
1901 * TestCase Description: 1. Compress the sample data using deflate
1902 * 2. inflateInit2_ with valid zlib version as argument
1903 * Return Value: Z_OK
1905 TInt CTestZlib::TestInflateInit2_versioncheck()
1907 TInt res = KErrNone ;
1908 z_stream d_stream; // decompression stream
1909 const char * version;
1910 d_stream.zalloc = (alloc_func)0;
1911 d_stream.zfree = (free_func)0;
1912 d_stream.opaque = (voidpf)0;
1914 Byte *compr, *uncompr;
1915 uLong comprLen = 20*sizeof(int);
1916 uLong uncomprLen = comprLen;
1917 compr = (Byte*)calloc((uInt)comprLen, 1);
1918 if (compr == Z_NULL)
1920 return KErrNoMemory;
1922 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1923 if (uncompr == Z_NULL)
1926 return KErrNoMemory;
1929 res = Test_deflate(compr, comprLen);
1934 return KErrNoMemory;
1936 d_stream.next_in = compr;
1937 d_stream.avail_in = 0;
1938 d_stream.next_out = uncompr;
1939 version=zlibVersion();
1940 INFO_PRINTF2(_L("Version : %d"),version);
1941 int ret = inflateInit2_(&d_stream, 15, "1.2.4", sizeof(d_stream)-5);
1956 * Function Name : TestInflateInit_versioncheck
1957 * TestCase Description: 1. Compress the sample data using deflate
1958 * 2. inflateInit_ with valid zlib version as argument
1959 * Return Value: Z_OK
1961 TInt CTestZlib::TestInflateInit_versioncheck()
1963 TInt res = KErrNone ;
1965 z_stream d_stream; // decompression stream
1966 const char * version;
1967 d_stream.zalloc = (alloc_func)0;
1968 d_stream.zfree = (free_func)0;
1969 d_stream.opaque = (voidpf)0;
1971 Byte *compr, *uncompr;
1972 uLong comprLen = 20*sizeof(int); // don't overflow on MSDOS
1973 uLong uncomprLen = comprLen;
1974 compr = (Byte*)calloc((uInt)comprLen, 1);
1975 if (compr == Z_NULL)
1977 return KErrNoMemory;
1979 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1980 if (uncompr == Z_NULL)
1983 return KErrNoMemory;
1985 res = Test_deflate(compr, comprLen);
1990 return KErrNoMemory;
1992 d_stream.next_in = compr;
1993 d_stream.avail_in = 0;
1994 d_stream.next_out = uncompr;
1995 version=zlibVersion();
1996 INFO_PRINTF2(_L("Version : %d"),version);
1997 int ret = inflateInit_(&d_stream,(char*) "1.2.4", sizeof(d_stream) - 5);
2012 * Function Name : TestCompress
2013 * TestCase Description: Test compress()
2014 * Return Value: Z_OK
2016 TInt CTestZlib::TestCompress()
2018 TInt res = KErrNone ;
2019 Byte *compr, *uncompr;
2020 uLong comprLen = 20*sizeof(int);
2021 uLong uncomprLen = comprLen;
2022 compr = (Byte*)calloc((uInt)comprLen, 1);
2023 if (compr == Z_NULL)
2025 return KErrNoMemory;
2027 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
2028 if (uncompr == Z_NULL)
2031 return KErrNoMemory;
2033 res=test_compress_positive(compr, comprLen, uncompr, uncomprLen);
2040 * Function Name : test_compress_negative
2041 * TestCase Description: This is a global function used by many test functions
2043 TInt test_compress_negative(Byte * compr,uLong comprLen,Byte * /*uncompr*/,uLong /*uncomprLen*/)
2045 TInt res = KErrNone ;
2047 uLong len = (uLong)strlen(hello)+1;
2048 err = compress(compr, &comprLen, (const Bytef*)hello, len);
2061 * Function Name : TestCompress_negative
2062 * TestCase Description: Call compress with compression length less than required
2063 * Return Value: Z_BUF_ERROR
2065 TInt CTestZlib::TestCompress_negative()
2067 TInt res = KErrNone ;
2068 Byte *compr, *uncompr;
2069 uLong comprLen = 1*sizeof(int);
2070 uLong uncomprLen = comprLen;
2071 compr = (Byte*)calloc((uInt)comprLen, 1);
2072 if (compr == Z_NULL)
2074 return KErrNoMemory;
2076 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
2077 if (uncompr == Z_NULL)
2080 return KErrNoMemory;
2082 res=test_compress_negative(compr, comprLen, uncompr, uncomprLen);
2089 * Function Name : TestCompress2_positive
2090 * TestCase Description: Test compress2 with valid arguments
2091 * Return Value: Z_OK
2093 TInt CTestZlib::TestCompress2_positive()
2095 TInt res = KErrNone ;
2097 uLong len = (uLong)strlen(hello)+1;
2099 Byte *compr, *uncompr;
2100 uLong comprLen = 20*sizeof(int);
2101 uLong uncomprLen = comprLen;
2102 compr = (Byte*)calloc((uInt)comprLen, 1);
2103 if (compr == Z_NULL)
2105 return KErrNoMemory;
2107 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
2108 if (uncompr == Z_NULL)
2111 return KErrNoMemory;
2114 err=compress2(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);
2130 * Function Name : TestCompress2_negative
2131 * TestCase Description: Test compress2 with compression length less than required
2132 * Return Value: Z_BUF_ERROR
2134 TInt CTestZlib::TestCompress2_negative()
2137 TInt res = KErrNone ;
2138 uLong len = (uLong)strlen(hello)+1;
2140 uLong comprLen = 20*sizeof(int);
2141 compr = (Byte*)calloc((uInt)comprLen, 1);
2142 if (compr == Z_NULL)
2144 return KErrNoMemory;
2146 err=compress2(compr, &comprLen, (const Bytef*)hello, len,14);
2161 * Function Name : test_compressbound
2162 * TestCase Description: This is a global function used by many test functions
2164 TInt test_compressbound(Byte * compr,uLong comprLen)
2166 TInt res = KErrNone ;
2168 uLong sourceLen = (uLong)strlen(hello)+1;
2169 err=compress(compr, &comprLen, (const Bytef*)hello, sourceLen);
2172 int x = compressBound(sourceLen);
2190 * Function Name : TestCompressbound
2191 * TestCase Description: 1. Call compress with appropriate arguments
2192 * 2. Then verify the length of the compressed buffer using compressBound
2193 * Return Value: Returns an upper bound on the compressed size after compression
2196 TInt CTestZlib::TestCompressbound()
2198 TInt res = KErrNone ;
2200 uLong comprLen =20*sizeof(int);
2201 compr = (Byte*)calloc((uInt)comprLen, 1);
2202 if (compr == Z_NULL)
2204 return KErrNoMemory;
2207 res = test_compressbound(compr, comprLen);
2213 * Function Name : test_deflatebound
2214 * TestCase Description: This is a global function used by many test functions
2216 TInt test_deflatebound(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
2218 TInt res = KErrNone ;
2221 stream.next_in = (Bytef*)source;
2222 stream.avail_in = (uInt)sourceLen;
2223 stream.next_out = dest;
2224 stream.avail_out = (uInt)*destLen;
2225 if ((uLong)stream.avail_out != *destLen)
2229 stream.zalloc = (alloc_func)0;
2230 stream.zfree = (free_func)0;
2231 stream.opaque = (voidpf)0;
2233 err = deflateInit(&stream, level);
2236 int y= deflateBound(&stream, sourceLen);
2251 err=deflateEnd(&stream);
2260 * Function Name : TestDeflatebound
2261 * TestCase Description: 1. Compress the sample data using deflate
2262 * 2. Then verify the length of the compressed buffer using deflateBound
2263 * Return Value: Returns an upper bound on the compressed size after compression
2265 TInt CTestZlib::TestDeflatebound()
2267 TInt res = KErrNone ;
2269 uLong len = (uLong)strlen(hello)+1;
2270 Byte *compr, *uncompr;
2271 uLong comprLen = 20*sizeof(int);
2272 uLong uncomprLen = comprLen;
2273 compr = (Byte*)calloc((uInt)comprLen, 1);
2274 if (compr == Z_NULL)
2276 return KErrNoMemory;
2278 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
2279 if(uncompr == Z_NULL)
2282 return KErrNoMemory;
2284 res=test_deflatebound(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);
2291 * Function Name : TestDeflateparams
2292 * TestCase Description: 1. deflateInit to initialize the internal stream state for compression
2293 * 2. deflateParams with valid compression level and strategy
2295 * Return Value: Z_OK
2297 TInt CTestZlib::TestDeflateparams()
2299 TInt res = KErrNone ;
2300 z_stream c_stream; /* compression stream */
2303 uLong comprLen = 20*sizeof(int);
2304 compr = (Byte*)calloc((uInt)comprLen, 1);
2305 if (compr == Z_NULL)
2307 return KErrNoMemory;
2309 uLong len = (uLong)strlen(hello)+1;
2310 c_stream.zalloc = (alloc_func)0;
2311 c_stream.zfree = (free_func)0;
2312 c_stream.opaque = (voidpf)0;
2314 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
2320 c_stream.next_in = (Bytef*)hello;
2321 c_stream.next_out = compr;
2323 err= deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
2328 deflateEnd(&c_stream);
2334 * Function Name : TestDeflateparamsfail1
2335 * TestCase Description: 1. deflateInit to initialize the internal stream state for compression
2336 * 2. deflateParams with invalid compression level
2337 * Return Value: Z_STREAM_ERROR
2339 TInt CTestZlib::TestDeflateparamsfail1()
2341 TInt res = KErrNone ;
2342 z_stream c_stream; /* compression stream */
2345 uLong comprLen = 20*sizeof(int);
2346 compr = (Byte*)calloc((uInt)comprLen, 1);
2347 if (compr == Z_NULL)
2349 return KErrNoMemory;
2352 uLong len = (uLong)strlen(hello)+1;
2353 c_stream.zalloc = (alloc_func)0;
2354 c_stream.zfree = (free_func)0;
2355 c_stream.opaque = (voidpf)0;
2357 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
2364 c_stream.next_in = (Bytef*)hello;
2365 c_stream.next_out = compr;
2367 err= deflateParams(&c_stream, 12, Z_DEFAULT_STRATEGY);
2372 deflateEnd(&c_stream);
2378 * Function Name : TestDeflateparamsfail2
2379 * TestCase Description: 1. deflateInit to initialize the internal stream state for compression
2380 * 2. Pass NULL stream as argument to deflateParams
2381 * Return Value: Z_STREAM_ERROR
2383 TInt CTestZlib::TestDeflateparamsfail2()
2385 TInt res = KErrNone ;
2386 int err= deflateParams(NULL, 12, Z_DEFAULT_STRATEGY);
2396 * Function Name : TestCrcinit
2397 * TestCase Description: Test crc32 with proper arguments
2398 * Return Value: KErrNone
2400 TInt CTestZlib::TestCrcinit()
2402 TInt res = KErrNone ;
2404 long crc = crc32(j,0, 0);
2419 * Function Name : TestCrc
2420 * TestCase Description: 1. Call crc32 with proper arguments
2421 * 2. Call crc32 with with one of the arguments as an updated crc generated from previous call to crc32
2422 * Return Value: KErrNone
2424 TInt CTestZlib::TestCrc()
2426 TInt res = KErrNone ;
2427 unsigned char buffer[5]="1234";
2431 long crc1 = crc32(j,0, 0);
2433 long crc = crc32(crc1, &buffer[0], i);
2435 INFO_PRINTF2(_L("buf %x"),crc);
2437 if(crc==(long)2615402659LL)
2450 * Function Name : TestGet_crc_table
2451 * TestCase Description: Test get_crc_table
2452 * Return Value: KErrNone
2454 TInt CTestZlib::TestGet_crc_table()
2456 TInt res = KErrNone ;
2457 const unsigned long* pcrc_32_tab;
2459 pcrc_32_tab = get_crc_table();
2474 * Function Name : TestDeflateInit_
2475 * TestCase Description: deflateInit_ with all valid arguments
2476 * Return Value: KErrNone
2478 TInt CTestZlib::TestDeflateInit_()
2480 TInt res = KErrNone ;
2484 uLong sourceLen = (uLong)strlen(hello)+1;
2486 uLong comprLen = 10*sizeof(int);
2487 compr = (Byte*)calloc((uInt)comprLen, 1);
2488 if (compr == Z_NULL)
2490 return KErrNoMemory;
2493 stream.zalloc = (alloc_func)0;
2494 stream.zfree = (free_func)0;
2495 stream.opaque = (voidpf)0;
2497 err= deflateInit_(&stream, Z_DEFAULT_COMPRESSION, zlibVersion(), sizeof(z_stream));
2509 deflateEnd(&stream);
2515 * Function Name : TestDeflateInit_level
2516 * TestCase Description: deflateInit_ with invalid compression level
2517 * Return Value: Z_STREAM_ERROR
2519 TInt CTestZlib::TestDeflateInit_level()
2521 TInt res = KErrNone ;
2524 uLong sourceLen = (uLong)strlen(hello)+1;
2526 uLong comprLen = 10*sizeof(int);
2527 compr = (Byte*)calloc((uInt)comprLen, 1);
2528 if (compr == Z_NULL)
2530 return KErrNoMemory;
2533 stream.zalloc = (alloc_func)0;
2534 stream.zfree = (free_func)0;
2535 stream.opaque = (voidpf)0;
2537 err= deflateInit_(&stream, 11, zlibVersion(), sizeof(z_stream));
2554 * Function Name : TestDeflateInit2_
2555 * TestCase Description: deflateInit2_ with invalid compression level
2556 * Return Value: Z_STREAM_ERROR
2558 TInt CTestZlib::TestDeflateInit2_()
2560 TInt res = KErrNone ;
2564 uLong sourceLen = (uLong)strlen(hello)+1;
2566 uLong comprLen = 10*sizeof(int);
2567 compr = (Byte*)calloc((uInt)comprLen, 1);
2568 if (compr == Z_NULL)
2570 return KErrNoMemory;
2573 stream.zalloc = (alloc_func)0;
2574 stream.zfree = (free_func)0;
2575 stream.opaque = (voidpf)0;
2577 err= deflateInit2_(&stream, 11, 8, 15, 8, 0, zlibVersion(), sizeof(z_stream));
2593 * Function Name : TestDeflatefail
2594 * TestCase Description: Set stream next_in and next_out to NULL and call deflateEnd
2595 * Return Value: Z_STREAM_ERROR
2597 TInt CTestZlib::TestDeflatefail()
2599 TInt res = KErrNone ;
2600 z_stream c_stream; /* compression stream */
2603 uLong comprLen = 20*sizeof(int);
2604 compr = (Byte*)calloc((uInt)comprLen, 1);
2605 if (compr == Z_NULL)
2607 return KErrNoMemory;
2610 uLong len = (uLong)strlen(hello)+1;
2612 c_stream.zalloc = (alloc_func)0;
2613 c_stream.zfree = (free_func)0;
2614 c_stream.opaque = (voidpf)0;
2616 res = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
2623 c_stream.next_in = NULL;//(Bytef*)hello;
2624 c_stream.next_out = NULL;//compr;
2626 while (c_stream.total_in != len && c_stream.total_out < comprLen)
2628 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
2629 err = deflate(&c_stream, Z_NO_FLUSH);
2640 /* Finish the stream, still forcing small buffers: */
2641 res = deflateEnd(&c_stream);
2647 * Function Name : TestDeflatefail
2648 * TestCase Description: Set stream avail_out to NULL and call deflateEnd
2649 * Return Value: Z_STREAM_ERROR
2651 TInt CTestZlib::TestDeflatefail2()
2653 TInt res = KErrNone ;
2654 z_stream c_stream; /* compression stream */
2657 uLong comprLen = 20*sizeof(int);
2659 compr = (Byte*)calloc((uInt)comprLen, 1);
2660 if (compr == Z_NULL)
2662 return KErrNoMemory;
2665 uLong len = (uLong)strlen(hello)+1;
2666 c_stream.zalloc = (alloc_func)0;
2667 c_stream.zfree = (free_func)0;
2668 c_stream.opaque = (voidpf)0;
2670 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
2677 c_stream.next_in = (Bytef*)hello;
2678 c_stream.next_out = compr;
2680 while (c_stream.total_in != len && c_stream.total_out < comprLen)
2682 c_stream.avail_in = 1;
2683 c_stream.avail_out = 0; /* fail */
2684 err = deflate(&c_stream, Z_NO_FLUSH);
2696 err = deflateEnd(&c_stream);
2702 * Function Name : TestZlibversion
2703 * TestCase Description: Test Zlibversion
2704 * Return Value: Z_OK
2706 TInt CTestZlib::TestZlibversion()
2708 TInt res = KErrNone ;
2709 if(strcmp(zlibVersion(), "1.2.3") != 0)
2712 ERR_PRINTF1(_L("using incorrect zlib version "));
2718 * Function Name : TestGzputc
2719 * TestCase Description: 1. Open a gzfile in read mode
2720 * 2. Write a character in the file using gzputc
2722 * Return Value: KErrNone
2724 TInt CTestZlib::TestGzputc()
2726 TInt res = KErrNone ;
2727 TInt res1 = KErrNone ;
2729 const char * fname = TESTFILE ;
2730 file = gzopen(fname, "wb");
2738 res1=gzputc(file, 'r');
2748 int err= gzclose(file);
2761 * Function Name : TestGzopen
2762 * TestCase Description: 1. Open a gzfile in read mode
2764 * Return Value: KErrNone
2766 TInt CTestZlib::TestGzopen()
2768 TInt res = KErrNone ;
2770 const char * fname = TESTFILE ;
2771 file = gzopen(fname, "rb");
2781 int err=gzclose(file);
2790 * Function Name : TestGzopenmode
2791 * TestCase Description: 1. Open a gzfile mentioning invalid mode
2792 * Return Value: KErrNone
2794 TInt CTestZlib::TestGzopenmode()
2796 TInt res = KErrNone ;
2798 const char * fname = TESTFILE ;
2799 file = gzopen(fname, "xyz");
2812 * Function Name : TestGzopenfail
2813 * TestCase Description: Open a gzfile mentioning invalid path
2814 * Return Value: KErrNone
2816 TInt CTestZlib::TestGzopenfail()
2818 TInt res = KErrNone ;
2820 const char * fname = NOFILE ;
2821 file = gzopen(fname, "wb");
2834 * Function Name : TestGzputcfail
2835 * TestCase Description: 1. Open a gzfile mentioning invalid path
2836 * 2. Use gzputc to write a character
2837 * Return Value: KErrNone
2839 TInt CTestZlib::TestGzputcfail()
2841 TInt res = KErrNone ;
2842 TInt res1 = KErrNone ;
2844 const char * fname = NOFILE ;
2845 file = gzopen(fname, "wb");
2853 res1=gzputc(file, 'r');
2864 int err= gzclose(file);
2877 * Function Name : TestGzputcreturn
2878 * TestCase Description: 1. Open a gzfile in write mode
2879 * 2. Write a character in the file using gzputc
2880 * 3. Verify the character written by comparing it with what is written
2882 * Return Value: returns the value of the character that was written
2884 TInt CTestZlib::TestGzputcreturn()
2886 TInt res = KErrNone ;
2887 TInt res1 = KErrNone ;
2889 const char * fname = TESTFILE ;
2890 file = gzopen(fname, "wb");
2899 res1=gzputc(file, 'r');
2910 int err= gzclose(file);
2919 * Function Name : TestGzputs
2920 * TestCase Description: 1. Open a gzfile in write mode
2921 * 2. Write a string into file
2923 * Return Value: KErrNone
2925 TInt CTestZlib::TestGzputs()
2927 TInt res = KErrNone ;
2929 const char * fname = TESTFILE ;
2930 file = gzopen(fname, "wb");
2936 if (gzputs(file, "ello") != 4)
2938 ERR_PRINTF1(_L("gzputs err"));
2940 int err= gzclose(file);
2949 * Function Name : TestGzputsfail
2950 * TestCase Description: 1. Open a gzfile in read mode
2951 * 2. Write a string into file
2953 * Return Value: KErrNone
2955 TInt CTestZlib::TestGzputsfail()
2957 TInt res = KErrNone ;
2959 const char *fname = TESTFILE ;
2960 file = gzopen(fname, "rb");
2966 if(gzputs(file, "ello") == 4)
2970 int err= gzclose(file);
2979 * Function Name : TestGzprintf
2980 * TestCase Description: 1. Open a gzfile in write mode
2981 * 2. Write a string into file mentioning the valid format specifier
2983 * Return Value: KErrNone
2985 TInt CTestZlib::TestGzprintf()
2987 TInt res = KErrNone ;
2989 const char * fname = TESTFILE ;
2990 file = gzopen(fname, "wb");
2996 if(gzprintf(file, ", %s!", "hello") != 8)
2998 ERR_PRINTF1(_L("gzprintf err"));
3002 int err = gzclose(file);
3009 res =res= KErrGeneral;
3015 * Function Name : TestGzprintf_trying
3016 * TestCase Description: 1. Open a gzfile in read mode
3017 * 2. Write a string into file mentioning the valid format specifier
3019 * Return Value: KErrNone
3021 TInt CTestZlib::TestGzprintf_trying()
3023 TInt res = KErrNone ;
3025 const char * fname = TESTFILE ;
3026 file = gzopen(fname, "rb");
3032 if (gzprintf(file, ", %s!", "hello") != 8)
3036 ERR_PRINTF1(_L("gzprintf err"));
3039 int err = gzclose(file);
3052 * Function Name : TestGzprintf_trying
3053 * TestCase Description: 1. Open a gzfile in write mode
3054 * 2. Write a string into file mentioning the valid arguments for gzwrite
3056 * Return Value: KErrNone
3058 TInt CTestZlib::TestGzwrite()
3060 TInt res = KErrNone ;
3063 const char *s="ritesh";
3065 const char * fname = TESTFILE ;
3066 file = gzopen(fname, "wb");
3072 size = gzwrite(file, (char*)s, (unsigned)strlen(s));
3077 int err= gzclose(file);
3086 * Function Name : TestGzwritefail
3087 * TestCase Description: 1. Open a gzfile in read mode
3088 * 2. Write a string into file mentioning the valid arguments for gzwrite
3090 * Return Value: Z_NULL
3092 TInt CTestZlib::TestGzwritefail()
3094 TInt res = KErrNone ;
3097 const char *s="ritesh";
3099 const char * fname = TESTFILE ;
3100 file = gzopen(fname, "rb"); //read mode
3106 size = gzwrite(file, (char*)s, (unsigned)strlen(s));
3111 int err= gzclose(file);
3119 TInt testgztell( const char * fname, Byte * uncompr,uLong uncomprLen)
3122 int len = (int)strlen(hello)+1;
3126 file = gzopen(fname, "wb");
3137 if(gzputs(file, "ello") != 4)
3139 //fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
3141 if(gzprintf(file, ", %s!", "hello") != 8)
3143 //fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
3145 gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
3148 file = gzopen(fname, "rb");
3154 strcpy((char*)uncompr, "garbage");
3155 if(gzread(file, uncompr, (unsigned)uncomprLen) != len)
3157 //fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
3160 if(strcmp((char*)uncompr, hello))
3162 //fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
3167 //printf("gzread(): %s\n", (char*)uncompr);
3170 pos = gzseek(file, -8L, SEEK_CUR);
3171 if (pos != 6 || gztell(file) != pos)
3179 TInt CTestZlib::TestGztell()
3181 TInt res = KErrNone ;
3182 Byte *compr, *uncompr;
3183 uLong comprLen = 20*sizeof(int);
3184 uLong uncomprLen = comprLen;
3185 compr = (Byte*)calloc((uInt)comprLen, 1);
3186 if (compr == Z_NULL)
3188 return KErrNoMemory;
3190 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3191 if (uncompr == Z_NULL)
3194 return KErrNoMemory;
3196 test_compress(compr, comprLen, uncompr, uncomprLen);
3197 int err = testgztell(TESTFILE,uncompr, uncomprLen);
3207 TInt CTestZlib::TestGztell1()
3209 TInt res = KErrNone ;
3212 file = gzopen(TESTFILE, "wb");
3232 TInt CTestZlib::TestGztellfail1()
3234 TInt res = KErrNone ;
3237 file = gzopen(NOFILE, "wb");
3251 int test_deflatecopy (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
3253 TInt res = KErrNone ;
3258 stream.zalloc = (alloc_func)0;
3259 stream.zfree = (free_func)0;
3260 stream.opaque = (voidpf)0;
3262 stream.next_in = (Bytef*)source;
3263 stream.avail_in = (uInt)sourceLen;
3265 stream.next_out = dest;
3266 stream.avail_out = (uInt)*destLen;
3267 if ((uLong)stream.avail_out != *destLen)
3272 err = deflateInit(&stream, level);
3278 err=deflateCopy(&stream1 , &stream);
3283 err=deflateEnd(&stream);
3288 err=deflateEnd(&stream1);
3296 TInt CTestZlib::TestDeflatecopy()
3299 uLong len = (uLong)strlen(hello)+1;
3301 Byte *compr, *uncompr;
3302 uLong comprLen = 20*sizeof(int);
3303 uLong uncomprLen = comprLen;
3304 compr = (Byte*)calloc((uInt)comprLen, 1);
3305 if (compr == Z_NULL)
3307 return KErrNoMemory;
3309 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3310 if (uncompr == Z_NULL)
3313 return KErrNoMemory;
3315 res= test_deflatecopy(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);
3322 TInt CTestZlib::TestDeflatecopyfail()
3324 TInt res = KErrNone ;int err;
3326 uLong len = (uLong)strlen(hello)+1;
3329 uLong comprLen = 20*sizeof(int);
3330 compr = (Byte*)calloc((uInt)comprLen, 1);
3332 if (compr == Z_NULL)
3334 return KErrNoMemory;
3336 err=deflateCopy(&stream1 , NULL);
3347 TInt CTestZlib::TestGzclose()
3349 TInt res = KErrNone ;
3351 int len = (int)strlen(hello)+1;
3354 const char * fname = TESTFILE;
3355 file = gzopen(fname, "wb");
3368 TInt CTestZlib::TestGzclose_fail()
3370 TInt res = KErrNone ;
3372 int len = (int)strlen(hello)+1;
3374 const char * fname = NOFILE;
3376 file = gzopen(fname, "wb");
3386 TInt CTestZlib::TestGzeof()
3388 TInt res = KErrNone ;
3390 const char * fname = TESTFILE ;
3391 file = gzopen(fname, "wb");
3398 if (gzputs(file, "ello") != 4)
3400 ERR_PRINTF1(_L("gzputs err"));
3409 int err= gzclose(file);
3417 TInt CTestZlib::TestGzeoffail1()
3419 TInt res = KErrNone ;
3421 const char * fname = TESTFILE ;
3422 file = gzopen(fname, "rb");
3434 int err= gzclose(file);
3442 TInt CTestZlib::TestGzeoffail2()
3444 TInt res = KErrNone ;
3446 const char * fname = NOFILE ;
3447 file = gzopen(fname, "wb");
3453 int err= gzclose(file);
3461 TInt CTestZlib::TestGzgetc()
3463 TInt res = KErrNone ;
3465 const char * fname = TESTFILE ;
3466 file = gzopen(fname, "rb");
3472 int l= gzgetc(file);
3473 int err= gzclose(file);
3482 TInt CTestZlib::TestGzflush()
3484 TInt res = KErrNone ;
3486 const char * fname = TESTFILE ;
3487 file = gzopen(fname, "wb");
3493 int l= gzflush(file,Z_FULL_FLUSH);
3499 int err=gzclose(file);
3508 TInt CTestZlib::TestGzflushsync()
3510 TInt res = KErrNone ;
3512 const char * fname = TESTFILE ;
3513 file = gzopen(fname, "wb");
3519 int l= gzflush(file,Z_SYNC_FLUSH);
3524 int err= gzclose(file);
3532 TInt CTestZlib::TestGzflushfail()
3534 TInt res = KErrNone ;
3536 const char * fname = TESTFILE ;
3537 file = gzopen(fname, "rb");
3543 int l= gzflush(file,Z_FULL_FLUSH);
3548 int err= gzclose(file);
3556 TInt CTestZlib::TestGzerror()
3558 TInt res = KErrNone ;
3560 int len = (int)strlen(hello)+1;
3562 const char * fname = TESTFILE ;
3563 file = gzopen(fname, "wb");
3569 if (gzputs(file, "ello") != 5)
3571 gzprintf(file, "gzputs err: %s\n", gzerror(file, &err));
3587 TInt CTestZlib::TestGzerrorfail1()
3589 TInt res = KErrNone ;
3591 int len = (int)strlen(hello)+1;
3593 const char * fname = NOFILE ;
3594 file = gzopen(fname, "wb");
3601 if (gzputs(file, "ello") != 5)
3603 gzprintf(file, "gzputs err: %s\n", gzerror(file, &err));
3615 TInt CTestZlib::TestGzgetcfail()
3617 TInt res = KErrNone ;
3619 const char * fname = TESTFILE ;
3620 file = gzopen(fname, "wb");
3626 int l= gzgetc(file);
3627 int err= gzclose(file);
3636 TInt CTestZlib::TestDeflateSetDictionary()
3638 TInt res = KErrNone ;
3639 Byte *compr, *uncompr;
3640 uLong comprLen = 20*sizeof(int);
3641 uLong uncomprLen = comprLen;
3643 compr = (Byte*)calloc((uInt)comprLen, 1);
3644 if (compr == Z_NULL)
3646 return KErrNoMemory;
3648 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3649 if (uncompr == Z_NULL)
3652 return KErrNoMemory;
3655 res = test_compress(compr, comprLen, uncompr, uncomprLen);
3660 return KErrNoMemory;
3662 res=Test_dict_deflate(compr, comprLen);
3670 TInt CTestZlib::TestDeflateSetDictionary_nodict()
3672 TInt res = KErrNone ;
3673 Byte *compr, *uncompr;
3674 uLong comprLen = 20*sizeof(int);
3675 uLong uncomprLen = comprLen;
3676 z_stream c_stream; /* compression stream */
3679 c_stream.zalloc = (alloc_func)0;
3680 c_stream.zfree = (free_func)0;
3681 c_stream.opaque = (voidpf)0;
3683 err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
3688 compr = (Byte*)calloc((uInt)comprLen, 1);
3689 if (compr == Z_NULL)
3691 return KErrNoMemory;
3693 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3694 if (uncompr == Z_NULL)
3697 return KErrNoMemory;
3699 err = deflateSetDictionary(&c_stream,NULL, sizeof(dictionary));
3708 err = deflateEnd(&c_stream);
3719 TInt CTestZlib::TestDeflateSetDictionary_fail()
3721 TInt res = KErrNone ;
3722 Byte *compr, *uncompr;
3723 uLong comprLen = 20*sizeof(int);
3724 uLong uncomprLen = comprLen;
3726 compr = (Byte*)calloc((uInt)comprLen, 1);
3727 if (compr == Z_NULL)
3729 return KErrNoMemory;
3731 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3732 if (uncompr == Z_NULL)
3735 return KErrNoMemory;
3738 res=test_compress(compr, comprLen, uncompr, uncomprLen);
3744 return KErrNoMemory;
3746 res = Test_dict_deflate(compr, comprLen);
3751 return KErrNoMemory;
3753 int err = deflateSetDictionary(NULL,(const Bytef*)dictionary, sizeof(dictionary));
3768 TInt CTestZlib::TestDeflateend()
3770 TInt res = KErrNone ;
3771 z_stream c_stream; /* compression stream */
3773 uLong len = (uLong)strlen(hello)+1;
3774 Byte *compr, *uncompr;
3775 uLong comprLen = 20*sizeof(int);
3776 uLong uncomprLen = comprLen;
3777 compr = (Byte*)calloc((uInt)comprLen, 1);
3778 if (compr == Z_NULL)
3780 return KErrNoMemory;
3782 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3783 if (uncompr == Z_NULL)
3786 return KErrNoMemory;
3789 c_stream.zalloc = (alloc_func)0;
3790 c_stream.zfree = (free_func)0;
3791 c_stream.opaque = (voidpf)0;
3792 err=test_compress(compr, comprLen, uncompr, uncomprLen);
3799 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
3807 c_stream.next_in = (Bytef*)hello;
3808 c_stream.next_out = compr;
3810 while (c_stream.total_in != len && c_stream.total_out < comprLen)
3812 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
3813 err = deflate(&c_stream, Z_NO_FLUSH);
3815 /* Finish the stream, still forcing small buffers: */
3818 c_stream.avail_out = 1;
3819 err = deflate(&c_stream, Z_FINISH);
3820 if (err == Z_STREAM_END) break;
3822 err = deflateEnd(&c_stream);
3833 TInt CTestZlib::TestDeflateendfail1()
3835 TInt res = KErrNone ;
3836 z_stream c_stream; /* compression stream */
3839 uLong comprLen = 20*sizeof(int);
3840 compr = (Byte*)calloc((uInt)comprLen, 1);
3841 if (compr == Z_NULL)
3843 return KErrNoMemory;
3846 uLong len = (uLong)strlen(hello)+1;
3847 c_stream.zalloc = (alloc_func)0;
3848 c_stream.zfree = (free_func)0;
3849 c_stream.opaque = (voidpf)0;
3851 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
3855 return KErrNoMemory;
3857 c_stream.next_in = (Bytef*)hello;
3858 c_stream.next_out = compr;
3860 while (c_stream.total_in != len && c_stream.total_out < comprLen)
3862 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
3863 err = deflate(&c_stream, Z_NO_FLUSH);
3866 err = deflateEnd(&c_stream);
3876 TInt CTestZlib::TestDeflate()
3878 TInt res = KErrNone ;
3879 z_stream c_stream; /* compression stream */
3882 uLong comprLen = 20*sizeof(int);
3883 compr = (Byte*)calloc((uInt)comprLen, 1);
3884 if (compr == Z_NULL)
3886 return KErrNoMemory;
3888 uLong len = (uLong)strlen(hello)+1;
3890 c_stream.zalloc = (alloc_func)0;
3891 c_stream.zfree = (free_func)0;
3892 c_stream.opaque = (voidpf)0;
3894 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
3901 c_stream.next_in = (Bytef*)hello;
3902 c_stream.next_out = compr;
3904 while (c_stream.total_in != len && c_stream.total_out < comprLen)
3906 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
3907 err = deflate(&c_stream, Z_NO_FLUSH);
3914 err = deflateEnd(&c_stream);
3921 TInt CTestZlib::TestGzseek()
3923 TInt res = KErrNone ;
3924 Byte *compr, *uncompr;
3925 uLong comprLen = 20*sizeof(int);
3926 uLong uncomprLen = comprLen;
3927 compr = (Byte*)calloc((uInt)comprLen, 1);
3928 if (compr == Z_NULL)
3930 return KErrNoMemory;
3932 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3933 if (uncompr == Z_NULL)
3936 return KErrNoMemory;
3939 err = test_compress(compr, comprLen, uncompr, uncomprLen);
3944 return KErrNoMemory;
3946 int len = (int)strlen(hello)+1;
3948 file = gzopen(TESTFILE, "wb");
3957 if (gzputs(file, "ello") != 4)
3962 if (gzprintf(file, ", %s!", "hello") != 8)
3967 err= gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
3984 TInt CTestZlib::TestGzseekfail1()
3986 TInt res = KErrNone ;
3987 Byte *compr, *uncompr;
3988 uLong comprLen = 20*sizeof(int);
3989 uLong uncomprLen = comprLen;
3991 compr = (Byte*)calloc((uInt)comprLen, 1);
3992 if (compr == Z_NULL)
3994 return KErrNoMemory;
3996 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
3997 if (uncompr == Z_NULL)
4000 return KErrNoMemory;
4003 err = test_compress(compr, comprLen, uncompr, uncomprLen);
4008 return KErrNoMemory;
4011 int len = (int)strlen(hello)+1;
4013 file = gzopen(NOFILE, "wb");
4015 err = gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
4031 TInt CTestZlib::TestGzseekfail2()
4033 TInt res = KErrNone ;
4034 Byte *compr, *uncompr;
4035 uLong comprLen = 20*sizeof(int);
4036 uLong uncomprLen = comprLen;
4038 compr = (Byte*)calloc((uInt)comprLen, 1);
4039 if (compr == Z_NULL)
4041 return KErrNoMemory;
4043 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
4044 if(uncompr == Z_NULL)
4047 return KErrNoMemory;
4051 err = test_compress(compr, comprLen, uncompr, uncomprLen);
4056 return KErrNoMemory;
4058 int len = (int)strlen(hello)+1;
4060 file = gzopen(TESTFILE, "wb");
4062 err = gzseek(file, -1L, SEEK_CUR); /* add one zero byte */
4078 TInt CTestZlib::TestGzsetparams()
4080 TInt res = KErrNone ;
4081 int len = (int)strlen(hello)+1;
4083 const char * fname = TESTFILE;
4085 file = gzopen(fname, "wb");
4088 int u = gzsetparams(file, Z_BEST_SPEED, Z_DEFAULT_STRATEGY);
4093 int err= gzclose(file);
4103 TInt CTestZlib::TestGzsetparams_fail1()
4105 TInt res = KErrNone ;
4106 int len = (int)strlen(hello)+1;
4108 const char * fname = TESTFILE;
4109 file = gzopen(fname, "wb");
4112 int u = gzsetparams(file, Z_BEST_SPEED, -2);
4118 int err= gzclose(file);
4128 TInt CTestZlib::TestGzsetparams_fail2()
4130 TInt res = KErrNone ;
4132 int len = (int)strlen(hello)+1;
4135 const char * fname = TESTFILE;
4136 file = gzopen(fname, "wb");
4139 int u = gzsetparams(file, -2, Z_DEFAULT_STRATEGY);
4144 int err= gzclose(file);
4153 TInt CTestZlib::TestGzsetparams_fail3()
4155 TInt res = KErrNone ;
4156 int len = (int)strlen(hello)+1;
4158 const char * fname = TESTFILE;
4160 file = gzopen(fname, "rb");
4168 int u = gzsetparams(file, Z_BEST_SPEED, Z_DEFAULT_STRATEGY);
4174 int err= gzclose(file);
4183 TInt CTestZlib::TestGzrewind()
4185 TInt res = KErrNone ;
4187 int len = (int)strlen(hello)+1;
4190 const char * fname = TESTFILE;
4191 file = gzopen(fname, "rb");
4197 err = gzrewind(file);
4206 err = gzclose(file);
4216 TInt CTestZlib::TestGzrewindfail()
4218 TInt res = KErrNone ;
4220 int len = (int)strlen(hello)+1;
4223 const char * fname = TESTFILE;
4224 file = gzopen(fname, "wb");
4230 err = gzrewind(file);
4248 TInt CTestZlib::TestGzdopen()
4250 TInt res = KErrNone ;
4251 int len = (int)strlen(hello)+1;
4253 const char * fname = TESTFILE ;
4254 FILE* fp = fopen(fname, "rb");
4255 file = gzdopen(fileno(fp), "rb");
4262 int err= gzclose(file);
4272 TInt CTestZlib::TestGzdopen_fail()
4274 TInt res = KErrNone ;
4275 int len = (int)strlen(hello)+1;
4277 const char * fname = TESTFILE ;
4278 FILE* fp = fopen(fname, "rb");
4279 file = gzdopen(fileno(fp), "xyz");
4286 int err= gzclose(file);
4296 TInt CTestZlib::TestGzdopen_fail2()
4298 TInt res = KErrNone ;
4299 int len = (int)strlen(hello)+1;
4301 const char * fname = TESTFILE ;
4302 FILE* fp = fopen(fname, "rb");
4303 file = gzdopen(-1, "xyz");
4310 int err= gzclose(file);
4319 /* ===========================================================================
4320 * Test deflate() with full flush
4322 TInt CTestZlib::Test_flush( Byte * compr,uLong * comprLen)
4324 TInt res = KErrNone ;
4325 z_stream c_stream; /* compression stream */
4327 uInt len = (uInt)strlen(hello)+1;
4329 c_stream.zalloc = (alloc_func)0;
4330 c_stream.zfree = (free_func)0;
4331 c_stream.opaque = (voidpf)0;
4333 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
4339 c_stream.next_in = (Bytef*)hello;
4340 c_stream.next_out = compr;
4341 c_stream.avail_in = 3;
4342 c_stream.avail_out = (uInt)*comprLen;
4343 err = deflate(&c_stream, Z_FULL_FLUSH);
4345 int h=inflateSyncPoint(&c_stream);
4346 compr[3]++; /* force an error in first compressed block */
4347 c_stream.avail_in = len - 3;
4349 err = deflate(&c_stream, Z_FINISH);
4350 if (err != Z_STREAM_END)
4354 err = deflateEnd(&c_stream);
4359 *comprLen = c_stream.total_out;
4364 TInt test_sync(Byte * compr,uLong comprLen, Byte * uncompr,uLong uncomprLen)
4366 TInt res = KErrNone ;
4368 z_stream d_stream; /* decompression stream */
4370 strcpy((char*)uncompr, "garbage");
4372 d_stream.zalloc = (alloc_func)0;
4373 d_stream.zfree = (free_func)0;
4374 d_stream.opaque = (voidpf)0;
4376 d_stream.next_in = compr;
4377 d_stream.avail_in = 2; /* just read the zlib header */
4379 err = inflateInit(&d_stream);
4384 d_stream.next_out = uncompr;
4385 d_stream.avail_out = (uInt)uncomprLen;
4387 err= inflate(&d_stream, Z_NO_FLUSH);
4392 d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */
4393 err = inflateSync(&d_stream); /* but skip the damaged part */
4398 err = inflate(&d_stream, Z_FINISH);
4403 err = inflateEnd(&d_stream);
4412 TInt CTestZlib::TestInflateSync()
4414 TInt res = KErrNone ;
4415 uLong len = (uLong)strlen(hello)+1;
4417 Byte *compr, *uncompr;
4418 uLong comprLen = 20*sizeof(int);
4419 uLong uncomprLen = comprLen;
4420 compr = (Byte*)calloc((uInt)comprLen, 1);
4421 if (compr == Z_NULL)
4423 return KErrNoMemory;
4425 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
4426 if(uncompr == Z_NULL)
4429 return KErrNoMemory;
4431 res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
4436 return KErrNoMemory;
4438 Test_flush(compr, &comprLen);
4439 res = test_sync(compr, comprLen, uncompr, uncomprLen);
4446 TInt CTestZlib::TestinflateSyncfail()
4448 TInt res = KErrNone ;
4449 uLong len = (uLong)strlen(hello)+1;
4451 Byte *compr, *uncompr;
4452 uLong comprLen = 20*sizeof(int);
4453 uLong uncomprLen = comprLen;
4454 compr = (Byte*)calloc((uInt)comprLen, 1);
4455 if (compr == Z_NULL)
4457 return KErrNoMemory;
4459 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
4460 if (uncompr == Z_NULL)
4463 return KErrNoMemory;
4466 res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
4471 return KErrNoMemory;
4473 int err = test_sync(compr, comprLen, uncompr, uncomprLen);
4488 int test_syncpoint (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
4490 TInt res = KErrNone ;
4494 stream.next_in = (Bytef*)source;
4495 stream.avail_in = (uInt)sourceLen;
4496 stream.next_out = dest;
4497 stream.avail_out = (uInt)*destLen;
4499 stream.zalloc = (alloc_func)0;
4500 stream.zfree = (free_func)0;
4501 stream.opaque = (voidpf)0;
4503 err = deflateInit(&stream, level);
4504 if (err != Z_OK) return err;
4506 err = deflate(&stream, Z_FINISH);
4507 if (err != Z_STREAM_END)
4509 deflateEnd(&stream);
4510 return err == Z_OK ? Z_BUF_ERROR : err;
4512 *destLen = stream.total_out;
4513 int h=inflateSyncPoint(&stream);
4518 deflateEnd(&stream);
4523 TInt CTestZlib::TestInflateSyncPoint()
4525 TInt res = KErrNone ;
4526 uLong len = (uLong)strlen(hello)+1;
4527 Byte *compr, *uncompr;
4528 uLong comprLen = 20*sizeof(int);
4529 uLong uncomprLen = comprLen;
4530 compr = (Byte*)calloc((uInt)comprLen, 1);
4531 if (compr == Z_NULL)
4533 return KErrNoMemory;
4535 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
4536 if (uncompr == Z_NULL)
4539 return KErrNoMemory;
4541 res= test_syncpoint(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);
4547 TInt CTestZlib::TestInflateSyncPoint_null()
4549 TInt res = KErrNone ;
4550 uLong len = (uLong)strlen(hello)+1;
4551 Byte *compr, *uncompr;
4552 uLong comprLen = 20*sizeof(int);
4553 uLong uncomprLen = comprLen;
4554 compr = (Byte*)calloc((uInt)comprLen, 1);
4555 if (compr == Z_NULL)
4557 return KErrNoMemory;
4559 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
4560 if (uncompr == Z_NULL)
4563 return KErrNoMemory;
4565 int h=inflateSyncPoint(NULL);
4576 TInt CTestZlib::TestZerror()
4578 TInt res = KErrNone ;
4579 const char * s = zError(1);
4580 if(strcmp(s,"stream end"))
4587 TInt CTestZlib::TestZerror1()
4589 TInt res = KErrNone ;
4590 const char * s = zError(-3);
4591 if(strcmp(s,"data error"))
4599 TInt CTestZlib::TestZerror2()
4601 TInt res = KErrNone ;
4602 const char * s = zError(0);