os/ossrv/compressionlibs/ziplib/test/tef/tlibz/src/tzlib_auto.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 *
    16 */
    17 
    18 
    19 #include "tzlib.h"
    20 
    21 /**
    22  * Function Name : TestAdlerinit
    23  * TestCase Description: Testing Adler
    24  * Return Value: Return KErrNone if adler32=1, else return KErrGeneral
    25  */
    26 TInt CTestZlib::TestAdlerinit()
    27 	{
    28 	TInt res = KErrNone ;
    29 	unsigned long j=0L;
    30 
    31 	long adler1 = adler32(j,0, 0);
    32 	if(adler1 == 1)
    33 		{    	
    34 		res=KErrNone ;    	
    35 		}
    36 	else
    37 		{    	
    38 		res = KErrGeneral;
    39 		}
    40 	return res;
    41 	}
    42 
    43 /**
    44  * Function Name : TestAdler
    45  * TestCase Description: Testing Adler32
    46  * Return Value:  Return KErrNone if adler32>0, else return KErrGeneral
    47  */
    48 TInt CTestZlib::TestAdler()
    49 	{
    50 	TInt res = KErrNone ;
    51 	unsigned char  buffer[5]="1234";
    52 	unsigned int i=4;
    53 	unsigned long j=0L;
    54 
    55 	long adler1 = adler32(j,0, 0);
    56 	long adler = adler32(adler1, &buffer[0], i);
    57 	INFO_PRINTF2(_L("buf %x"),adler);
    58 
    59 	if(adler > 0)
    60 		{    	
    61 		res=KErrNone ;    	
    62 		}
    63 	else
    64 		{    	
    65 		res = KErrGeneral;
    66 		}
    67 	return res;
    68 	}
    69 
    70 /**
    71  * Function Name : TestDeflateReset
    72  * TestCase Description: Call deflateReset after deflateInit
    73  * Return Value: Returns KErrNone on deflateReset returning Z_OK, else KErrGeneral
    74  */  
    75 TInt CTestZlib::TestDeflateReset()
    76 	{ 
    77 	INFO_PRINTF1(_L("DeflateReset test with valid input"));
    78 	TInt res = KErrNone ;
    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;
    84 	int err;
    85 	z_stream stream;
    86 	compr    = (Byte*)calloc((uInt)comprLen, 1);
    87 	if (compr == Z_NULL)
    88 		{
    89 		return KErrNoMemory;
    90 		}
    91 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
    92 	if (uncompr == Z_NULL) 
    93 		{
    94 		free(compr);
    95 		return KErrNoMemory;
    96 		}
    97 
    98 	stream.zalloc = (alloc_func)0;
    99 	stream.zfree = (free_func)0;
   100 	stream.opaque = (voidpf)0;
   101 
   102 	err = deflateInit(&stream, level);
   103 	if (err != Z_OK) 
   104 		{
   105 		free(compr);
   106 		free(uncompr);
   107 		return KErrGeneral;
   108 		}
   109 
   110 	Bytef *dest = compr ;
   111 	uLongf *destLen = &comprLen;
   112 	const Bytef *source = (const Bytef*)hello;
   113 	uLong sourceLen = len;  
   114 
   115 	stream.next_in = (Bytef*)source;
   116 	stream.avail_in = (uInt)sourceLen;
   117 #ifdef MAXSEG_64K
   118 /* Check for source > 64K on 16-bit machine: */
   119 if ((uLong)stream.avail_in != sourceLen)  
   120 	{
   121 	res = KErrGeneral; 
   122 	}
   123 #endif
   124 stream.next_out = dest;
   125 stream.avail_out = (uInt)*destLen;
   126 if ((uLong)stream.avail_out != *destLen)  
   127 	{
   128 	res = KErrGeneral; 
   129 	}
   130 err=deflateReset(&stream);
   131 if (err != Z_OK)  
   132 	{
   133 	res = KErrGeneral;     			
   134 	} 
   135 else  
   136 	{    	
   137 	res = KErrNone;
   138 	}   
   139 err = deflateEnd(&stream);
   140 if (err != Z_OK) 
   141 	{
   142 	INFO_PRINTF1(_L("Error in deflateEnd"));
   143 	free(compr);
   144 	free(uncompr);	
   145 	return KErrGeneral;
   146 	}
   147 free(compr);
   148 free(uncompr);
   149 return res;
   150 	}
   151 
   152 /**
   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
   156  */ 
   157 TInt CTestZlib::TestDeflateReset_fail()
   158 	{ 
   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;
   164 	int err;
   165 	z_stream stream;
   166 	compr = (Byte*)calloc((uInt)comprLen, 1);
   167 	if (compr == Z_NULL)
   168 		{
   169 		return KErrNoMemory;
   170 		}
   171 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   172 	if (uncompr == Z_NULL) 
   173 		{
   174 		free(compr);
   175 		return KErrNoMemory;
   176 		}
   177 
   178 	stream.zalloc = (alloc_func)0;
   179 	stream.zfree = (free_func)0;
   180 	stream.opaque = (voidpf)0;
   181 	err=deflateReset(&stream);
   182 	if (err != Z_OK)  
   183 		{
   184 		res = KErrNone;
   185 		} 
   186 	else  
   187 		{    	
   188 		res = KErrGeneral;     			
   189 		}   
   190 	free(compr);
   191 	free(uncompr);
   192 	return res;
   193 	}
   194 
   195 /**
   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
   199  */
   200 TInt CTestZlib::TestDeflateInit2_bits()
   201 	{
   202 	TInt res = KErrNone ;
   203 	z_stream stream;
   204 	int err;
   205 	int level=Z_DEFAULT_COMPRESSION;
   206 
   207 	uLong sourceLen = (uLong)strlen(hello)+1;
   208 	Byte *compr;
   209 	uLong comprLen = 10*sizeof(int); 
   210 	compr = (Byte*)calloc((uInt)comprLen, 1);
   211 	if (compr == Z_NULL)
   212 		{
   213 		return KErrNoMemory;
   214 		}
   215 	stream.zalloc = (alloc_func)0;
   216 	stream.zfree = (free_func)0;
   217 	stream.opaque = (voidpf)0;
   218 
   219 	err= deflateInit2_(&stream, level, 3, 15, 8, 0, zlibVersion(), sizeof(z_stream));
   220 
   221 	if (err != Z_OK) 
   222 		{
   223 		res = KErrNone;
   224 		} 
   225 	else  
   226 		{    	
   227 		res = KErrGeneral; 
   228 		}   
   229 	free(compr);
   230 	return res;
   231 	}
   232 
   233 /**
   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
   237  */
   238 TInt CTestZlib::TestDeflateInit2_level()
   239 	{
   240 	TInt res = KErrNone ;
   241 	z_stream stream;
   242 	int err;
   243 	int level=Z_DEFAULT_COMPRESSION;
   244 
   245 	uLong sourceLen = (uLong)strlen(hello)+1;
   246 	Byte *compr;
   247 	uLong comprLen = 10*sizeof(int); 
   248 	compr = (Byte*)calloc((uInt)comprLen, 1);
   249 	if (compr == Z_NULL)
   250 		{
   251 		return KErrNoMemory;
   252 		}
   253 
   254 	stream.zalloc = (alloc_func)0;
   255 	stream.zfree = (free_func)0;
   256 	stream.opaque = (voidpf)0;
   257 
   258 	err= deflateInit2_(&stream, level, 3, 2, 8,
   259 			0,  zlibVersion(), sizeof(z_stream));
   260 
   261 	if (err != Z_OK) 
   262 		{
   263 		res = KErrNone;
   264 		} 
   265 	else  
   266 		{    	
   267 		res = KErrGeneral; 
   268 		}   
   269 	free(compr);
   270 	return res;
   271 	}
   272 
   273 /**
   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
   277  */  
   278 TInt CTestZlib::TestInflateInit2_bits()
   279 	{
   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;
   286 
   287 	version = zlibVersion();
   288 	int ret =  inflateInit2_(&d_stream,5,version, sizeof(d_stream));
   289 	if(ret==0)
   290 		{ 
   291 		res = KErrGeneral;    	
   292 		}
   293 	else
   294 		{    
   295 		res = KErrNone;    
   296 		} 
   297 	return res;       
   298 	}
   299 
   300 /**
   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
   306  */  
   307 TInt CTestZlib::TestGzread()
   308 	{
   309 	char * buf1 = (char*)malloc(1024);
   310 	if (buf1 == NULL)
   311 		{
   312 		ERR_PRINTF1(_L("Heap out of memory"));
   313 		return KErrNoMemory;
   314 		}
   315 
   316 	int len1;
   317 	TInt res = KErrNone ;
   318 	char  *file=FILETESTGZ;
   319 	char *infile;
   320 	gzFile in;
   321 	infile = file;
   322 	in = gzopen(infile, "rb");           
   323 	if (in == Z_NULL) 
   324 		{
   325 		free(buf1);
   326 		ERR_PRINTF1(_L("Could not open the file"));
   327 		res = KErrGeneral;
   328 		return res;
   329 		}   
   330 	for (;;)
   331 		{
   332 		len1 = gzread(in, buf1, sizeof(buf1));
   333 		if (len1 == 0 )
   334 			break;
   335 		else if(len1 < 0 ) 
   336 			{
   337 			INFO_PRINTF1(_L("Error in reading the file"));
   338 			free(buf1);
   339 			return KErrGeneral;
   340 			}
   341 		}
   342 	if (gzclose(in) != Z_OK)
   343 		{    	
   344 		ERR_PRINTF1(_L("Could not close the file"));
   345 		res=KErrGeneral;     
   346 		}
   347 	free(buf1);
   348 	return res;
   349 	}   
   350 
   351 /**
   352  * Function Name : TestGzread_fail
   353  * TestCase Description: 1. Open a gz file in write mode
   354  *						2. gzRead from the file. 
   355  *						3. close the file
   356  * Return Value: Returns KErrNone on gzread returning -1
   357  */   
   358 TInt CTestZlib::TestGzread_fail()
   359 	{
   360 	char * buf1 = (char*)malloc(1024);
   361 	if(buf1==NULL)
   362 		{
   363 		return KErrNoMemory;
   364 		}
   365 	int len1;
   366 	TInt res = KErrNone ;
   367 	gzFile in = Z_NULL;
   368 	in = gzopen(FILETESTGZ1, "wb"); 
   369 	res=(int)in;
   370 	if (0 == res)
   371 		{
   372 		free(buf1);
   373 		return KErrNoMemory;;
   374 		}
   375 
   376 	len1 = gzread(in, buf1, sizeof(buf1));
   377 	if (len1 < 0) 
   378 		{
   379 		res = KErrNone;
   380 		}
   381 	else if (0 == len1)
   382 		{
   383 		res = KErrGeneral;
   384 		}
   385 
   386 	if (gzclose(in) != Z_OK)
   387 		{
   388 		free(buf1);
   389 		INFO_PRINTF1(_L("Error encountered while closing the file"));
   390 		return KErrGeneral;     
   391 		}
   392 
   393 	free(buf1);
   394 	return res;
   395 	}   
   396 /**
   397  * Function Name : test_uncompress
   398  * TestCase Description: This is a global function used by many test functions
   399  */ 
   400 TInt test_uncompress(Byte * compr,uLong comprLen,Byte * uncompr,uLong uncomprLen)
   401 	{
   402 	TInt res = KErrNone ;
   403 	int err;
   404 	uLong len = (uLong)strlen(hello)+1;
   405 
   406 	err = compress(compr, &comprLen, (const Bytef*)hello, len);
   407 
   408 	if(err == 0)
   409 		{    	
   410 		strcpy((char*)uncompr, "garbage");
   411 		err = uncompress(uncompr, &uncomprLen, compr, comprLen);
   412 		if(err < Z_OK)
   413 			{
   414 			res = KErrGeneral ;
   415 			}    
   416 		} 
   417 	else
   418 		{    	
   419 		res = KErrGeneral;
   420 		}
   421 
   422 	return res;
   423 	}
   424 /**
   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
   429  *	
   430  * Return Value: Z_OK
   431  */ 
   432 TInt CTestZlib::TestUncompress()
   433 	{
   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);
   439 	if (compr == Z_NULL)
   440 		{
   441 		return KErrNoMemory;
   442 		}
   443 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   444 	if (uncompr == Z_NULL) 
   445 		{
   446 		free(compr);
   447 		return KErrNoMemory;
   448 		}
   449 	res =  test_uncompress(compr, comprLen, uncompr, uncomprLen);
   450 	free(compr);
   451 	free(uncompr);
   452 	return res;
   453 	}
   454 
   455 /**
   456  * Function Name : TestUncompressfail
   457  * TestCase Description: 1. Uncompress is called with uncompressed length smaller than required
   458  *	
   459  * Return Value: Z_BUF_ERROR
   460  */   
   461 TInt CTestZlib::TestUncompressfail()
   462 	{
   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);
   468 	if (compr == Z_NULL)
   469 		{
   470 		return Z_MEM_ERROR;
   471 		}
   472 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   473 	if (uncompr == Z_NULL) 
   474 		{
   475 		free(compr);
   476 		return KErrNoMemory;
   477 		}
   478 	int err =  test_uncompress(compr, comprLen, uncompr, uncomprLen);
   479 	if(err==0)
   480 		{
   481 		res = KErrGeneral;
   482 		} 
   483 	free(compr);
   484 	free(uncompr);
   485 	return res;
   486 	}
   487 
   488 /**
   489  * Function Name : Test_dict_deflate
   490  * TestCase Description: This is a global function used by many test functions
   491  */ 
   492 TInt CTestZlib::Test_dict_deflate( Byte * compr,uLong comprLen)
   493 	{
   494 	TInt res = KErrNone ;
   495 	z_stream c_stream; /* compression stream */
   496 	int err;
   497 
   498 	c_stream.zalloc = (alloc_func)0;
   499 	c_stream.zfree = (free_func)0;
   500 	c_stream.opaque = (voidpf)0;
   501 
   502 	err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
   503 	if(err<0)
   504 		{
   505 		res = KErrGeneral;
   506 		return res;	
   507 		}
   508 
   509 	err = deflateSetDictionary(&c_stream,
   510 			(const Bytef*)dictionary, sizeof(dictionary));
   511 	if(err<0)
   512 		{
   513 		res = KErrGeneral;
   514 		return res;
   515 		}
   516 	dictId = c_stream.adler;
   517 	c_stream.next_out = compr;
   518 	c_stream.avail_out = (uInt)comprLen;
   519 
   520 	c_stream.next_in = (Bytef*)hello;
   521 	c_stream.avail_in = (uInt)strlen(hello)+1;
   522 
   523 	err = deflate(&c_stream, Z_FINISH);
   524 	if (err != Z_STREAM_END) 
   525 		{
   526 		res = KErrGeneral;
   527 		}
   528 	err = deflateEnd(&c_stream);
   529 	if (err != 0) 
   530 		{
   531 		res = KErrGeneral;
   532 		}
   533 	return res;
   534 	}
   535 
   536 
   537 /**
   538  * Function Name : Test_dict_inflate
   539  * TestCase Description: This is an utility function used by many test functions
   540  */
   541 TInt CTestZlib::Test_dict_inflate(Byte * compr,uLong comprLen, Byte * uncompr,uLong uncomprLen)
   542 	{
   543 	TInt res = KErrNone ;
   544 	int err;
   545 	z_stream d_stream; /* decompression stream */
   546 
   547 	strcpy((char*)uncompr, "garbage");
   548 
   549 	d_stream.zalloc = (alloc_func)0;
   550 	d_stream.zfree = (free_func)0;
   551 	d_stream.opaque = (voidpf)0;
   552 
   553 	d_stream.next_in  = compr;
   554 	d_stream.avail_in = (uInt)comprLen;
   555 
   556 	err = inflateInit(&d_stream);
   557 	if(Z_MEM_ERROR == err)
   558 		{
   559 		return Z_MEM_ERROR;    	
   560 		}
   561 	else if(Z_VERSION_ERROR == err)
   562 		{
   563 		return Z_VERSION_ERROR;    	
   564 		}
   565 
   566 	d_stream.next_out = uncompr;
   567 	d_stream.avail_out = (uInt)uncomprLen;
   568 
   569 	for (;;) 
   570 		{
   571 		err = inflate(&d_stream, Z_NO_FLUSH);
   572 		if (err == Z_NEED_DICT) 
   573 			{
   574 			if (d_stream.adler != dictId) 
   575 				{
   576 				break;
   577 				}
   578 			err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
   579 					sizeof(dictionary));
   580 			if(err < Z_OK)
   581 				{
   582 				INFO_PRINTF1(_L("Error returned by inflateSetDictionary"));
   583 				break;
   584 				}
   585 			}
   586 		else
   587 			{
   588 			break;
   589 			}
   590 		}		// end of for
   591 
   592 		err = inflateEnd(&d_stream);
   593 		if (strcmp((char*)uncompr, hello)) 
   594 			{
   595 			INFO_PRINTF1(_L("Bad inflate with dictionary"));
   596 			res = KErrGeneral;
   597 			} 
   598 		else 
   599 			{
   600 			INFO_PRINTF1(_L("Inflate with dictionary successful"));
   601 			}
   602 		return res;
   603 	}
   604 
   605 /**
   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
   610  */ 
   611 TInt CTestZlib::TestInflateSetDictionary()
   612 	{
   613 	TInt res = KErrNone ;
   614 	Byte *compr, *uncompr;
   615 	uLong comprLen = 100*sizeof(int); 
   616 	uLong uncomprLen = comprLen;
   617 
   618 	compr = (Byte*)calloc((uInt)comprLen, 1);
   619 	if (compr == NULL)
   620 		{
   621 		return KErrNoMemory;
   622 		}
   623 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   624 	if (uncompr == Z_NULL) 
   625 		{
   626 		free(compr);
   627 		return KErrNoMemory;
   628 		}
   629 	res = Test_dict_deflate(compr, comprLen);
   630 	if(res < 0)
   631 		{
   632 		free(compr);
   633 		free(uncompr);
   634 		return res;
   635 		}
   636 	if(res==0)
   637 		{
   638 		res=Test_dict_inflate(compr, comprLen, uncompr, uncomprLen);	
   639 		}
   640 	else
   641 		{
   642 		res=KErrGeneral;
   643 		}
   644 	free(compr);
   645 	free(uncompr);
   646 	return res;
   647 	}
   648 
   649 
   650 /**
   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
   655  */    
   656 TInt CTestZlib::TestInflateSetDictionary_size()
   657 	{ 
   658 
   659 	TInt res=KErrNone;
   660 	Byte *compr, *uncompr;
   661 	uLong comprLen = 20*sizeof(int); 
   662 	uLong uncomprLen = comprLen;
   663 	z_stream d_stream; /* decompression stream */
   664 
   665 	compr = (Byte*)calloc((uInt)comprLen, 1);
   666 	if (compr == Z_NULL)
   667 		{
   668 		return KErrNoMemory;
   669 		}
   670 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   671 	if (uncompr == Z_NULL) 
   672 		{
   673 		free(compr);
   674 		return KErrNoMemory;
   675 		}
   676 
   677 	res = Test_dict_deflate(compr, comprLen);
   678 	if(res<0)
   679 		{
   680 		res=KErrGeneral;
   681 		free(compr);
   682 		free(uncompr);
   683 		return res;
   684 		}
   685 	strcpy((char*)uncompr, "garbage");
   686 
   687 	d_stream.zalloc = (alloc_func)0;
   688 	d_stream.zfree = (free_func)0;
   689 	d_stream.opaque = (voidpf)0;
   690 
   691 	d_stream.next_in  = compr;
   692 	d_stream.avail_in = (uInt)comprLen;
   693 
   694 	int err = inflateInit(&d_stream);
   695 
   696 	d_stream.next_out = uncompr;
   697 	d_stream.avail_out = (uInt)uncomprLen;
   698 
   699 	for (;;) 
   700 		{
   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)
   705 			{
   706 			res=KErrNone; 
   707 			break;     
   708 			}
   709 		else 
   710 			{
   711 			res=KErrGeneral; 
   712 			break;
   713 			}
   714 		}
   715 	err = inflateEnd(&d_stream);
   716 	if(err != Z_OK)
   717 		{
   718 		INFO_PRINTF1(_L("InflateEnd failed"));
   719 		free(compr);
   720 		free(uncompr);
   721 		return KErrGeneral;
   722 		}
   723 
   724 	free(compr);
   725 	free(uncompr);
   726 	return res;
   727 	}
   728 
   729 /**
   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
   734  */     
   735 TInt CTestZlib::TestInflateSetDictionary_null()
   736 	{
   737 	TInt res=KErrNone;
   738 	Byte *compr, *uncompr;
   739 	uLong comprLen = 20*sizeof(int); 
   740 	uLong uncomprLen = comprLen;
   741 
   742 	compr = (Byte*)calloc((uInt)comprLen, 1);
   743 	if (compr == Z_NULL)
   744 		{
   745 		return KErrNoMemory;
   746 		}
   747 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   748 	if (uncompr == Z_NULL) 
   749 		{
   750 		free(compr);
   751 		return KErrNoMemory;
   752 		}
   753 
   754 	res= Test_dict_deflate(compr, comprLen);
   755 	if(res == KErrGeneral)
   756 		{
   757 		free(compr);
   758 		free(uncompr);
   759 		return res;
   760 		}
   761 	int err = inflateSetDictionary(NULL, (const Bytef*)dictionary,sizeof(dictionary));
   762 	if(err != Z_STREAM_ERROR)
   763 		{
   764 		res=KErrGeneral;
   765 		}
   766 	free(compr);
   767 	free(uncompr);
   768 	return res;
   769 	}
   770 
   771 /**
   772  * Function Name : test_compress
   773  * TestCase Description: This is a global function used by many test functions
   774  */
   775 TInt test_compress(Byte * compr,uLong comprLen,Byte * uncompr,uLong uncomprLen)
   776 	{
   777 	int err = KErrNone;
   778 	uLong len = (uLong)strlen(hello)+1;
   779 
   780 	err = compress(compr, &comprLen, (const Bytef*)hello, len);
   781 
   782 	if(err<0)
   783 		{
   784 		return err;
   785 		}
   786 	strcpy((char*)uncompr, "garbage");
   787 
   788 	err = uncompress(uncompr, &uncomprLen, compr, comprLen);
   789 
   790 	if(err<0)
   791 		{
   792 		return err;
   793 		}
   794 	if (strcmp((char*)uncompr, hello)) 
   795 		{
   796 		//INFO_PRINTF1(_L("Uncompressed string does not match with original string"));
   797 		err = KErrGeneral;
   798 		}
   799 	else 
   800 		{
   801 		err=0;
   802 		}
   803 	return err;
   804 	}
   805 
   806 /**
   807  * Function Name : test_gzgets
   808  * TestCase Description: This is a global function used by many test functions
   809  */
   810 int test_gzgets(const char * fname, Byte * uncompr,uLong  uncomprLen)
   811 	{
   812 	int err = KErrNone;
   813 	int len = (int)strlen(hello)+1;
   814 	gzFile file;
   815 
   816 	file = gzopen(fname, "wb");
   817 	if (file == NULL) 
   818 		{
   819 		err = KErrGeneral; 
   820 		return err;        
   821 		}
   822 	gzputc(file, 'h');
   823 	if (gzputs(file, "ello") != 4) 
   824 		{
   825 		err=1;
   826 		}
   827 	if (gzprintf(file, ", %s!", "hello") != 8) 
   828 		{
   829 		err=1;
   830 		}
   831 	err = gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
   832 	if (err < 0)
   833 		{
   834 		//INFO_PRINTF1(_L("Error returned by gzssek"));
   835 		}
   836 	gzclose(file);
   837 
   838 	file = gzopen(fname, "rb");
   839 	if (file == NULL) 
   840 		{
   841 		err = KErrGeneral; 
   842 		return err;        
   843 		}
   844 	strcpy((char*)uncompr, "garbage");
   845 	if (gzread(file, uncompr, (unsigned)uncomprLen) != len) 
   846 		{
   847 		}
   848 	if (strcmp((char*)uncompr, hello))
   849 		{
   850 		err=0;
   851 		}
   852 	else 
   853 		{
   854 		err=1;
   855 		}
   856 
   857 	err = gzseek(file, -8L, SEEK_CUR);
   858 	if (err < 0)
   859 		{
   860 		//INFO_PRINTF1(_L("Error returned by gzssek"));
   861 		}
   862 	gzgets(file, (char*)uncompr, (int)uncomprLen);
   863 
   864 	if (strlen((char*)uncompr) != 7) // " hello!" 
   865 		{ 
   866 		err=0;
   867 		}
   868 	gzclose(file);    
   869 	return err;
   870 	}
   871 
   872 /**
   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
   877  */
   878 TInt CTestZlib::TestGzgets()
   879 	{ 	
   880 	TInt res = KErrNone ;
   881 	Byte *compr, *uncompr;
   882 	uLong comprLen = 20*sizeof(int); 
   883 
   884 	uLong uncomprLen = comprLen;
   885 	compr = (Byte*)calloc((uInt)comprLen, 1);
   886 	if (compr == Z_NULL)
   887 		{
   888 		return KErrNoMemory;
   889 		}
   890 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   891 	if (uncompr == Z_NULL) 
   892 		{
   893 		free(compr);
   894 		return KErrNoMemory;
   895 		}
   896 
   897 	res = test_compress(compr, comprLen, uncompr, uncomprLen);
   898 	if(res < 0)
   899 		{
   900 		free(compr);
   901 		free(uncompr);
   902 		return KErrNoMemory;
   903 		}
   904 	int err=test_gzgets(MYFILE,uncompr, uncomprLen);
   905 	if(err == 0)
   906 		{    	
   907 		res = KErrGeneral;
   908 		}
   909 	free(compr);
   910 	free(uncompr);
   911 	return res;
   912 	}
   913 
   914 /**
   915  * Function Name : test_gzgetsfail
   916  * TestCase Description: This is a global function used by many test functions
   917  */
   918 TInt test_gzgetsfail(const char * fname, Byte * uncompr,int  uncomprLen)
   919 	{
   920 	TInt res = KErrNone ;
   921 	char* err;
   922 	int len = (int)strlen(hello)+1;
   923 	gzFile file;
   924 
   925 	file = gzopen(fname, "wb");
   926 	if (file == NULL) 
   927 		{
   928 		res = KErrGeneral;
   929 		}
   930 	err = gzgets(file, (char*)uncompr, uncomprLen);
   931 
   932 	if(err == 0)
   933 		{    	
   934 		res = KErrNone ;    	
   935 		}
   936 	else
   937 		{    	
   938 		res = KErrGeneral;
   939 		}
   940 	int  err1=  gzclose(file);
   941 	if (err1 != Z_OK)  
   942 		{
   943 		res = KErrGeneral; 
   944 		}     
   945 	return res;
   946 	}
   947 
   948 
   949 /**
   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
   954  */
   955 TInt CTestZlib::TestgzgetsFail()
   956 	{
   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);
   962 	if (compr == Z_NULL)
   963 		{
   964 		return KErrNoMemory;
   965 		}
   966 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   967 	if (uncompr == Z_NULL) 
   968 		{
   969 		free(compr);
   970 		return KErrNoMemory;
   971 		}
   972 	test_compress(compr, comprLen, uncompr, uncomprLen);
   973 	int ret=  test_gzgetsfail(TESTFILE,uncompr, -1);
   974 	if(ret == 0)
   975 		{    	
   976 		res = KErrNone ;    	
   977 		}
   978 	else
   979 		{    	
   980 		res = KErrGeneral;
   981 		}
   982 
   983 	free(compr);
   984 	free(uncompr);
   985 	return res;
   986 	}
   987 
   988 
   989 /**
   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
   994  */   
   995 TInt CTestZlib::TestgzgetsopenFail()
   996 	{
   997 	TInt res = KErrNone ;
   998 
   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)
  1004 		{
  1005 		return KErrNoMemory;
  1006 		}
  1007 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1008 	if (uncompr == Z_NULL) 
  1009 		{
  1010 		free(compr);
  1011 		return KErrNoMemory;
  1012 		}
  1013 	res=test_compress(compr, comprLen, uncompr, uncomprLen);
  1014 	if(res < 0)
  1015 		{
  1016 		free(compr);
  1017 		free(uncompr);
  1018 		return KErrNoMemory;
  1019 		}
  1020 	int err = test_gzgetsfail(NOFILE,uncompr, uncomprLen);
  1021 
  1022 	if(err != 0)
  1023 		{    	
  1024 		res = KErrNone ;    	
  1025 		}
  1026 	else
  1027 		{    	
  1028 		res = KErrGeneral;
  1029 		}
  1030 	free(compr);
  1031 	free(uncompr);
  1032 	return res;
  1033 	}
  1034 
  1035 
  1036 /**
  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
  1041  */ 
  1042 TInt CTestZlib::Test_deflate( Byte *compr, uLong comprLen)
  1043 	{
  1044 	TInt res = KErrNone ;
  1045 	z_stream c_stream; /* compression stream */
  1046 	int err;
  1047 	uLong len = (uLong)strlen(hello)+1;
  1048 
  1049 	c_stream.zalloc = (alloc_func)0;
  1050 	c_stream.zfree = (free_func)0;
  1051 	c_stream.opaque = (voidpf)0;
  1052 
  1053 	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  1054 
  1055 	if(err<0)
  1056 		{
  1057 		return err;
  1058 		}
  1059 	c_stream.next_in = (Bytef*)hello;
  1060 	c_stream.next_out = compr;
  1061 
  1062 	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  1063 		{
  1064 		c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
  1065 		err = deflate(&c_stream, Z_NO_FLUSH);
  1066 		}
  1067 	/* Finish the stream, still forcing small buffers: */
  1068 	for (;;) 
  1069 		{
  1070 		c_stream.avail_out = 1;
  1071 		err = deflate(&c_stream, Z_FINISH);
  1072 		if (err == Z_STREAM_END) break;
  1073 		if(err!=Z_OK)
  1074 			{
  1075 			res = KErrGeneral;
  1076 			}    
  1077 		}
  1078 	err = deflateEnd(&c_stream);
  1079 	if(err!=Z_OK)
  1080 		{
  1081 		res = KErrGeneral;
  1082 		} 
  1083 	return res;
  1084 	}
  1085 
  1086 
  1087 /**
  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
  1093  */
  1094 TInt CTestZlib::TestInflate()
  1095 	{
  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)
  1102 		{
  1103 		return KErrNoMemory;
  1104 		}
  1105 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1106 	if (uncompr == Z_NULL) 
  1107 		{
  1108 		free(compr);
  1109 		return KErrNoMemory;
  1110 		}
  1111 	// test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  1112 	res = Test_deflate(compr, comprLen);
  1113 	if(res<0)
  1114 		{
  1115 		free(compr);
  1116 		free(uncompr);
  1117 		return KErrNoMemory;	
  1118 		}
  1119 
  1120 	int err=0;
  1121 	z_stream d_stream; /* decompression stream */
  1122 
  1123 	strcpy((char*)uncompr, "garbage");
  1124 
  1125 	d_stream.zalloc = (alloc_func)0;
  1126 	d_stream.zfree = (free_func)0;
  1127 	d_stream.opaque = (voidpf)0;
  1128 
  1129 	d_stream.next_in  = compr;
  1130 	d_stream.avail_in = 0;
  1131 	d_stream.next_out = uncompr;
  1132 
  1133 	res = inflateInit(&d_stream);
  1134 
  1135 	if(res<0)
  1136 		{
  1137 		free(compr);
  1138 		free(uncompr);
  1139 		return KErrNoMemory;	
  1140 		}
  1141 	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) 
  1142 		{
  1143 		d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
  1144 		err = inflate(&d_stream, Z_SYNC_FLUSH);
  1145 
  1146 		if (err == Z_STREAM_END || err == Z_MEM_ERROR) break;
  1147 		}
  1148 	//inflate() should normally be called until it returns Z_STREAM_END 
  1149 
  1150 	if(err == Z_MEM_ERROR)
  1151 		{
  1152 		err = inflateEnd(&d_stream);
  1153 		free(compr);
  1154 		free(uncompr);
  1155 		return err;
  1156 		}
  1157 	err = inflateEnd(&d_stream);
  1158 
  1159 	if (err != Z_OK)  
  1160 		{
  1161 		res = KErrGeneral;     			
  1162 		} 
  1163 	else
  1164 		{
  1165 		res=KErrNone ;
  1166 		}
  1167 	free(compr);
  1168 	free(uncompr);
  1169 	return res;
  1170 	}
  1171 
  1172 
  1173 /**
  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
  1179  */  
  1180 TInt CTestZlib::TestInflate_fail1()
  1181 	{
  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)
  1188 		{
  1189 		return KErrNoMemory;
  1190 		}
  1191 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1192 	if (uncompr == Z_NULL) 
  1193 		{
  1194 		free(compr);
  1195 		return KErrNoMemory;
  1196 		}
  1197 
  1198 	// test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  1199 	res = Test_deflate(compr, comprLen);
  1200 	if(res<0)
  1201 		{
  1202 		free(compr);
  1203 		free(uncompr);
  1204 		return KErrNoMemory;	
  1205 		}
  1206 
  1207 	int err;
  1208 	z_stream d_stream; /* decompression stream */
  1209 
  1210 	strcpy((char*)uncompr, "garbage");
  1211 
  1212 	d_stream.zalloc = (alloc_func)0;
  1213 	d_stream.zfree = (free_func)0;
  1214 	d_stream.opaque = (voidpf)0;
  1215 
  1216 	d_stream.next_in  = compr;
  1217 	d_stream.avail_in = 0;
  1218 	d_stream.next_out = NULL;
  1219 
  1220 	err = inflateInit(&d_stream);
  1221 
  1222 	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
  1223 		{
  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;
  1228 		}
  1229 	//inflate() should normally be called until it returns Z_STREAM_END 
  1230 
  1231 	err = inflateEnd(&d_stream);
  1232 
  1233 	if (err != Z_OK)  
  1234 		{
  1235 		res = KErrGeneral;     			
  1236 		} 
  1237 	else
  1238 		{
  1239 		res=KErrNone ;
  1240 		}
  1241 	free(compr);
  1242 	free(uncompr);
  1243 	return res;
  1244 	}
  1245 
  1246 /**
  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
  1252  */  
  1253 TInt CTestZlib::TestInflate_fail2()
  1254 	{
  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)
  1261 		{
  1262 		return KErrNoMemory;
  1263 		}
  1264 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1265 	if (uncompr == Z_NULL) 
  1266 		{
  1267 		free(compr);
  1268 		return KErrNoMemory;
  1269 		}
  1270 	res = Test_deflate(compr, comprLen);
  1271 	if(res<0)
  1272 		{
  1273 		free(compr);
  1274 		free(uncompr);
  1275 		return KErrNoMemory;	
  1276 		}
  1277 
  1278 	int err;
  1279 	z_stream d_stream; /* decompression stream */
  1280 
  1281 	strcpy((char*)uncompr, "garbage");
  1282 
  1283 	d_stream.zalloc = (alloc_func)0;
  1284 	d_stream.zfree = (free_func)0;
  1285 	d_stream.opaque = (voidpf)0;
  1286 
  1287 	d_stream.next_in  = compr;
  1288 	d_stream.avail_in = 0;
  1289 	d_stream.next_out = uncompr;
  1290 
  1291 	err = inflateInit(&d_stream);
  1292 
  1293 	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) 
  1294 		{
  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;      
  1298 		}
  1299 	//inflate() should normally be called until it returns Z_STREAM_END 
  1300 	err = inflateEnd(&d_stream);
  1301 
  1302 	if (err != Z_OK)  
  1303 		{
  1304 		res = KErrGeneral;     			
  1305 		} 
  1306 	else
  1307 		{
  1308 		res=KErrNone ;
  1309 		}
  1310 	free(compr);
  1311 	free(uncompr);
  1312 	return res;
  1313 	}
  1314 
  1315 /**
  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
  1321  */    
  1322 TInt CTestZlib::TestInflate_fail3()
  1323 	{
  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)
  1330 		{
  1331 		return KErrNoMemory;
  1332 		}
  1333 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1334 	if (uncompr == Z_NULL) 
  1335 		{
  1336 		free(compr);
  1337 		return KErrNoMemory;
  1338 		}
  1339 	res = Test_deflate(compr, comprLen);
  1340 	if(res<0)
  1341 		{
  1342 		free(compr);
  1343 		free(uncompr);
  1344 		return KErrNoMemory;	
  1345 		}
  1346 
  1347 	int err;
  1348 	z_stream d_stream; /* decompression stream */
  1349 
  1350 	strcpy((char*)uncompr, "garbage");
  1351 
  1352 	d_stream.zalloc = (alloc_func)0;
  1353 	d_stream.zfree = (free_func)0;
  1354 	d_stream.opaque = (voidpf)0;
  1355 
  1356 	d_stream.next_in  = NULL;
  1357 	d_stream.avail_in = 0;
  1358 	d_stream.next_out = uncompr;
  1359 
  1360 	err = inflateInit(&d_stream);
  1361 
  1362 	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
  1363 		{
  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;
  1368 		}
  1369 	//inflate() should normally be called until it returns Z_STREAM_END 
  1370 
  1371 	err = inflateEnd(&d_stream);
  1372 
  1373 	if (err != Z_OK)  
  1374 		{
  1375 		res = KErrGeneral;     			
  1376 		} 
  1377 	else
  1378 		{
  1379 		res=KErrNone ;
  1380 		}
  1381 	free(compr);
  1382 	free(uncompr);
  1383 	return res;
  1384 	}
  1385 
  1386 /**
  1387  * Function Name : test_compress_positive
  1388  * TestCase Description: This is a global function used by many test functions
  1389  */ 
  1390 TInt test_compress_positive(Byte * compr,uLong comprLen,Byte * /*uncompr*/,uLong /*uncomprLen*/)
  1391 	{
  1392 	TInt res = KErrNone ;
  1393 	int err;
  1394 	uLong len = (uLong)strlen(hello)+1;
  1395 
  1396 	err = compress(compr, &comprLen, (const Bytef*)hello, len);
  1397 	if(err < 0)
  1398 		{  	
  1399 		res = KErrNoMemory;
  1400 		}
  1401 
  1402 	if(err == 0)
  1403 		{  	
  1404 		res = KErrNone ;
  1405 		} 
  1406 	else
  1407 		{    	
  1408 		res = KErrGeneral;
  1409 		}   
  1410 	return res;
  1411 	}
  1412 
  1413 /**
  1414  * Function Name : test_inflateend_positive
  1415  * TestCase Description: This is a global function used by many test functions
  1416  */ 
  1417 TInt test_inflateend_positive(Byte * compr,uLong comprLen,Byte * uncompr,uLong uncomprLen)
  1418 	{ 
  1419 	TInt res = KErrNone ;
  1420 	int err;
  1421 	z_stream d_stream; // decompression stream
  1422 
  1423 	strcpy((char*)uncompr, "garbage");
  1424 
  1425 	d_stream.zalloc = (alloc_func)0;
  1426 	d_stream.zfree = (free_func)0;
  1427 	d_stream.opaque = (voidpf)0;
  1428 
  1429 	d_stream.next_in  = compr;
  1430 	d_stream.avail_in = 0;
  1431 	d_stream.next_out = uncompr;
  1432 
  1433 	err = inflateInit(&d_stream);
  1434 	if(err <0)
  1435 		{
  1436 		return KErrNoMemory;
  1437 		}
  1438 
  1439 	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
  1440 		{
  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;
  1444 		if(err<0) break;
  1445 		}
  1446 
  1447 	err = inflateEnd(&d_stream);
  1448 	if (err != Z_OK)  
  1449 		{
  1450 		res = KErrGeneral;     			
  1451 		} 
  1452 	else
  1453 		{
  1454 		res=KErrNone ;
  1455 		}
  1456 	return res;
  1457 	}
  1458 
  1459 
  1460 /**
  1461  * Function Name : TestInflateend
  1462  * TestCase Description: 1.	Compress the sample data using deflate
  1463  *						2.	inflate to decompress the data
  1464  *						3.	inflateEnd
  1465  * Return Value: Z_OK
  1466  */
  1467 TInt CTestZlib::TestInflateend()
  1468 	{
  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)
  1475 		{
  1476 		return KErrNoMemory;
  1477 		}
  1478 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1479 	if (uncompr == Z_NULL) 
  1480 		{
  1481 		free(compr);
  1482 		return KErrNoMemory;
  1483 		}
  1484 	res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  1485 	if(res<0)
  1486 		{
  1487 		free(compr);
  1488 		free(uncompr);
  1489 		return KErrNoMemory;	
  1490 		}
  1491 	res = Test_deflate(compr, comprLen);
  1492 	if(res<0)
  1493 		{
  1494 		free(compr);
  1495 		free(uncompr);
  1496 		return KErrNoMemory;	
  1497 		}
  1498 	res = test_inflateend_positive(compr, comprLen, uncompr, uncomprLen);
  1499 	if(res <0)    
  1500 		{
  1501 		free(compr);
  1502 		free(uncompr);
  1503 		return res;
  1504 		}
  1505 	else if(res==0)
  1506 		{ 
  1507 		res = KErrNone;    
  1508 		}
  1509 	else
  1510 		{    
  1511 		res = KErrGeneral;            
  1512 		} 
  1513 	free(compr);
  1514 	free(uncompr);
  1515 	return res;
  1516 	}
  1517 
  1518 /**
  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
  1524  */ 
  1525 TInt CTestZlib::TestInflateend_fail()
  1526 	{
  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)
  1533 		{
  1534 		return KErrNoMemory;
  1535 		}
  1536 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1537 	if (uncompr == Z_NULL) 
  1538 		{
  1539 		free(compr);
  1540 		return KErrNoMemory;
  1541 		}
  1542 	res=test_compress(compr, comprLen, uncompr, uncomprLen);
  1543 	if(res<0)
  1544 		{
  1545 		free(compr);
  1546 		free(uncompr);
  1547 		return KErrNoMemory;	
  1548 		}
  1549 	res = Test_deflate(compr, comprLen);
  1550 	if(res<0)
  1551 		{
  1552 		free(compr);
  1553 		free(uncompr);
  1554 		return KErrNoMemory;	
  1555 		}
  1556 	int ret=  inflateEnd(NULL);
  1557 	if(ret==0)
  1558 		{
  1559 		res = KErrGeneral;    	
  1560 		}
  1561 	else
  1562 		{    	
  1563 		res = KErrNone;
  1564 		}   
  1565 	free(compr);
  1566 	free(uncompr);
  1567 	return res;
  1568 	}
  1569 
  1570 /**
  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
  1576  */  
  1577 TInt CTestZlib::TestInflateReset()
  1578 	{  
  1579 	TInt res=KErrNone;
  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;
  1585 
  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)
  1591 		{
  1592 		return KErrNoMemory;
  1593 		}
  1594 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1595 	if (uncompr == Z_NULL) 
  1596 		{
  1597 		free(compr);
  1598 		return KErrNoMemory;
  1599 		}
  1600 
  1601 	res = Test_deflate(compr, comprLen);
  1602 	if(res<0)
  1603 		{
  1604 		free(compr);
  1605 		free(uncompr);
  1606 		return KErrNoMemory;	
  1607 		}
  1608 	d_stream.next_in  = compr;
  1609 	d_stream.avail_in = 0;
  1610 	d_stream.next_out = uncompr;
  1611 	version=zlibVersion();
  1612 	int err;
  1613 	err = inflateInit_(&d_stream,(char*)version, sizeof(d_stream));
  1614 	if(err<0)
  1615 		{
  1616 		free(compr);
  1617 		free(uncompr);
  1618 		return KErrNoMemory;	
  1619 		}
  1620 
  1621 	err=inflateReset(&d_stream);
  1622 	if(err<0)
  1623 		{
  1624 		inflateEnd(&d_stream);
  1625 		free(compr);
  1626 		free(uncompr);
  1627 		return KErrNoMemory;	
  1628 		}
  1629 	if(err!=0)
  1630 		{
  1631 		res=KErrGeneral;
  1632 		}
  1633 	free(compr);
  1634 	free(uncompr);
  1635 	res=inflateEnd(&d_stream);
  1636 	return res;
  1637 	}
  1638 
  1639 
  1640 /**
  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
  1646  */   
  1647 TInt CTestZlib::TestInflateResetfail1()
  1648 	{
  1649 	TInt res=KErrNone;
  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;
  1655 
  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)
  1661 		{
  1662 		return KErrNoMemory;
  1663 		}
  1664 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1665 	if (uncompr == Z_NULL) 
  1666 		{
  1667 		free(compr);
  1668 		return KErrNoMemory;
  1669 		}
  1670 
  1671 	res = Test_deflate(compr, comprLen);
  1672 	if(res<0)
  1673 		{
  1674 		free(compr);
  1675 		free(uncompr);
  1676 		return KErrNoMemory;	
  1677 		}
  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)
  1685 		{
  1686 		res=KErrGeneral;
  1687 		}
  1688 	res=inflateEnd(&d_stream);
  1689 	if(res!=0)
  1690 		{
  1691 		res=KErrGeneral;
  1692 		}
  1693 	free(compr);
  1694 	free(uncompr);
  1695 	return res;
  1696 	}
  1697 
  1698 /**
  1699  * Function Name : TestInflateInit2_
  1700  * TestCase Description: Test inflateInit2_
  1701  * Return Value: Z_OK
  1702  */     
  1703 TInt CTestZlib::TestInflateInit2_()
  1704 	{ 
  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;
  1711 
  1712 	version = zlibVersion();
  1713 	TInt ret =  inflateInit2_(&d_stream,15,version, sizeof(d_stream));
  1714 	if(ret==0)
  1715 		{ 
  1716 		res = KErrNone;
  1717 		}
  1718 	else
  1719 		{     	
  1720 		return ret; 
  1721 		} 
  1722 	inflateEnd(&d_stream);
  1723 	return res;       
  1724 	}
  1725 
  1726 /**
  1727  * Function Name : TestInflateInit_
  1728  * TestCase Description: Test inflateInit_
  1729  * Return Value: Z_OK
  1730  */
  1731 TInt CTestZlib::TestInflateInit_()
  1732 	{ 
  1733 	TInt res = KErrNone ;
  1734 	z_stream d_stream; 
  1735 	const char * version;
  1736 	d_stream.zalloc = (alloc_func)0;
  1737 	d_stream.zfree = (free_func)0;
  1738 	d_stream.opaque = (voidpf)0;
  1739 
  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)
  1745 		{
  1746 		return KErrNoMemory;
  1747 		}
  1748 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1749 	if (uncompr == Z_NULL) 
  1750 		{
  1751 		free(compr);
  1752 		return KErrNoMemory;
  1753 		}
  1754 	res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  1755 	if(res<0)
  1756 		{
  1757 		free(compr);
  1758 		free(uncompr);
  1759 		return KErrNoMemory;	
  1760 		}
  1761 
  1762 	res = Test_deflate(compr, comprLen);
  1763 	if(res<0)
  1764 		{
  1765 		free(compr);
  1766 		free(uncompr);
  1767 		return KErrNoMemory;	
  1768 		}
  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));
  1774 	if(ret==0)
  1775 		{ 
  1776 		res = KErrNone;
  1777 		}
  1778 	else
  1779 		{    
  1780 		res = KErrGeneral;   
  1781 		}    
  1782 	inflateEnd(&d_stream);
  1783 	free(compr);
  1784 	free(uncompr);
  1785 	return res;   
  1786 	}
  1787 
  1788 /**
  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
  1793  */  
  1794 TInt CTestZlib::TestInflateInit2_negative()
  1795 	{ 
  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;
  1802 
  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)
  1808 		{
  1809 		return KErrNoMemory;
  1810 		}
  1811 	uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
  1812 	if (uncompr == Z_NULL) 
  1813 		{
  1814 		free(compr);
  1815 		return KErrNoMemory;
  1816 		}
  1817 
  1818 	res = Test_deflate(compr, comprLen);
  1819 	if(res<0)
  1820 		{
  1821 		free(compr);
  1822 		free(uncompr);
  1823 		return KErrNoMemory;	
  1824 		}
  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);
  1830 	if(ret==0)
  1831 		{
  1832 		res = KErrGeneral;    	
  1833 		}
  1834 	else
  1835 		{    	
  1836 		res = KErrNone;
  1837 		}      
  1838 	free(compr);
  1839 	free(uncompr);
  1840 	// inflateEnd(&d_stream);
  1841 	return res;       
  1842 	}
  1843 
  1844 /**
  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
  1849  */ 
  1850 TInt CTestZlib::TestInflateInit_negative()
  1851 	{ 
  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;
  1858 
  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)
  1864 		{
  1865 		return KErrNoMemory;
  1866 		}
  1867 	uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
  1868 	if (uncompr == Z_NULL) 
  1869 		{
  1870 		free(compr);
  1871 		return KErrNoMemory;
  1872 		}
  1873 	res = Test_deflate(compr, comprLen);
  1874 	if(res<0)
  1875 		{
  1876 		free(compr);
  1877 		free(uncompr);
  1878 		return KErrNoMemory;	
  1879 		}
  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);
  1885 	if(ret==0)
  1886 		{
  1887 		res = KErrGeneral;    	
  1888 		}
  1889 	else
  1890 		{    	
  1891 		res = KErrNone;
  1892 		}   
  1893 	// inflateEnd(&d_stream); 
  1894 	free(compr);
  1895 	free(uncompr);
  1896 	return res;    
  1897 	}
  1898 
  1899 /**
  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
  1904  */   
  1905 TInt CTestZlib::TestInflateInit2_versioncheck()
  1906 	{ 
  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;
  1913 
  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)
  1919 		{
  1920 		return KErrNoMemory;
  1921 		}
  1922 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1923 	if (uncompr == Z_NULL) 
  1924 		{
  1925 		free(compr);
  1926 		return KErrNoMemory;
  1927 		}
  1928 
  1929 	res = Test_deflate(compr, comprLen);
  1930 	if(res<0)
  1931 		{
  1932 		free(compr);
  1933 		free(uncompr);
  1934 		return KErrNoMemory;	
  1935 		}
  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);
  1942 	if(ret==0)
  1943 		{
  1944 		res = KErrGeneral;    	
  1945 		}
  1946 	else
  1947 		{    	
  1948 		res = KErrNone;
  1949 		}  
  1950 	free(compr);
  1951 	free(uncompr); 
  1952 	return res;      
  1953 	}
  1954 
  1955 /**
  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
  1960  */ 
  1961 TInt CTestZlib::TestInflateInit_versioncheck()
  1962 	{	 
  1963 	TInt res = KErrNone ;
  1964 
  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;
  1970 
  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)
  1976 		{
  1977 		return KErrNoMemory;
  1978 		}
  1979 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1980 	if (uncompr == Z_NULL) 
  1981 		{
  1982 		free(compr);
  1983 		return KErrNoMemory;
  1984 		}
  1985 	res = Test_deflate(compr, comprLen);
  1986 	if(res<0)
  1987 		{
  1988 		free(compr);
  1989 		free(uncompr);
  1990 		return KErrNoMemory;	
  1991 		}
  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);
  1998 	if(ret==0)
  1999 		{
  2000 		res = KErrGeneral;    	
  2001 		}
  2002 	else
  2003 		{    	
  2004 		res = KErrNone;
  2005 		}   
  2006 	free(compr);
  2007 	free(uncompr);
  2008 	return res;   
  2009 	}
  2010 
  2011 /**
  2012  * Function Name : TestCompress
  2013  * TestCase Description: Test compress()
  2014  * Return Value: Z_OK
  2015  */  
  2016 TInt CTestZlib::TestCompress()
  2017 	{ 
  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)
  2024 		{
  2025 		return KErrNoMemory;
  2026 		}
  2027 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  2028 	if (uncompr == Z_NULL) 
  2029 		{
  2030 		free(compr);
  2031 		return KErrNoMemory;
  2032 		}
  2033 	res=test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  2034 	free(compr);
  2035 	free(uncompr);
  2036 	return res;
  2037 	}
  2038 
  2039 /**
  2040  * Function Name : test_compress_negative
  2041  * TestCase Description: This is a global function used by many test functions
  2042  */
  2043 TInt test_compress_negative(Byte * compr,uLong comprLen,Byte * /*uncompr*/,uLong /*uncomprLen*/)
  2044 	{
  2045 	TInt res = KErrNone ;
  2046 	int err;
  2047 	uLong len = (uLong)strlen(hello)+1;
  2048 	err = compress(compr, &comprLen, (const Bytef*)hello, len);
  2049 	if(err == 0)
  2050 		{  
  2051 		res = KErrGeneral;   
  2052 		} 
  2053 	else
  2054 		{    	
  2055 		res =    KErrNone ;
  2056 		}   
  2057 	return res;
  2058 	}
  2059 
  2060 /**
  2061  * Function Name : TestCompress_negative
  2062  * TestCase Description: Call compress with compression length less than required
  2063  * Return Value: Z_BUF_ERROR
  2064  */
  2065 TInt CTestZlib::TestCompress_negative()
  2066 	{
  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)
  2073 		{
  2074 		return KErrNoMemory;
  2075 		}
  2076 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  2077 	if (uncompr == Z_NULL) 
  2078 		{
  2079 		free(compr);
  2080 		return KErrNoMemory;
  2081 		}
  2082 	res=test_compress_negative(compr, comprLen, uncompr, uncomprLen);
  2083 	free(compr);
  2084 	free(uncompr);
  2085 	return res;
  2086 	}
  2087 
  2088 /**
  2089  * Function Name : TestCompress2_positive
  2090  * TestCase Description: Test compress2 with valid arguments
  2091  * Return Value: Z_OK
  2092  */
  2093 TInt CTestZlib::TestCompress2_positive()
  2094 	{
  2095 	TInt res = KErrNone ;
  2096 	int err;
  2097 	uLong len = (uLong)strlen(hello)+1;
  2098 
  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)
  2104 		{
  2105 		return KErrNoMemory;
  2106 		}
  2107 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  2108 	if (uncompr == Z_NULL) 
  2109 		{
  2110 		free(compr);
  2111 		return KErrNoMemory;
  2112 		}
  2113 
  2114 	err=compress2(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);      
  2115 
  2116 	if(err == 0)
  2117 		{  	
  2118 		res = KErrNone ;
  2119 		} 
  2120 	else
  2121 		{    	
  2122 		res = KErrGeneral;
  2123 		}   
  2124 	free(compr);
  2125 	free(uncompr);
  2126 	return res;
  2127 	}
  2128 
  2129 /**
  2130  * Function Name : TestCompress2_negative
  2131  * TestCase Description: Test compress2 with compression length less than required  
  2132  * Return Value: Z_BUF_ERROR
  2133  */
  2134 TInt CTestZlib::TestCompress2_negative()
  2135 	{
  2136 	int err;
  2137 	TInt res = KErrNone ;
  2138 	uLong len = (uLong)strlen(hello)+1;
  2139 	Byte *compr;
  2140 	uLong comprLen = 20*sizeof(int); 
  2141 	compr    = (Byte*)calloc((uInt)comprLen, 1);
  2142 	if (compr == Z_NULL)
  2143 		{
  2144 		return KErrNoMemory;
  2145 		}
  2146 	err=compress2(compr, &comprLen, (const Bytef*)hello, len,14);   
  2147 	if(err == 0)
  2148 		{  
  2149 		res = KErrGeneral;     
  2150 		} 
  2151 	else
  2152 		{    	
  2153 		res = KErrNone ;
  2154 		}   
  2155 	free(compr);
  2156 	return res;
  2157 	}
  2158 
  2159 
  2160 /**
  2161  * Function Name : test_compressbound
  2162  * TestCase Description: This is a global function used by many test functions
  2163  */
  2164 TInt test_compressbound(Byte * compr,uLong comprLen)
  2165 	{
  2166 	TInt res = KErrNone ;
  2167 	int err;
  2168 	uLong sourceLen = (uLong)strlen(hello)+1;
  2169 	err=compress(compr, &comprLen, (const Bytef*)hello, sourceLen);
  2170 	if(err==0)
  2171 		{    	
  2172 		int x =  compressBound(sourceLen);
  2173 		if(x > sourceLen)
  2174 			{  	
  2175 			res = KErrNone ;         
  2176 			} 
  2177 		else
  2178 			{    	
  2179 			res = KErrGeneral;     
  2180 			}   
  2181 		}
  2182 	else
  2183 		{
  2184 		res = KErrGeneral;     
  2185 		}
  2186 	return res;
  2187 	}
  2188 
  2189 /**
  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
  2194  *				
  2195  */
  2196 TInt CTestZlib::TestCompressbound()
  2197 	{     
  2198 	TInt res = KErrNone ;
  2199 	Byte *compr;
  2200 	uLong comprLen =20*sizeof(int);
  2201 	compr    = (Byte*)calloc((uInt)comprLen, 1);
  2202 	if (compr == Z_NULL)
  2203 		{
  2204 		return KErrNoMemory;
  2205 		}
  2206 
  2207 	res = test_compressbound(compr, comprLen);
  2208 	free(compr);
  2209 	return res;
  2210 	}
  2211 
  2212 /**
  2213  * Function Name : test_deflatebound
  2214  * TestCase Description: This is a global function used by many test functions
  2215  */
  2216 TInt test_deflatebound(Bytef *dest,  uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
  2217 	{	 
  2218 	TInt res = KErrNone ;
  2219 	int err;
  2220 	z_stream stream;
  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) 
  2226 		{
  2227 		res = KErrGeneral; 
  2228 		}
  2229 	stream.zalloc = (alloc_func)0;
  2230 	stream.zfree = (free_func)0;
  2231 	stream.opaque = (voidpf)0;
  2232 
  2233 	err = deflateInit(&stream, level);
  2234 	if (err == Z_OK) 
  2235 		{
  2236 		int y= deflateBound(&stream, sourceLen);
  2237 		if(y > sourceLen)
  2238 			{  
  2239 			res = KErrNone ;
  2240 			} 
  2241 		else
  2242 			{   	
  2243 			res = KErrGeneral;      	
  2244 			}   
  2245 		}
  2246 	else
  2247 		{
  2248 		res = KErrGeneral;      
  2249 		return res;   
  2250 		}    
  2251 	err=deflateEnd(&stream);
  2252 	if (err != Z_OK) 
  2253 		{
  2254 		res = KErrGeneral;      
  2255 		}
  2256 	return res;
  2257 	}
  2258 
  2259 /**
  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
  2264  */
  2265 TInt CTestZlib::TestDeflatebound()
  2266 	{    
  2267 	TInt res = KErrNone ;
  2268 
  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)
  2275 		{
  2276 		return KErrNoMemory;
  2277 		}
  2278 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  2279 	if(uncompr == Z_NULL) 
  2280 		{
  2281 		free(compr);
  2282 		return KErrNoMemory;
  2283 		}
  2284 	res=test_deflatebound(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);   
  2285 	free(compr);
  2286 	free(uncompr);
  2287 	return res;
  2288 	}
  2289 
  2290 /**
  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
  2294  *						
  2295  * Return Value: Z_OK
  2296  */  
  2297 TInt CTestZlib::TestDeflateparams()
  2298 	{     
  2299 	TInt res = KErrNone ;
  2300 	z_stream c_stream; /* compression stream */
  2301 	int err;
  2302 	Byte * compr;
  2303 	uLong comprLen = 20*sizeof(int); 
  2304 	compr = (Byte*)calloc((uInt)comprLen, 1);
  2305 	if (compr == Z_NULL)
  2306 		{
  2307 		return KErrNoMemory;
  2308 		}
  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;
  2313 
  2314 	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  2315 	if(err <0)
  2316 		{
  2317 		free(compr);
  2318 		return err;	
  2319 		}
  2320 	c_stream.next_in  = (Bytef*)hello;
  2321 	c_stream.next_out = compr;
  2322 
  2323 	err= deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
  2324 	if(err != 0)
  2325 		{    	
  2326 		res = KErrGeneral;
  2327 		}
  2328 	deflateEnd(&c_stream);
  2329 	free(compr);
  2330 	return res;
  2331 	}
  2332 
  2333 /**
  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
  2338  */  
  2339 TInt CTestZlib::TestDeflateparamsfail1()
  2340 	{     
  2341 	TInt res = KErrNone ;
  2342 	z_stream c_stream; /* compression stream */
  2343 	int err;
  2344 	Byte * compr;
  2345 	uLong comprLen = 20*sizeof(int); 
  2346 	compr = (Byte*)calloc((uInt)comprLen, 1);
  2347 	if (compr == Z_NULL)
  2348 		{
  2349 		return KErrNoMemory;
  2350 		}
  2351 
  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;
  2356 
  2357 	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  2358 	if(err<0)
  2359 		{
  2360 		free(compr);
  2361 		return err;	
  2362 		}
  2363 
  2364 	c_stream.next_in = (Bytef*)hello;
  2365 	c_stream.next_out = compr;
  2366 
  2367 	err= deflateParams(&c_stream, 12, Z_DEFAULT_STRATEGY);
  2368 	if(err != 0)
  2369 		{    	
  2370 		res =  KErrNone;
  2371 		}
  2372 	deflateEnd(&c_stream);
  2373 	free(compr);
  2374 	return res;
  2375 	}
  2376 
  2377 /**
  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
  2382  */ 
  2383 TInt CTestZlib::TestDeflateparamsfail2()
  2384 	{     
  2385 	TInt res = KErrNone ;   
  2386 	int err= deflateParams(NULL, 12, Z_DEFAULT_STRATEGY);
  2387 	if(err != 0)
  2388 		{    	
  2389 		res =  	KErrNone;
  2390 		}
  2391 
  2392 	return res;
  2393 	}
  2394 
  2395 /**
  2396  * Function Name : TestCrcinit
  2397  * TestCase Description: Test crc32 with proper arguments
  2398  * Return Value: KErrNone
  2399  */   
  2400 TInt CTestZlib::TestCrcinit()
  2401 	{
  2402 	TInt res = KErrNone ;
  2403 	unsigned long j=0L;
  2404 	long crc = crc32(j,0, 0);
  2405 
  2406 	if(crc==0)
  2407 		{  
  2408 		res = KErrNone ;
  2409 		} 
  2410 	else
  2411 		{
  2412 		res = KErrGeneral;      	
  2413 		}   
  2414 
  2415 	return res; 
  2416 	}
  2417 
  2418 /**
  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
  2423  */    
  2424 TInt CTestZlib::TestCrc()
  2425 	{
  2426 	TInt res = KErrNone ;
  2427 	unsigned char  buffer[5]="1234";
  2428 	unsigned int i=4;
  2429 	unsigned long j=0L;
  2430 
  2431 	long crc1 = crc32(j,0, 0);
  2432 
  2433 	long crc = crc32(crc1, &buffer[0], i);
  2434 
  2435 	INFO_PRINTF2(_L("buf %x"),crc);
  2436 
  2437 	if(crc==(long)2615402659LL)
  2438 		{  
  2439 		res = KErrNone ;
  2440 		} 
  2441 	else
  2442 		{
  2443 		res = KErrGeneral;      	
  2444 		}   
  2445 
  2446 	return res;           
  2447 	}
  2448 
  2449 /**
  2450  * Function Name : TestGet_crc_table
  2451  * TestCase Description: Test get_crc_table
  2452  * Return Value: KErrNone
  2453  */    
  2454 TInt CTestZlib::TestGet_crc_table()
  2455 	{ 
  2456 	TInt res = KErrNone ;
  2457 	const unsigned long* pcrc_32_tab;
  2458 
  2459 	pcrc_32_tab = get_crc_table();
  2460 
  2461 	if(pcrc_32_tab)
  2462 		{  
  2463 		res = KErrNone ;
  2464 		} 
  2465 	else
  2466 		{
  2467 		res = KErrGeneral;      	
  2468 		}   
  2469 
  2470 	return res;  
  2471 	}
  2472 
  2473 /**
  2474  * Function Name : TestDeflateInit_
  2475  * TestCase Description: deflateInit_ with all valid arguments
  2476  * Return Value: KErrNone
  2477  */     
  2478 TInt CTestZlib::TestDeflateInit_()
  2479 	{
  2480 	TInt res = KErrNone ;
  2481 	z_stream stream;
  2482 	int err;
  2483 
  2484 	uLong sourceLen = (uLong)strlen(hello)+1;
  2485 	Byte *compr;
  2486 	uLong comprLen = 10*sizeof(int); 
  2487 	compr    = (Byte*)calloc((uInt)comprLen, 1);
  2488 	if (compr == Z_NULL)
  2489 		{
  2490 		return KErrNoMemory;
  2491 		}
  2492 
  2493 	stream.zalloc = (alloc_func)0;
  2494 	stream.zfree = (free_func)0;
  2495 	stream.opaque = (voidpf)0;
  2496 
  2497 	err= deflateInit_(&stream, Z_DEFAULT_COMPRESSION,  zlibVersion(), sizeof(z_stream));
  2498 
  2499 	if (err != Z_OK) 
  2500 		{	 
  2501 		free(compr);
  2502 		res = KErrGeneral; 
  2503 		return res;
  2504 		} 
  2505 	else  
  2506 		{    	
  2507 		res = KErrNone;
  2508 		}   
  2509 	deflateEnd(&stream);
  2510 	free(compr);
  2511 	return res;
  2512 	}
  2513 
  2514 /**
  2515  * Function Name : TestDeflateInit_level
  2516  * TestCase Description: deflateInit_ with invalid compression level
  2517  * Return Value: Z_STREAM_ERROR
  2518  */     
  2519 TInt CTestZlib::TestDeflateInit_level()
  2520 	{
  2521 	TInt res = KErrNone ;
  2522 	z_stream stream;
  2523 	int err;
  2524 	uLong sourceLen = (uLong)strlen(hello)+1;
  2525 	Byte *compr;
  2526 	uLong comprLen = 10*sizeof(int); 
  2527 	compr = (Byte*)calloc((uInt)comprLen, 1);
  2528 	if (compr == Z_NULL)
  2529 		{
  2530 		return KErrNoMemory;
  2531 		}
  2532 
  2533 	stream.zalloc = (alloc_func)0;
  2534 	stream.zfree = (free_func)0;
  2535 	stream.opaque = (voidpf)0;
  2536 
  2537 	err= deflateInit_(&stream, 11,  zlibVersion(), sizeof(z_stream));
  2538 
  2539 	if (err != Z_OK) 
  2540 		{
  2541 		res = KErrNone;
  2542 		} 
  2543 	else  
  2544 		{    	
  2545 		res = KErrGeneral; 
  2546 		}   
  2547 
  2548 	free(compr);
  2549 	return res;
  2550 	}
  2551 
  2552 
  2553 /**
  2554  * Function Name : TestDeflateInit2_
  2555  * TestCase Description: deflateInit2_ with invalid compression level
  2556  * Return Value: Z_STREAM_ERROR
  2557  */
  2558 TInt CTestZlib::TestDeflateInit2_()
  2559 	{
  2560 	TInt res = KErrNone ;
  2561 	z_stream stream;
  2562 	int err;
  2563 
  2564 	uLong sourceLen = (uLong)strlen(hello)+1;
  2565 	Byte *compr;
  2566 	uLong comprLen = 10*sizeof(int); 
  2567 	compr    = (Byte*)calloc((uInt)comprLen, 1);
  2568 	if (compr == Z_NULL)
  2569 		{
  2570 		return KErrNoMemory;
  2571 		}
  2572 
  2573 	stream.zalloc = (alloc_func)0;
  2574 	stream.zfree = (free_func)0;
  2575 	stream.opaque = (voidpf)0;
  2576 
  2577 	err= deflateInit2_(&stream, 11, 8, 15, 8, 0,  zlibVersion(), sizeof(z_stream));
  2578 
  2579 	if (err != Z_OK) 
  2580 		{  	
  2581 		res = KErrNone; 
  2582 		} 
  2583 	else  
  2584 		{    	
  2585 		res = KErrGeneral;
  2586 		}   
  2587 	free(compr);
  2588 	return res;
  2589 	}
  2590 
  2591 
  2592 /**
  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
  2596  */   
  2597 TInt CTestZlib::TestDeflatefail()
  2598 	{	    
  2599 	TInt res = KErrNone ;
  2600 	z_stream c_stream; /* compression stream */
  2601 	int err;
  2602 	Byte * compr;
  2603 	uLong comprLen = 20*sizeof(int); 
  2604 	compr    = (Byte*)calloc((uInt)comprLen, 1);
  2605 	if (compr == Z_NULL)
  2606 		{
  2607 		return KErrNoMemory;
  2608 		}
  2609 
  2610 	uLong len = (uLong)strlen(hello)+1;
  2611 
  2612 	c_stream.zalloc = (alloc_func)0;
  2613 	c_stream.zfree = (free_func)0;
  2614 	c_stream.opaque = (voidpf)0;
  2615 
  2616 	res = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  2617 	if(res <0)
  2618 		{
  2619 		free(compr);
  2620 		return res;	
  2621 		}
  2622 
  2623 	c_stream.next_in  = NULL;//(Bytef*)hello;
  2624 	c_stream.next_out = NULL;//compr;
  2625 
  2626 	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  2627 		{
  2628 		c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
  2629 		err = deflate(&c_stream, Z_NO_FLUSH);
  2630 		if(err == 0)
  2631 			{    	
  2632 			res = KErrGeneral;
  2633 			}
  2634 		else
  2635 			{
  2636 			res=KErrNone;
  2637 			break;
  2638 			} 
  2639 		}
  2640 	/* Finish the stream, still forcing small buffers: */
  2641 	res = deflateEnd(&c_stream);
  2642 	free(compr);
  2643 	return res;
  2644 	}
  2645 
  2646 /**
  2647  * Function Name : TestDeflatefail
  2648  * TestCase Description: Set stream avail_out to NULL and call deflateEnd
  2649  * Return Value: Z_STREAM_ERROR
  2650  */
  2651 TInt CTestZlib::TestDeflatefail2()
  2652 	{    
  2653 	TInt res = KErrNone ;
  2654 	z_stream c_stream; /* compression stream */
  2655 	int err;
  2656 	Byte * compr;
  2657 	uLong comprLen = 20*sizeof(int); 
  2658 
  2659 	compr = (Byte*)calloc((uInt)comprLen, 1);
  2660 	if (compr == Z_NULL)
  2661 		{
  2662 		return KErrNoMemory;
  2663 		}
  2664 
  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;
  2669 
  2670 	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  2671 
  2672 	if(err <0)
  2673 		{
  2674 		free(compr);
  2675 		return err;	
  2676 		}
  2677 	c_stream.next_in = (Bytef*)hello;
  2678 	c_stream.next_out = compr;
  2679 
  2680 	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  2681 		{
  2682 		c_stream.avail_in = 1;
  2683 		c_stream.avail_out = 0; /* fail */
  2684 		err = deflate(&c_stream, Z_NO_FLUSH);
  2685 		if(err == 0)
  2686 			{    	
  2687 			res =  	 KErrGeneral;
  2688 			}
  2689 		else
  2690 			{
  2691 			res=KErrNone;
  2692 			break;
  2693 			}
  2694 		}
  2695 
  2696 	err = deflateEnd(&c_stream);
  2697 	free(compr);
  2698 	return res;
  2699 	}
  2700 
  2701 /**
  2702  * Function Name : TestZlibversion
  2703  * TestCase Description: Test Zlibversion
  2704  * Return Value: Z_OK
  2705  */  
  2706 TInt CTestZlib::TestZlibversion()
  2707 	{  
  2708 	TInt res = KErrNone ;
  2709 	if(strcmp(zlibVersion(), "1.2.3") != 0) 
  2710 		{
  2711 		res=KErrGeneral;
  2712 		ERR_PRINTF1(_L("using incorrect zlib version "));
  2713 		} 
  2714 	return res;
  2715 	}
  2716 
  2717 /**
  2718  * Function Name : TestGzputc
  2719  * TestCase Description: 1. Open a gzfile in read mode
  2720  *						2. Write a character in the file using gzputc
  2721  *						3. Close the file
  2722  * Return Value: KErrNone
  2723  */    
  2724 TInt CTestZlib::TestGzputc()
  2725 	{    
  2726 	TInt res = KErrNone ;
  2727 	TInt res1 = KErrNone ;
  2728 	gzFile file;
  2729 	const char * fname = TESTFILE ;
  2730 	file = gzopen(fname, "wb");
  2731 	if (file == NULL) 
  2732 		{
  2733 		res = KErrGeneral;
  2734 		return res;
  2735 		}
  2736 	else
  2737 		{
  2738 		res1=gzputc(file, 'r');
  2739 		if(res1<0)
  2740 			{
  2741 			res = KErrGeneral;
  2742 			} 
  2743 		else  
  2744 			{    	
  2745 			res = KErrNone;
  2746 			}     	
  2747 		}
  2748 	int err=  gzclose(file);
  2749 	if (err != Z_OK)  
  2750 		{
  2751 		res = KErrGeneral; 
  2752 		} 
  2753 	else  
  2754 		{    	
  2755 		res = KErrNone;
  2756 		}   
  2757 	return res;
  2758 	}
  2759 
  2760 /**
  2761  * Function Name : TestGzopen
  2762  * TestCase Description: 1. Open a gzfile in read mode
  2763  *						2. Close the file
  2764  * Return Value: KErrNone
  2765  */    
  2766 TInt CTestZlib::TestGzopen()
  2767 	{
  2768 	TInt res = KErrNone ;
  2769 	gzFile file;
  2770 	const char * fname = TESTFILE ;
  2771 	file = gzopen(fname, "rb");
  2772 	if (file == NULL) 
  2773 		{
  2774 		res = KErrGeneral;
  2775 		return res;
  2776 		}    
  2777 	else
  2778 		{    	
  2779 		res = KErrNone;
  2780 		}
  2781 	int err=gzclose(file);
  2782 	if (err != Z_OK)  
  2783 		{
  2784 		res = KErrGeneral; 
  2785 		} 
  2786 	return res;
  2787 	}
  2788 
  2789 /**
  2790  * Function Name : TestGzopenmode
  2791  * TestCase Description: 1.	Open a gzfile mentioning invalid mode
  2792  * Return Value: KErrNone
  2793  */    
  2794 TInt CTestZlib::TestGzopenmode()
  2795 	{
  2796 	TInt res = KErrNone ;
  2797 	gzFile file;
  2798 	const char * fname = TESTFILE ;
  2799 	file = gzopen(fname, "xyz");
  2800 	if (file == NULL) 
  2801 		{
  2802 		res = KErrNone;
  2803 		}    
  2804 	else
  2805 		{    	
  2806 		res = KErrGeneral;
  2807 		}
  2808 	return res;
  2809 	}
  2810 
  2811 /**
  2812  * Function Name : TestGzopenfail
  2813  * TestCase Description: Open a gzfile mentioning invalid path
  2814  * Return Value: KErrNone
  2815  */ 
  2816 TInt CTestZlib::TestGzopenfail()
  2817 	{
  2818 	TInt res = KErrNone ;
  2819 	gzFile file;
  2820 	const char * fname = NOFILE ;
  2821 	file = gzopen(fname, "wb");
  2822 	if (file == NULL) 
  2823 		{
  2824 		res =KErrNone;
  2825 		}    
  2826 	else
  2827 		{    	
  2828 		res = KErrGeneral;
  2829 		}
  2830 	return res;
  2831 	}
  2832 
  2833 /**
  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
  2838  */    
  2839 TInt CTestZlib::TestGzputcfail()
  2840 	{
  2841 	TInt res = KErrNone ;
  2842 	TInt res1 = KErrNone ;
  2843 	gzFile file;
  2844 	const char * fname = NOFILE ;
  2845 	file = gzopen(fname, "wb");   
  2846 	if (file != NULL) 
  2847 		{
  2848 		res = KErrGeneral;
  2849 		return res;
  2850 		}
  2851 	else
  2852 		{
  2853 		res1=gzputc(file, 'r');
  2854 		if(res1<0)
  2855 			{
  2856 			res = KErrNone;
  2857 			} 
  2858 		else  
  2859 			{    	
  2860 			res = KErrGeneral;
  2861 			}     	
  2862 		}
  2863 
  2864 	int err=  gzclose(file);
  2865 	if (err == Z_OK)  
  2866 		{
  2867 		res = KErrGeneral; 
  2868 		} 
  2869 	else  
  2870 		{    	
  2871 		res = KErrNone;
  2872 		}   
  2873 	return res;
  2874 	}
  2875 
  2876 /**
  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
  2881  *						4. Close the file
  2882  * Return Value: returns the value of the character that was written 
  2883  */    
  2884 TInt CTestZlib::TestGzputcreturn()
  2885 	{
  2886 	TInt res = KErrNone ;
  2887 	TInt res1 = KErrNone ;
  2888 	gzFile file;
  2889 	const char * fname = TESTFILE ;
  2890 	file = gzopen(fname, "wb");
  2891 
  2892 	if (file == NULL) 
  2893 		{
  2894 		res = KErrGeneral;
  2895 		return res;
  2896 		}
  2897 	else
  2898 		{
  2899 		res1=gzputc(file, 'r');
  2900 		if(res1!=(int)'r')
  2901 			{
  2902 			res = KErrGeneral;
  2903 			} 
  2904 		else  
  2905 			{    	
  2906 			res = KErrNone;
  2907 			}     	
  2908 		}
  2909 
  2910 	int err=  gzclose(file);
  2911 	if (err != Z_OK)  
  2912 		{
  2913 		res = KErrGeneral; 
  2914 		} 
  2915 	return res;
  2916 	}
  2917 
  2918 /**
  2919  * Function Name : TestGzputs
  2920  * TestCase Description: 1. Open a gzfile in write mode
  2921  *						2. Write a string into file
  2922  *						3. Close the file
  2923  * Return Value: KErrNone
  2924  */    
  2925 TInt CTestZlib::TestGzputs()
  2926 	{
  2927 	TInt res = KErrNone ;
  2928 	gzFile file;
  2929 	const char * fname = TESTFILE ;
  2930 	file = gzopen(fname, "wb");
  2931 	if (file == NULL) 
  2932 		{
  2933 		res = KErrGeneral;
  2934 		return res;
  2935 		}
  2936 	if (gzputs(file, "ello") != 4) 
  2937 		{
  2938 		ERR_PRINTF1(_L("gzputs err"));
  2939 		}
  2940 	int err=  gzclose(file);
  2941 	if (err != Z_OK)  
  2942 		{
  2943 		res = KErrGeneral; 
  2944 		}       
  2945 	return res;    
  2946 	}
  2947 
  2948 /**
  2949  * Function Name : TestGzputsfail
  2950  * TestCase Description: 1. Open a gzfile in read mode
  2951  *						2. Write a string into file
  2952  *						3. Close the file
  2953  * Return Value: KErrNone
  2954  */      
  2955 TInt CTestZlib::TestGzputsfail()
  2956 	{	
  2957 	TInt res = KErrNone ;
  2958 	gzFile file;
  2959 	const char *fname = TESTFILE ;
  2960 	file = gzopen(fname, "rb");
  2961 	if (file == NULL) 
  2962 		{
  2963 		res = KErrGeneral;
  2964 		return res;
  2965 		}
  2966 	if(gzputs(file, "ello") == 4) 
  2967 		{
  2968 		res= KErrGeneral;
  2969 		}
  2970 	int err=  gzclose(file);
  2971 	if (err != Z_OK)  
  2972 		{
  2973 		res = KErrGeneral; 
  2974 		}       
  2975 	return res;    
  2976 	}
  2977 
  2978 /**
  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
  2982  *						3. Close the file
  2983  * Return Value: KErrNone
  2984  */     
  2985 TInt CTestZlib::TestGzprintf()
  2986 	{
  2987 	TInt res = KErrNone ;
  2988 	gzFile file;
  2989 	const char * fname = TESTFILE ;
  2990 	file = gzopen(fname, "wb");
  2991 	if(file == NULL) 
  2992 		{
  2993 		res = KErrNoMemory;
  2994 		return res;
  2995 		}   
  2996 	if(gzprintf(file, ", %s!", "hello") != 8) 
  2997 		{
  2998 		ERR_PRINTF1(_L("gzprintf err"));
  2999 		return KErrNone;
  3000 		}
  3001 
  3002 	int err = gzclose(file);
  3003 	if(err == 0)
  3004 		{  	
  3005 		res = KErrNone ;
  3006 		} 
  3007 	else
  3008 		{	    	
  3009 		res =res= KErrGeneral;
  3010 		} 
  3011 	return res;
  3012 	}
  3013 
  3014 /**
  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
  3018  *						3. Close the file
  3019  * Return Value: KErrNone
  3020  */    
  3021 TInt CTestZlib::TestGzprintf_trying()
  3022 	{
  3023 	TInt res = KErrNone ;
  3024 	gzFile file;
  3025 	const char * fname = TESTFILE ;
  3026 	file = gzopen(fname, "rb");
  3027 	if (file == NULL) 
  3028 		{
  3029 		res = KErrNoMemory;
  3030 		return res;
  3031 		}   
  3032 	if (gzprintf(file, ", %s!", "hello") != 8) 
  3033 		{
  3034 		gzclose(file);
  3035 		res=KErrGeneral;
  3036 		ERR_PRINTF1(_L("gzprintf err"));
  3037 		return KErrNone;
  3038 		}
  3039 	int err = gzclose(file);
  3040 	if(err == 0)
  3041 		{  	
  3042 		res = KErrNone ;
  3043 		} 
  3044 	else
  3045 		{    	
  3046 		res = KErrGeneral;
  3047 		}   
  3048 	return res;
  3049 	}
  3050 
  3051 /**
  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
  3055  *						3. Close the file
  3056  * Return Value: KErrNone
  3057  */
  3058 TInt CTestZlib::TestGzwrite()
  3059 	{
  3060 	TInt res = KErrNone ;
  3061 	gzFile file;
  3062 	uInt size ,len;
  3063 	const char *s="ritesh";
  3064 	len=strlen(s);
  3065 	const char * fname = TESTFILE ;
  3066 	file = gzopen(fname, "wb");
  3067 	if (file == Z_NULL)  
  3068 		{
  3069 		res = KErrGeneral; 
  3070 		return res;
  3071 		}     
  3072 	size = gzwrite(file, (char*)s, (unsigned)strlen(s));
  3073 	if(len!=size)
  3074 		{
  3075 		res = KErrGeneral;
  3076 		}
  3077 	int err=  gzclose(file);
  3078 	if (err != Z_OK)  
  3079 		{
  3080 		res = KErrGeneral; 
  3081 		}     
  3082 	return res;
  3083 	}
  3084 
  3085 /**
  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
  3089  *						3. Close the file
  3090  * Return Value: Z_NULL
  3091  */
  3092 TInt CTestZlib::TestGzwritefail()
  3093 	{   
  3094 	TInt res = KErrNone ;
  3095 	gzFile file;
  3096 	uInt size ,len;
  3097 	const char *s="ritesh";
  3098 	len=strlen(s);
  3099 	const char * fname = TESTFILE ;
  3100 	file = gzopen(fname, "rb"); //read mode
  3101 	if (file == Z_NULL)  
  3102 		{
  3103 		res = KErrNoMemory; 
  3104 		return res;
  3105 		}     
  3106 	size = gzwrite(file, (char*)s, (unsigned)strlen(s));
  3107 	if(len!=size)
  3108 		{
  3109 		res = KErrNone;
  3110 		}
  3111 	int err=  gzclose(file);
  3112 	if (err != Z_OK)  
  3113 		{
  3114 		res = KErrGeneral;     	    	
  3115 		}     
  3116 	return res;
  3117 	}
  3118 
  3119 TInt testgztell( const char * fname, Byte * uncompr,uLong  uncomprLen)   
  3120 	{
  3121 	int err=0;
  3122 	int len = (int)strlen(hello)+1;
  3123 	gzFile file;
  3124 	z_off_t pos;
  3125 
  3126 	file = gzopen(fname, "wb");
  3127 	if (file == NULL) 
  3128 		{
  3129 		if (file == NULL) 
  3130 			{
  3131 			err = KErrGeneral; 
  3132 			return err;        
  3133 			}
  3134 
  3135 		}
  3136 	gzputc(file, 'h');
  3137 	if(gzputs(file, "ello") != 4) 
  3138 		{
  3139 		//fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
  3140 		}
  3141 	if(gzprintf(file, ", %s!", "hello") != 8) 
  3142 		{
  3143 		//fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
  3144 		}
  3145 	gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
  3146 	gzclose(file);
  3147 
  3148 	file = gzopen(fname, "rb");
  3149 	if(file == NULL) 
  3150 		{
  3151 		err = KErrGeneral; 
  3152 		return err;        
  3153 		}
  3154 	strcpy((char*)uncompr, "garbage");
  3155 	if(gzread(file, uncompr, (unsigned)uncomprLen) != len) 
  3156 		{
  3157 		//fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
  3158 		//exit(1);
  3159 		}
  3160 	if(strcmp((char*)uncompr, hello)) 
  3161 		{
  3162 		//fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
  3163 		////exit(1);
  3164 		}
  3165 	else
  3166 		{
  3167 		//printf("gzread(): %s\n", (char*)uncompr);
  3168 		}
  3169 
  3170 	pos = gzseek(file, -8L, SEEK_CUR);
  3171 	if (pos != 6 || gztell(file) != pos) 
  3172 		{
  3173 		err=-1;   
  3174 		}
  3175 	err=  gzclose(file);
  3176 	return err;
  3177 	}
  3178 
  3179 TInt CTestZlib::TestGztell()
  3180 	{ 
  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)
  3187 		{
  3188 		return KErrNoMemory;
  3189 		}
  3190 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  3191 	if (uncompr == Z_NULL) 
  3192 		{
  3193 		free(compr);
  3194 		return KErrNoMemory;
  3195 		}
  3196 	test_compress(compr, comprLen, uncompr, uncomprLen);
  3197 	int err = testgztell(TESTFILE,uncompr, uncomprLen);
  3198 	if(err<0)
  3199 		{
  3200 		res= KErrGeneral;	
  3201 		}
  3202 	free(compr);
  3203 	free(uncompr);
  3204 	return res;
  3205 	}
  3206 
  3207 TInt CTestZlib::TestGztell1()
  3208 	{ 
  3209 	TInt res = KErrNone ;
  3210 	int err;
  3211 	gzFile file;
  3212 	file = gzopen(TESTFILE, "wb");             
  3213 	if (file == NULL) 
  3214 		{
  3215 		res = KErrGeneral; 
  3216 		return res;        
  3217 		}           
  3218 	err=gztell(file) ;
  3219 	if(err<0)
  3220 		{
  3221 		res = KErrGeneral;
  3222 		return res;	
  3223 		}
  3224 	err=  gzclose(file);
  3225 	if(err != Z_OK)  
  3226 		{
  3227 		res = KErrGeneral; 
  3228 		}
  3229 	return res;
  3230 	}
  3231 
  3232 TInt CTestZlib::TestGztellfail1()
  3233 	{ 
  3234 	TInt res = KErrNone ;
  3235 	int err;
  3236 	gzFile file;
  3237 	file = gzopen(NOFILE, "wb");             
  3238 	if (file == NULL) 
  3239 		{
  3240 		res = KErrNone; 
  3241 		return res;        
  3242 		}          
  3243 	err=gztell(file) ;
  3244 	if(err>0)
  3245 		{
  3246 		res= KErrGeneral;	
  3247 		}
  3248 	return res;
  3249 	}
  3250 
  3251 int  test_deflatecopy (Bytef *dest,  uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
  3252 	{
  3253 	TInt res = KErrNone ;
  3254 	z_stream stream;
  3255 	z_stream stream1;
  3256 	int err;
  3257 
  3258 	stream.zalloc = (alloc_func)0;
  3259 	stream.zfree = (free_func)0;
  3260 	stream.opaque = (voidpf)0;
  3261 
  3262 	stream.next_in = (Bytef*)source;
  3263 	stream.avail_in = (uInt)sourceLen;
  3264 
  3265 	stream.next_out = dest;
  3266 	stream.avail_out = (uInt)*destLen;
  3267 	if ((uLong)stream.avail_out != *destLen)  
  3268 		{
  3269 		res = KErrGeneral; 
  3270 		} 
  3271 
  3272 	err = deflateInit(&stream, level);
  3273 	if (err != Z_OK)  
  3274 		{
  3275 		res = KErrGeneral; 
  3276 		return res;
  3277 		} 
  3278 	err=deflateCopy(&stream1 , &stream); 
  3279 	if (err != Z_OK)  
  3280 		{
  3281 		res = KErrGeneral; 
  3282 		} 
  3283 	err=deflateEnd(&stream);
  3284 	if (err != Z_OK)  
  3285 		{
  3286 		res = KErrGeneral; 
  3287 		} 
  3288 	err=deflateEnd(&stream1);
  3289 	if (err != Z_OK)  
  3290 		{
  3291 		res = KErrGeneral; 
  3292 		}
  3293 	return res;
  3294 	}
  3295 
  3296 TInt CTestZlib::TestDeflatecopy()
  3297 	{
  3298 	TInt res;
  3299 	uLong len = (uLong)strlen(hello)+1;
  3300 
  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)
  3306 		{
  3307 		return KErrNoMemory;
  3308 		}
  3309 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  3310 	if (uncompr == Z_NULL) 
  3311 		{
  3312 		free(compr);
  3313 		return KErrNoMemory;
  3314 		}
  3315 	res= test_deflatecopy(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);
  3316 	free(compr);
  3317 	free(uncompr);
  3318 	return res;
  3319 	}
  3320 
  3321 
  3322 TInt CTestZlib::TestDeflatecopyfail()
  3323 	{
  3324 	TInt res = KErrNone ;int err;
  3325 	z_stream stream1;
  3326 	uLong len = (uLong)strlen(hello)+1;
  3327 
  3328 	Byte *compr;
  3329 	uLong comprLen = 20*sizeof(int); 
  3330 	compr    = (Byte*)calloc((uInt)comprLen, 1);
  3331 
  3332 	if (compr == Z_NULL)
  3333 		{
  3334 		return KErrNoMemory;
  3335 		}
  3336 	err=deflateCopy(&stream1 , NULL); 
  3337 	if (err == Z_OK)  
  3338 		{
  3339 		res = KErrNone;     	    	
  3340 		} 
  3341 
  3342 	free(compr);
  3343 	return res;
  3344 	}
  3345 
  3346 
  3347 TInt CTestZlib::TestGzclose()
  3348 	{     
  3349 	TInt res = KErrNone ;
  3350 	int err;
  3351 	int len = (int)strlen(hello)+1;
  3352 	gzFile file;
  3353 
  3354 	const char * fname = TESTFILE;
  3355 	file = gzopen(fname, "wb");
  3356 	gzputc(file, 'h');
  3357 
  3358 	err= gzclose(file);
  3359 
  3360 	if(err != 0)
  3361 		{    	
  3362 		res =  	 KErrGeneral;
  3363 		}
  3364 	return res;   
  3365 	}
  3366 
  3367 
  3368 TInt CTestZlib::TestGzclose_fail()
  3369 	{
  3370 	TInt res = KErrNone ;
  3371 	int err;
  3372 	int len = (int)strlen(hello)+1;
  3373 	gzFile file;
  3374 	const char * fname = NOFILE;
  3375 
  3376 	file = gzopen(fname, "wb");
  3377 
  3378 	err=gzclose(file);
  3379 	if(err == 0)
  3380 		{    	
  3381 		res =  	 KErrGeneral;
  3382 		}
  3383 	return res;   
  3384 	}
  3385 
  3386 TInt CTestZlib::TestGzeof()
  3387 	{
  3388 	TInt res = KErrNone ;
  3389 	gzFile file;
  3390 	const char * fname = TESTFILE ;
  3391 	file = gzopen(fname, "wb");
  3392 	if (file == NULL) 
  3393 		{
  3394 		res = KErrGeneral;
  3395 		return res;
  3396 		}   
  3397 
  3398 	if (gzputs(file, "ello") != 4) 
  3399 		{
  3400 		ERR_PRINTF1(_L("gzputs err"));
  3401 		return KErrNone;
  3402 		}
  3403 	int x=gzeof(file);
  3404 	if(x!=0)
  3405 		{
  3406 		res= KErrGeneral;	
  3407 		}
  3408 
  3409 	int err=  gzclose(file);
  3410 	if (err != Z_OK)  
  3411 		{
  3412 		res = KErrGeneral; 
  3413 		} 
  3414 	return res;
  3415 	}
  3416 
  3417 TInt CTestZlib::TestGzeoffail1()
  3418 	{
  3419 	TInt res = KErrNone ;
  3420 	gzFile file;
  3421 	const char * fname = TESTFILE ;
  3422 	file = gzopen(fname, "rb");
  3423 	if (file == NULL) 
  3424 		{
  3425 		res = KErrGeneral;
  3426 		return res;
  3427 		}   
  3428 	int x=gzeof(file);
  3429 	if(x!=Z_STREAM_END)
  3430 		{
  3431 		res= KErrNone;	
  3432 		}
  3433 
  3434 	int err=  gzclose(file);
  3435 	if (err != Z_OK)  
  3436 		{
  3437 		res = KErrGeneral; 
  3438 		} 
  3439 	return res;
  3440 	}	
  3441 
  3442 TInt CTestZlib::TestGzeoffail2()
  3443 	{
  3444 	TInt res = KErrNone ;
  3445 	gzFile file;
  3446 	const char * fname = NOFILE ;
  3447 	file = gzopen(fname, "wb");   
  3448 	int x=gzeof(file);
  3449 	if(x!=0)
  3450 		{
  3451 		res= KErrNone;	
  3452 		}    
  3453 	int err=  gzclose(file);
  3454 	if (err == Z_OK)  
  3455 		{
  3456 		res = KErrGeneral;     	    	
  3457 		}       
  3458 	return res;
  3459 	}
  3460 
  3461 TInt CTestZlib::TestGzgetc()
  3462 	{
  3463 	TInt res = KErrNone ;
  3464 	gzFile file;
  3465 	const char * fname = TESTFILE ;
  3466 	file = gzopen(fname, "rb");
  3467 	if (file == Z_NULL)  
  3468 		{
  3469 		res = KErrNoMemory; 
  3470 		return res;
  3471 		} 
  3472 	int l=  gzgetc(file);
  3473 	int err=  gzclose(file);
  3474 	if (err != Z_OK)  
  3475 		{
  3476 		res = KErrGeneral; 
  3477 		}     
  3478 	return res;
  3479 	}
  3480 
  3481 
  3482 TInt CTestZlib::TestGzflush()
  3483 	{
  3484 	TInt res = KErrNone ;
  3485 	gzFile file;
  3486 	const char * fname = TESTFILE ;
  3487 	file = gzopen(fname, "wb");
  3488 	if (file == Z_NULL)  
  3489 		{
  3490 		res = KErrNoMemory; 
  3491 		return res;
  3492 		}     
  3493 	int l= gzflush(file,Z_FULL_FLUSH);
  3494 	if(l != Z_OK)  
  3495 		{
  3496 		res = KErrGeneral;  
  3497 		} 
  3498 
  3499 	int err=gzclose(file);
  3500 	if (err != Z_OK)  
  3501 		{
  3502 		res = KErrGeneral;     	    	
  3503 		}     
  3504 	return res;
  3505 	}
  3506 
  3507 
  3508 TInt CTestZlib::TestGzflushsync()
  3509 	{
  3510 	TInt res = KErrNone ;
  3511 	gzFile file;
  3512 	const char * fname = TESTFILE ;
  3513 	file = gzopen(fname, "wb");
  3514 	if (file == Z_NULL)  
  3515 		{
  3516 		res = KErrNoMemory; 
  3517 		return res;
  3518 		}     
  3519 	int l= gzflush(file,Z_SYNC_FLUSH);
  3520 	if (l != Z_OK)  
  3521 		{
  3522 		res = KErrGeneral;  
  3523 		} 
  3524 	int err=  gzclose(file);
  3525 	if(err != Z_OK)  
  3526 		{
  3527 		res = KErrGeneral;     	    	
  3528 		}     
  3529 	return res;
  3530 	}
  3531 
  3532 TInt CTestZlib::TestGzflushfail()
  3533 	{
  3534 	TInt res = KErrNone ;
  3535 	gzFile file;   
  3536 	const char * fname = TESTFILE ;
  3537 	file = gzopen(fname, "rb");
  3538 	if (file == Z_NULL)  
  3539 		{
  3540 		res = KErrGeneral; 
  3541 		return res;
  3542 		}     
  3543 	int l= gzflush(file,Z_FULL_FLUSH);
  3544 	if (l == Z_OK)  
  3545 		{
  3546 		res = KErrGeneral;  
  3547 		} 
  3548 	int err=  gzclose(file);
  3549 	if (err != Z_OK) 
  3550 		{
  3551 		res = KErrGeneral;     	    	
  3552 		} 
  3553 	return res;
  3554 	}
  3555 
  3556 TInt CTestZlib::TestGzerror()
  3557 	{
  3558 	TInt res = KErrNone ;
  3559 	int err;
  3560 	int len = (int)strlen(hello)+1;
  3561 	gzFile file;
  3562 	const char * fname = TESTFILE ;
  3563 	file = gzopen(fname, "wb");
  3564 	if (file == NULL) 
  3565 		{
  3566 		res=KErrGeneral;
  3567 		}
  3568 	gzputc(file, 'h');
  3569 	if (gzputs(file, "ello") != 5) 
  3570 		{
  3571 		gzprintf(file, "gzputs err: %s\n", gzerror(file, &err));
  3572 		res=KErrGeneral;
  3573 		}
  3574 	err=  gzclose(file);
  3575 	if (err != Z_OK)  
  3576 		{
  3577 		res = KErrGeneral;     	    	
  3578 		}
  3579 	else
  3580 		{
  3581 		res = KErrNone;     	    	
  3582 		} 
  3583 	return res;
  3584 	}
  3585 
  3586 
  3587 TInt CTestZlib::TestGzerrorfail1()
  3588 	{
  3589 	TInt res = KErrNone ;
  3590 	int err;
  3591 	int len = (int)strlen(hello)+1;
  3592 	gzFile file;
  3593 	const char * fname = NOFILE ;
  3594 	file = gzopen(fname, "wb");
  3595 	if (file != NULL) 
  3596 		{
  3597 		res=KErrGeneral;
  3598 		return res;
  3599 		}
  3600 	gzputc(file, 'h');
  3601 	if (gzputs(file, "ello") != 5) 
  3602 		{
  3603 		gzprintf(file, "gzputs err: %s\n", gzerror(file, &err));
  3604 		res=KErrNone;
  3605 		}
  3606 	err=  gzclose(file);
  3607 	if (err == Z_OK)  
  3608 		{
  3609 		res = KErrGeneral; 
  3610 		}       
  3611 	return res;
  3612 	}
  3613 
  3614 
  3615 TInt CTestZlib::TestGzgetcfail()
  3616 	{
  3617 	TInt res = KErrNone ;
  3618 	gzFile file;   
  3619 	const char * fname = TESTFILE ;
  3620 	file = gzopen(fname, "wb");
  3621 	if (file == Z_NULL)  
  3622 		{
  3623 		res = KErrNoMemory; 
  3624 		return res;
  3625 		}     
  3626 	int l=  gzgetc(file);
  3627 	int err=  gzclose(file);
  3628 	if (err != Z_OK)  
  3629 		{
  3630 		res = KErrGeneral;     	    	
  3631 		} 
  3632 	return res;
  3633 	}
  3634 
  3635 
  3636 TInt CTestZlib::TestDeflateSetDictionary()
  3637 	{
  3638 	TInt res = KErrNone ;
  3639 	Byte *compr, *uncompr;
  3640 	uLong comprLen = 20*sizeof(int); 
  3641 	uLong uncomprLen = comprLen;
  3642 
  3643 	compr    = (Byte*)calloc((uInt)comprLen, 1);
  3644 	if (compr == Z_NULL)
  3645 		{
  3646 		return KErrNoMemory;
  3647 		}
  3648 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  3649 	if (uncompr == Z_NULL) 
  3650 		{
  3651 		free(compr);
  3652 		return KErrNoMemory;
  3653 		}
  3654 
  3655 	res = test_compress(compr, comprLen, uncompr, uncomprLen);
  3656 	if(res < 0)
  3657 		{
  3658 		free(compr);
  3659 		free(uncompr);
  3660 		return KErrNoMemory;
  3661 		}
  3662 	res=Test_dict_deflate(compr, comprLen);
  3663 	free(compr);
  3664 	free(uncompr);
  3665 	return res;
  3666 	}
  3667 
  3668 
  3669 
  3670 TInt CTestZlib::TestDeflateSetDictionary_nodict()
  3671 	{
  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 */
  3677 	int err;
  3678 
  3679 	c_stream.zalloc = (alloc_func)0;
  3680 	c_stream.zfree = (free_func)0;
  3681 	c_stream.opaque = (voidpf)0;
  3682 
  3683 	err = deflateInit(&c_stream, Z_BEST_COMPRESSION);                    
  3684 	if(err < 0)                 
  3685 		{
  3686 		return Z_MEM_ERROR;
  3687 		}
  3688 	compr    = (Byte*)calloc((uInt)comprLen, 1);
  3689 	if (compr == Z_NULL)
  3690 		{
  3691 		return KErrNoMemory;
  3692 		}
  3693 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  3694 	if (uncompr == Z_NULL) 
  3695 		{
  3696 		free(compr);
  3697 		return KErrNoMemory;
  3698 		}
  3699 	err = deflateSetDictionary(&c_stream,NULL, sizeof(dictionary));
  3700 	if(err != 0)
  3701 		{    	
  3702 		res = KErrNone ;    	
  3703 		}
  3704 	else
  3705 		{    	
  3706 		res = KErrGeneral;
  3707 		}
  3708 	err = deflateEnd(&c_stream);
  3709 	if (err)
  3710 		{
  3711 		res =	 KErrGeneral;
  3712 		}
  3713 	free(compr);
  3714 	free(uncompr);
  3715 
  3716 	return res;
  3717 	}
  3718 
  3719 TInt CTestZlib::TestDeflateSetDictionary_fail()
  3720 	{
  3721 	TInt res = KErrNone ;
  3722 	Byte *compr, *uncompr;
  3723 	uLong comprLen = 20*sizeof(int); 
  3724 	uLong uncomprLen = comprLen;
  3725 
  3726 	compr    = (Byte*)calloc((uInt)comprLen, 1);
  3727 	if (compr == Z_NULL)
  3728 		{
  3729 		return KErrNoMemory;
  3730 		}	
  3731 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  3732 	if (uncompr == Z_NULL) 
  3733 		{
  3734 		free(compr);
  3735 		return KErrNoMemory;
  3736 		}
  3737 
  3738 	res=test_compress(compr, comprLen, uncompr, uncomprLen);
  3739 
  3740 	if(res < 0)
  3741 		{
  3742 		free(compr);
  3743 		free(uncompr);
  3744 		return KErrNoMemory;
  3745 		}
  3746 	res = Test_dict_deflate(compr, comprLen);
  3747 	if(res < 0)
  3748 		{
  3749 		free(compr);
  3750 		free(uncompr);
  3751 		return KErrNoMemory;
  3752 		}
  3753 	int  err = deflateSetDictionary(NULL,(const Bytef*)dictionary, sizeof(dictionary));
  3754 	if(err != 0)
  3755 		{    	
  3756 		res = KErrNone ;    	
  3757 		}
  3758 	else
  3759 		{    	
  3760 		res = KErrGeneral;
  3761 		}
  3762 	free(compr);
  3763 	free(uncompr);
  3764 	return res;
  3765 	}
  3766 
  3767 
  3768 TInt CTestZlib::TestDeflateend()
  3769 	{    
  3770 	TInt res = KErrNone ;
  3771 	z_stream c_stream; /* compression stream */
  3772 	int err;
  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)
  3779 		{
  3780 		return KErrNoMemory;
  3781 		}
  3782 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  3783 	if (uncompr == Z_NULL) 
  3784 		{
  3785 		free(compr);
  3786 		return KErrNoMemory;
  3787 		}
  3788 
  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);
  3793 	if(err <0)
  3794 		{
  3795 		free(compr);
  3796 		free(uncompr);
  3797 		return err;	
  3798 		}
  3799 	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  3800 	if(err <0)
  3801 		{
  3802 		free(compr);
  3803 		free(uncompr);
  3804 		return err;	
  3805 		}
  3806 
  3807 	c_stream.next_in  = (Bytef*)hello;
  3808 	c_stream.next_out = compr;
  3809 
  3810 	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  3811 		{
  3812 		c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
  3813 		err = deflate(&c_stream, Z_NO_FLUSH);
  3814 		}
  3815 	/* Finish the stream, still forcing small buffers: */
  3816 	for (;;) 
  3817 		{
  3818 		c_stream.avail_out = 1;
  3819 		err = deflate(&c_stream, Z_FINISH);
  3820 		if (err == Z_STREAM_END) break;
  3821 		}
  3822 	err = deflateEnd(&c_stream);
  3823 	if (err)
  3824 		{
  3825 		res =	 KErrGeneral;
  3826 		}
  3827 	free(compr);
  3828 	free(uncompr);
  3829 	return res;
  3830 	}
  3831 
  3832 
  3833 TInt CTestZlib::TestDeflateendfail1()
  3834 	{    
  3835 	TInt res = KErrNone ;
  3836 	z_stream c_stream; /* compression stream */
  3837 	int err;
  3838 	Byte * compr;
  3839 	uLong comprLen = 20*sizeof(int); 
  3840 	compr = (Byte*)calloc((uInt)comprLen, 1);
  3841 	if (compr == Z_NULL)
  3842 		{
  3843 		return KErrNoMemory;
  3844 		}
  3845 
  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;
  3850 
  3851 	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  3852 	if(err<0)
  3853 		{
  3854 		free(compr);
  3855 		return KErrNoMemory;
  3856 		}
  3857 	c_stream.next_in  = (Bytef*)hello;
  3858 	c_stream.next_out = compr;
  3859 
  3860 	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  3861 		{
  3862 		c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
  3863 		err = deflate(&c_stream, Z_NO_FLUSH);
  3864 		}
  3865 
  3866 	err = deflateEnd(&c_stream);
  3867 	if (!err)
  3868 		{
  3869 		res =	 KErrGeneral;
  3870 		}
  3871 	free(compr);
  3872 	return res;
  3873 	}
  3874 
  3875 
  3876 TInt CTestZlib::TestDeflate()
  3877 	{    
  3878 	TInt res = KErrNone ;
  3879 	z_stream c_stream; /* compression stream */
  3880 	int err;
  3881 	Byte * compr;
  3882 	uLong comprLen = 20*sizeof(int); 
  3883 	compr    = (Byte*)calloc((uInt)comprLen, 1);   
  3884 	if (compr == Z_NULL)
  3885 		{
  3886 		return KErrNoMemory;
  3887 		}
  3888 	uLong len = (uLong)strlen(hello)+1;
  3889 
  3890 	c_stream.zalloc = (alloc_func)0;
  3891 	c_stream.zfree = (free_func)0;
  3892 	c_stream.opaque = (voidpf)0;
  3893 
  3894 	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  3895 	if(err <0)
  3896 		{
  3897 		free(compr);
  3898 		return err;	
  3899 		}
  3900 
  3901 	c_stream.next_in  = (Bytef*)hello;
  3902 	c_stream.next_out = compr;
  3903 
  3904 	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  3905 		{
  3906 		c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
  3907 		err = deflate(&c_stream, Z_NO_FLUSH);
  3908 		if(err != 0)
  3909 			{    	
  3910 			res = KErrGeneral;
  3911 			}
  3912 		}
  3913 
  3914 	err = deflateEnd(&c_stream);
  3915 	free(compr);
  3916 
  3917 	return res;
  3918 	}
  3919 
  3920 
  3921 TInt CTestZlib::TestGzseek()
  3922 	{    
  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)
  3929 		{
  3930 		return KErrNoMemory;
  3931 		}
  3932 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  3933 	if (uncompr == Z_NULL) 
  3934 		{
  3935 		free(compr);
  3936 		return KErrNoMemory;
  3937 		}
  3938 	int err;
  3939 	err = test_compress(compr, comprLen, uncompr, uncomprLen);
  3940 	if (err < 0)
  3941 		{
  3942 		free(compr);
  3943 		free(uncompr);
  3944 		return KErrNoMemory;
  3945 		}   
  3946 	int len = (int)strlen(hello)+1;
  3947 	gzFile file;
  3948 	file = gzopen(TESTFILE, "wb");
  3949 	if (file == NULL) 
  3950 		{
  3951 		free(compr);
  3952 		free(uncompr);
  3953 		res = KErrNoMemory; 
  3954 		return res;        
  3955 		}
  3956 	gzputc(file, 'h');
  3957 	if (gzputs(file, "ello") != 4)
  3958 		{
  3959 		res = KErrGeneral; 
  3960 		return res;
  3961 		}
  3962 	if (gzprintf(file, ", %s!", "hello") != 8) 
  3963 		{
  3964 		res = KErrGeneral; 
  3965 		return res;
  3966 		}
  3967 	err= gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
  3968 	if(err<0)
  3969 		{
  3970 		res	= KErrGeneral;	
  3971 		}
  3972 	err=  gzclose(file);
  3973 	if (err != Z_OK)  
  3974 		{
  3975 		res = KErrGeneral; 
  3976 		} 
  3977 
  3978 	free(compr);
  3979 	free(uncompr);
  3980 	return res;
  3981 	}
  3982 
  3983 
  3984 TInt CTestZlib::TestGzseekfail1()
  3985 	{    
  3986 	TInt res = KErrNone ; 
  3987 	Byte *compr, *uncompr;
  3988 	uLong comprLen = 20*sizeof(int); 
  3989 	uLong uncomprLen = comprLen;
  3990 
  3991 	compr    = (Byte*)calloc((uInt)comprLen, 1);
  3992 	if (compr == Z_NULL)
  3993 		{
  3994 		return KErrNoMemory;
  3995 		}
  3996 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  3997 	if (uncompr == Z_NULL) 
  3998 		{
  3999 		free(compr);
  4000 		return KErrNoMemory;
  4001 		}
  4002 	int err;
  4003 	err = test_compress(compr, comprLen, uncompr, uncomprLen);
  4004 	if (err < 0)
  4005 		{
  4006 		free(compr);
  4007 		free(uncompr);
  4008 		return KErrNoMemory;
  4009 		}   
  4010 
  4011 	int len = (int)strlen(hello)+1;
  4012 	gzFile file;
  4013 	file = gzopen(NOFILE, "wb");
  4014 
  4015 	err = gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
  4016 	if(err>=0)
  4017 		{
  4018 		res= KErrGeneral;	
  4019 		}
  4020 	err=  gzclose(file);
  4021 	if (err == Z_OK)  
  4022 		{
  4023 		res = KErrGeneral; 
  4024 		} 
  4025 
  4026 	free(compr);
  4027 	free(uncompr);
  4028 	return res;
  4029 	}
  4030 
  4031 TInt CTestZlib::TestGzseekfail2()
  4032 	{    
  4033 	TInt res = KErrNone ; 
  4034 	Byte *compr, *uncompr;
  4035 	uLong comprLen = 20*sizeof(int); 
  4036 	uLong uncomprLen = comprLen;
  4037 
  4038 	compr    = (Byte*)calloc((uInt)comprLen, 1);
  4039 	if (compr == Z_NULL)
  4040 		{
  4041 		return KErrNoMemory;
  4042 		}
  4043 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  4044 	if(uncompr == Z_NULL) 
  4045 		{
  4046 		free(compr);
  4047 		return KErrNoMemory;
  4048 		}
  4049 
  4050 	int err;
  4051 	err = test_compress(compr, comprLen, uncompr, uncomprLen);
  4052 	if (err < 0)
  4053 		{
  4054 		free(compr);
  4055 		free(uncompr);
  4056 		return KErrNoMemory;
  4057 		}   
  4058 	int len = (int)strlen(hello)+1;
  4059 	gzFile file;
  4060 	file = gzopen(TESTFILE, "wb");
  4061 
  4062 	err = gzseek(file, -1L, SEEK_CUR); /* add one zero byte */
  4063 	if(err>=0)
  4064 		{
  4065 		res= KErrGeneral;	
  4066 		}
  4067 	err=  gzclose(file);
  4068 	if (err != Z_OK)  
  4069 		{
  4070 		res = KErrGeneral; 
  4071 		} 
  4072 
  4073 	free(compr);
  4074 	free(uncompr);
  4075 	return res;
  4076 	}
  4077 
  4078 TInt CTestZlib::TestGzsetparams()
  4079 	{    
  4080 	TInt res = KErrNone ;
  4081 	int len = (int)strlen(hello)+1;
  4082 	gzFile file;
  4083 	const char * fname = TESTFILE;
  4084 
  4085 	file = gzopen(fname, "wb");
  4086 	gzputc(file, 'h');
  4087 
  4088 	int u = gzsetparams(file, Z_BEST_SPEED, Z_DEFAULT_STRATEGY);
  4089 	if(u!=0)
  4090 		{
  4091 		res= KErrGeneral;	
  4092 		}
  4093 	int err=  gzclose(file);
  4094 	if (err != Z_OK)  
  4095 		{
  4096 		res = KErrGeneral; 
  4097 		} 
  4098 
  4099 	return res;
  4100 	}
  4101 
  4102 
  4103 TInt CTestZlib::TestGzsetparams_fail1()
  4104 	{   
  4105 	TInt res = KErrNone ; 
  4106 	int len = (int)strlen(hello)+1;
  4107 	gzFile file;
  4108 	const char * fname = TESTFILE;
  4109 	file = gzopen(fname, "wb");
  4110 	gzputc(file, 'h');
  4111 
  4112 	int u = gzsetparams(file, Z_BEST_SPEED, -2);
  4113 	if(u==0)
  4114 		{
  4115 		res= KErrGeneral;	
  4116 		}
  4117 
  4118 	int err=  gzclose(file);
  4119 	if (err != Z_OK)  
  4120 		{
  4121 		res = KErrGeneral; 
  4122 		} 
  4123 
  4124 	return res;
  4125 	}
  4126 
  4127 
  4128 TInt CTestZlib::TestGzsetparams_fail2()
  4129 	{    
  4130 	TInt res = KErrNone ;
  4131 
  4132 	int len = (int)strlen(hello)+1;
  4133 	gzFile file;
  4134 
  4135 	const char * fname = TESTFILE;
  4136 	file = gzopen(fname, "wb");
  4137 	gzputc(file, 'h');
  4138 
  4139 	int u = gzsetparams(file, -2, Z_DEFAULT_STRATEGY);
  4140 	if(u==0)
  4141 		{
  4142 		res= KErrGeneral;	
  4143 		}
  4144 	int err=  gzclose(file);
  4145 	if (err != Z_OK)  
  4146 		{
  4147 		res = KErrGeneral; 
  4148 		} 
  4149 
  4150 	return res;
  4151 	}
  4152 
  4153 TInt CTestZlib::TestGzsetparams_fail3()
  4154 	{   
  4155 	TInt res = KErrNone ; 
  4156 	int len = (int)strlen(hello)+1;
  4157 	gzFile file;
  4158 	const char * fname = TESTFILE;
  4159 
  4160 	file = gzopen(fname, "rb");
  4161 	if (file == NULL) 
  4162 		{
  4163 		res = KErrGeneral; 
  4164 		return res;        
  4165 		}
  4166 	gzputc(file, 'h');
  4167 
  4168 	int u = gzsetparams(file, Z_BEST_SPEED, Z_DEFAULT_STRATEGY);
  4169 	if(u==0)
  4170 		{
  4171 		res	= KErrGeneral;	
  4172 		}
  4173 
  4174 	int err=  gzclose(file);
  4175 	if (err != Z_OK)  
  4176 		{
  4177 		res = KErrGeneral; 
  4178 		} 
  4179 	return res;
  4180 	}
  4181 
  4182 
  4183 TInt CTestZlib::TestGzrewind()
  4184 	{ 
  4185 	TInt res = KErrNone ;
  4186 	int err;
  4187 	int len = (int)strlen(hello)+1;
  4188 	gzFile file;
  4189 
  4190 	const char * fname = TESTFILE;
  4191 	file = gzopen(fname, "rb");
  4192 	if (file == NULL) 
  4193 		{
  4194 		res = KErrGeneral;
  4195 		}
  4196 	gzputc(file, 'h');
  4197 	err = gzrewind(file);
  4198 	if(err == 0)
  4199 		{    	
  4200 		res = KErrNone ;    	
  4201 		}
  4202 	else
  4203 		{    	
  4204 		res = KErrGeneral;
  4205 		}
  4206 	err = gzclose(file);
  4207 	if (err != Z_OK)  
  4208 		{
  4209 		res = KErrGeneral; 
  4210 		} 
  4211 	return res;
  4212 	}
  4213 
  4214 
  4215 
  4216 TInt CTestZlib::TestGzrewindfail()
  4217 	{    
  4218 	TInt res = KErrNone ;
  4219 	int err;
  4220 	int len = (int)strlen(hello)+1;
  4221 	gzFile file;
  4222 
  4223 	const char * fname = TESTFILE;
  4224 	file = gzopen(fname, "wb");
  4225 	if (file == NULL) 
  4226 		{
  4227 		res = KErrGeneral; 
  4228 		}
  4229 	gzputc(file, 'h');
  4230 	err = gzrewind(file);
  4231 	if(err == 0)
  4232 		{    	
  4233 		res =  	 KErrGeneral;
  4234 		}
  4235 	else
  4236 		{    	
  4237 		res = KErrNone ;  
  4238 		}
  4239 	err=  gzclose(file);
  4240 	if (err != Z_OK)  
  4241 		{
  4242 		res = KErrGeneral; 
  4243 		} 
  4244 
  4245 	return res;
  4246 	}
  4247 
  4248 TInt CTestZlib::TestGzdopen()
  4249 	{
  4250 	TInt res = KErrNone ;
  4251 	int len = (int)strlen(hello)+1;
  4252 	gzFile file;
  4253 	const char * fname = TESTFILE ;
  4254 	FILE*  fp = fopen(fname, "rb");
  4255 	file = gzdopen(fileno(fp), "rb");
  4256 	if (file == NULL)
  4257 		{
  4258 		res = Z_MEM_ERROR;
  4259 		fclose(fp);
  4260 		return res;
  4261 		}
  4262 	int err=  gzclose(file);
  4263 	if (err != Z_OK)  
  4264 		{
  4265 		res = KErrGeneral; 
  4266 		}
  4267 	fclose(fp);
  4268 	return res;
  4269 	}
  4270 
  4271 
  4272 TInt CTestZlib::TestGzdopen_fail()
  4273 	{
  4274 	TInt res = KErrNone ;
  4275 	int len = (int)strlen(hello)+1;
  4276 	gzFile file;
  4277 	const char * fname = TESTFILE ;
  4278 	FILE*  fp = fopen(fname, "rb");
  4279 	file = gzdopen(fileno(fp), "xyz");
  4280 	if (file == NULL) 
  4281 		{
  4282 		res=KErrNone; 
  4283 		fclose(fp);
  4284 		return res;
  4285 		}
  4286 	int err=  gzclose(file);
  4287 	if (err == Z_OK)  
  4288 		{
  4289 		res = KErrGeneral; 
  4290 		}  
  4291 	fclose(fp);
  4292 	return res;
  4293 	}
  4294 
  4295 
  4296 TInt CTestZlib::TestGzdopen_fail2()
  4297 	{
  4298 	TInt res = KErrNone ;
  4299 	int len = (int)strlen(hello)+1;
  4300 	gzFile file;
  4301 	const char * fname = TESTFILE ;
  4302 	FILE*  fp = fopen(fname, "rb");
  4303 	file = gzdopen(-1, "xyz");
  4304 	if (file == NULL) 
  4305 		{ 
  4306 		fclose(fp);
  4307 		res=KErrNone;
  4308 		return res;
  4309 		}
  4310 	int err=  gzclose(file);
  4311 	if (err == Z_OK)  
  4312 		{
  4313 		res = KErrGeneral; 
  4314 		}
  4315 	fclose(fp);
  4316 	return res;
  4317 	}
  4318 
  4319 /* ===========================================================================
  4320  * Test deflate() with full flush
  4321  */
  4322 TInt CTestZlib::Test_flush(   Byte * compr,uLong * comprLen)
  4323 	{
  4324 	TInt res = KErrNone ;
  4325 	z_stream c_stream; /* compression stream */
  4326 	int err;
  4327 	uInt len = (uInt)strlen(hello)+1;
  4328 
  4329 	c_stream.zalloc = (alloc_func)0;
  4330 	c_stream.zfree = (free_func)0;
  4331 	c_stream.opaque = (voidpf)0;
  4332 
  4333 	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  4334 	if(err<0)
  4335 		{
  4336 		return Z_MEM_ERROR;    	
  4337 		}
  4338 
  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);
  4344 
  4345 	int h=inflateSyncPoint(&c_stream);
  4346 	compr[3]++; /* force an error in first compressed block */
  4347 	c_stream.avail_in = len - 3;
  4348 
  4349 	err = deflate(&c_stream, Z_FINISH);
  4350 	if (err != Z_STREAM_END)
  4351 		{
  4352 		res = KErrGeneral;
  4353 		}
  4354 	err = deflateEnd(&c_stream);  
  4355 	if (err != 0) 
  4356 		{
  4357 		res = KErrGeneral;
  4358 		}
  4359 	*comprLen = c_stream.total_out;
  4360 	return res;
  4361 	}
  4362 
  4363 
  4364 TInt test_sync(Byte * compr,uLong comprLen, Byte * uncompr,uLong uncomprLen)
  4365 	{
  4366 	TInt res = KErrNone ;
  4367 	int err;
  4368 	z_stream d_stream; /* decompression stream */
  4369 
  4370 	strcpy((char*)uncompr, "garbage");
  4371 
  4372 	d_stream.zalloc = (alloc_func)0;
  4373 	d_stream.zfree = (free_func)0;
  4374 	d_stream.opaque = (voidpf)0;
  4375 
  4376 	d_stream.next_in  = compr;
  4377 	d_stream.avail_in = 2; /* just read the zlib header */
  4378 
  4379 	err = inflateInit(&d_stream);
  4380 	if(err!=0)
  4381 		{
  4382 		res=KErrGeneral;
  4383 		}
  4384 	d_stream.next_out = uncompr;
  4385 	d_stream.avail_out = (uInt)uncomprLen;
  4386 
  4387 	err=  inflate(&d_stream, Z_NO_FLUSH);
  4388 	if(err!=0)
  4389 		{
  4390 		res=KErrGeneral;
  4391 		}
  4392 	d_stream.avail_in = (uInt)comprLen-2;   /* read all compressed data */
  4393 	err = inflateSync(&d_stream);           /* but skip the damaged part */
  4394 	if(err!=0)
  4395 		{
  4396 		res=KErrGeneral;
  4397 		}
  4398 	err = inflate(&d_stream, Z_FINISH);
  4399 	if(err==0)
  4400 		{
  4401 		res=KErrGeneral;
  4402 		}
  4403 	err = inflateEnd(&d_stream);
  4404 	if(err!=0)
  4405 		{
  4406 		res=KErrGeneral;
  4407 		}
  4408 	return res;
  4409 	}
  4410 
  4411 
  4412 TInt CTestZlib::TestInflateSync()
  4413 	{   
  4414 	TInt res = KErrNone ;
  4415 	uLong len = (uLong)strlen(hello)+1;
  4416 
  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)
  4422 		{
  4423 		return KErrNoMemory;
  4424 		}
  4425 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  4426 	if(uncompr == Z_NULL) 
  4427 		{
  4428 		free(compr);
  4429 		return KErrNoMemory;
  4430 		}
  4431 	res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  4432 	if(res<0)
  4433 		{
  4434 		free(compr);
  4435 		free(uncompr);
  4436 		return KErrNoMemory;	
  4437 		}
  4438 	Test_flush(compr, &comprLen);
  4439 	res = test_sync(compr, comprLen, uncompr, uncomprLen);
  4440 	free(compr);
  4441 	free(uncompr);
  4442 	return res;
  4443 	}
  4444 
  4445 
  4446 TInt CTestZlib::TestinflateSyncfail()
  4447 	{   
  4448 	TInt res = KErrNone ;
  4449 	uLong len = (uLong)strlen(hello)+1;
  4450 
  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)
  4456 		{
  4457 		return KErrNoMemory;
  4458 		}
  4459 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  4460 	if (uncompr == Z_NULL) 
  4461 		{
  4462 		free(compr);
  4463 		return KErrNoMemory;
  4464 		}
  4465 
  4466 	res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  4467 	if(res<0)
  4468 		{
  4469 		free(compr);
  4470 		free(uncompr);
  4471 		return KErrNoMemory;	
  4472 		}
  4473 	int err = test_sync(compr, comprLen, uncompr, uncomprLen);
  4474 	if(err!=0)
  4475 		{
  4476 		res = KErrNone ;
  4477 		}    
  4478 	else
  4479 		{
  4480 		res = KErrGeneral;
  4481 		}    
  4482 	free(compr);
  4483 	free(uncompr);
  4484 	return res;
  4485 	}
  4486 
  4487 
  4488 int  test_syncpoint (Bytef *dest,  uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
  4489 	{
  4490 	TInt res = KErrNone ;
  4491 	z_stream stream;
  4492 	int err;
  4493 
  4494 	stream.next_in = (Bytef*)source;
  4495 	stream.avail_in = (uInt)sourceLen;
  4496 	stream.next_out = dest;
  4497 	stream.avail_out = (uInt)*destLen;
  4498 
  4499 	stream.zalloc = (alloc_func)0;
  4500 	stream.zfree = (free_func)0;
  4501 	stream.opaque = (voidpf)0;
  4502 
  4503 	err = deflateInit(&stream, level);
  4504 	if (err != Z_OK) return err;    
  4505 
  4506 	err = deflate(&stream, Z_FINISH);
  4507 	if (err != Z_STREAM_END) 
  4508 		{
  4509 		deflateEnd(&stream);
  4510 		return err == Z_OK ? Z_BUF_ERROR : err;
  4511 		}
  4512 	*destLen = stream.total_out;    
  4513 	int h=inflateSyncPoint(&stream);
  4514 	if(h!=0)
  4515 		{
  4516 		res=KErrGeneral;
  4517 		}
  4518 	deflateEnd(&stream);
  4519 	return res;
  4520 	}
  4521 
  4522 
  4523 TInt CTestZlib::TestInflateSyncPoint()
  4524 	{
  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)
  4532 		{
  4533 		return KErrNoMemory;
  4534 		}
  4535 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  4536 	if (uncompr == Z_NULL) 
  4537 		{
  4538 		free(compr);
  4539 		return KErrNoMemory;
  4540 		}
  4541 	res= test_syncpoint(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);
  4542 	free(compr);
  4543 	free(uncompr);
  4544 	return res;
  4545 	}
  4546 
  4547 TInt CTestZlib::TestInflateSyncPoint_null()
  4548 	{
  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)
  4556 		{
  4557 		return KErrNoMemory;
  4558 		}
  4559 	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  4560 	if (uncompr == Z_NULL) 
  4561 		{
  4562 		free(compr);
  4563 		return KErrNoMemory;
  4564 		}
  4565 	int h=inflateSyncPoint(NULL);
  4566 	if(h==0)
  4567 		{
  4568 		res=KErrGeneral;
  4569 		}
  4570 	free(compr);
  4571 	free(uncompr);
  4572 	return res;
  4573 	}
  4574 
  4575 
  4576 TInt CTestZlib::TestZerror()
  4577 	{
  4578 	TInt res = KErrNone ;
  4579 	const char * s = zError(1);
  4580 	if(strcmp(s,"stream end"))
  4581 		{
  4582 		res=KErrGeneral;
  4583 		}
  4584 	return res;
  4585 	}
  4586 
  4587 TInt CTestZlib::TestZerror1()
  4588 	{
  4589 	TInt res = KErrNone ;
  4590 	const char * s = zError(-3);
  4591 	if(strcmp(s,"data error"))
  4592 		{
  4593 		res=KErrGeneral;
  4594 		}
  4595 
  4596 	return res;
  4597 	} 
  4598 
  4599 TInt CTestZlib::TestZerror2()
  4600 	{
  4601 	TInt res = KErrNone ;
  4602 	const char * s = zError(0);
  4603 	if(strcmp(s,""))
  4604 		{
  4605 		res=KErrGeneral;
  4606 		}
  4607 
  4608 	return res;
  4609 	}
  4610