os/ossrv/compressionlibs/ziplib/test/tef/tlibz/src/tzlib_auto.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/compressionlibs/ziplib/test/tef/tlibz/src/tzlib_auto.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,4610 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "tzlib.h"
    1.23 +
    1.24 +/**
    1.25 + * Function Name : TestAdlerinit
    1.26 + * TestCase Description: Testing Adler
    1.27 + * Return Value: Return KErrNone if adler32=1, else return KErrGeneral
    1.28 + */
    1.29 +TInt CTestZlib::TestAdlerinit()
    1.30 +	{
    1.31 +	TInt res = KErrNone ;
    1.32 +	unsigned long j=0L;
    1.33 +
    1.34 +	long adler1 = adler32(j,0, 0);
    1.35 +	if(adler1 == 1)
    1.36 +		{    	
    1.37 +		res=KErrNone ;    	
    1.38 +		}
    1.39 +	else
    1.40 +		{    	
    1.41 +		res = KErrGeneral;
    1.42 +		}
    1.43 +	return res;
    1.44 +	}
    1.45 +
    1.46 +/**
    1.47 + * Function Name : TestAdler
    1.48 + * TestCase Description: Testing Adler32
    1.49 + * Return Value:  Return KErrNone if adler32>0, else return KErrGeneral
    1.50 + */
    1.51 +TInt CTestZlib::TestAdler()
    1.52 +	{
    1.53 +	TInt res = KErrNone ;
    1.54 +	unsigned char  buffer[5]="1234";
    1.55 +	unsigned int i=4;
    1.56 +	unsigned long j=0L;
    1.57 +
    1.58 +	long adler1 = adler32(j,0, 0);
    1.59 +	long adler = adler32(adler1, &buffer[0], i);
    1.60 +	INFO_PRINTF2(_L("buf %x"),adler);
    1.61 +
    1.62 +	if(adler > 0)
    1.63 +		{    	
    1.64 +		res=KErrNone ;    	
    1.65 +		}
    1.66 +	else
    1.67 +		{    	
    1.68 +		res = KErrGeneral;
    1.69 +		}
    1.70 +	return res;
    1.71 +	}
    1.72 +
    1.73 +/**
    1.74 + * Function Name : TestDeflateReset
    1.75 + * TestCase Description: Call deflateReset after deflateInit
    1.76 + * Return Value: Returns KErrNone on deflateReset returning Z_OK, else KErrGeneral
    1.77 + */  
    1.78 +TInt CTestZlib::TestDeflateReset()
    1.79 +	{ 
    1.80 +	INFO_PRINTF1(_L("DeflateReset test with valid input"));
    1.81 +	TInt res = KErrNone ;
    1.82 +	int level = Z_DEFAULT_COMPRESSION ;
    1.83 +	uLong len = (uLong)strlen(hello)+1;
    1.84 +	Byte *compr, *uncompr;
    1.85 +	uLong comprLen = 20*sizeof(int); 
    1.86 +	uLong uncomprLen = comprLen;
    1.87 +	int err;
    1.88 +	z_stream stream;
    1.89 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
    1.90 +	if (compr == Z_NULL)
    1.91 +		{
    1.92 +		return KErrNoMemory;
    1.93 +		}
    1.94 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
    1.95 +	if (uncompr == Z_NULL) 
    1.96 +		{
    1.97 +		free(compr);
    1.98 +		return KErrNoMemory;
    1.99 +		}
   1.100 +
   1.101 +	stream.zalloc = (alloc_func)0;
   1.102 +	stream.zfree = (free_func)0;
   1.103 +	stream.opaque = (voidpf)0;
   1.104 +
   1.105 +	err = deflateInit(&stream, level);
   1.106 +	if (err != Z_OK) 
   1.107 +		{
   1.108 +		free(compr);
   1.109 +		free(uncompr);
   1.110 +		return KErrGeneral;
   1.111 +		}
   1.112 +
   1.113 +	Bytef *dest = compr ;
   1.114 +	uLongf *destLen = &comprLen;
   1.115 +	const Bytef *source = (const Bytef*)hello;
   1.116 +	uLong sourceLen = len;  
   1.117 +
   1.118 +	stream.next_in = (Bytef*)source;
   1.119 +	stream.avail_in = (uInt)sourceLen;
   1.120 +#ifdef MAXSEG_64K
   1.121 +/* Check for source > 64K on 16-bit machine: */
   1.122 +if ((uLong)stream.avail_in != sourceLen)  
   1.123 +	{
   1.124 +	res = KErrGeneral; 
   1.125 +	}
   1.126 +#endif
   1.127 +stream.next_out = dest;
   1.128 +stream.avail_out = (uInt)*destLen;
   1.129 +if ((uLong)stream.avail_out != *destLen)  
   1.130 +	{
   1.131 +	res = KErrGeneral; 
   1.132 +	}
   1.133 +err=deflateReset(&stream);
   1.134 +if (err != Z_OK)  
   1.135 +	{
   1.136 +	res = KErrGeneral;     			
   1.137 +	} 
   1.138 +else  
   1.139 +	{    	
   1.140 +	res = KErrNone;
   1.141 +	}   
   1.142 +err = deflateEnd(&stream);
   1.143 +if (err != Z_OK) 
   1.144 +	{
   1.145 +	INFO_PRINTF1(_L("Error in deflateEnd"));
   1.146 +	free(compr);
   1.147 +	free(uncompr);	
   1.148 +	return KErrGeneral;
   1.149 +	}
   1.150 +free(compr);
   1.151 +free(uncompr);
   1.152 +return res;
   1.153 +	}
   1.154 +
   1.155 +/**
   1.156 + * Function Name : TestDeflateReset_fail
   1.157 + * TestCase Description: Call deflateReset before calling deflateInit
   1.158 + * Return Value: Return KErrNone incase of deflateReset returning Z_STREAM_ERROR, else KErrGeneral
   1.159 + */ 
   1.160 +TInt CTestZlib::TestDeflateReset_fail()
   1.161 +	{ 
   1.162 +	TInt res = KErrNone ;
   1.163 +	uLong len = (uLong)strlen(hello)+1;
   1.164 +	Byte *compr, *uncompr;
   1.165 +	uLong comprLen = 20*sizeof(int); 
   1.166 +	uLong uncomprLen = comprLen;
   1.167 +	int err;
   1.168 +	z_stream stream;
   1.169 +	compr = (Byte*)calloc((uInt)comprLen, 1);
   1.170 +	if (compr == Z_NULL)
   1.171 +		{
   1.172 +		return KErrNoMemory;
   1.173 +		}
   1.174 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   1.175 +	if (uncompr == Z_NULL) 
   1.176 +		{
   1.177 +		free(compr);
   1.178 +		return KErrNoMemory;
   1.179 +		}
   1.180 +
   1.181 +	stream.zalloc = (alloc_func)0;
   1.182 +	stream.zfree = (free_func)0;
   1.183 +	stream.opaque = (voidpf)0;
   1.184 +	err=deflateReset(&stream);
   1.185 +	if (err != Z_OK)  
   1.186 +		{
   1.187 +		res = KErrNone;
   1.188 +		} 
   1.189 +	else  
   1.190 +		{    	
   1.191 +		res = KErrGeneral;     			
   1.192 +		}   
   1.193 +	free(compr);
   1.194 +	free(uncompr);
   1.195 +	return res;
   1.196 +	}
   1.197 +
   1.198 +/**
   1.199 + * Function Name : TestDeflateInit2_bits
   1.200 + * TestCase Description: Call deflateInit2_ with window bits = 15 as argument
   1.201 + * Return Value: Return KErrNone if deflateInit2_ returns Z_OK
   1.202 + */
   1.203 +TInt CTestZlib::TestDeflateInit2_bits()
   1.204 +	{
   1.205 +	TInt res = KErrNone ;
   1.206 +	z_stream stream;
   1.207 +	int err;
   1.208 +	int level=Z_DEFAULT_COMPRESSION;
   1.209 +
   1.210 +	uLong sourceLen = (uLong)strlen(hello)+1;
   1.211 +	Byte *compr;
   1.212 +	uLong comprLen = 10*sizeof(int); 
   1.213 +	compr = (Byte*)calloc((uInt)comprLen, 1);
   1.214 +	if (compr == Z_NULL)
   1.215 +		{
   1.216 +		return KErrNoMemory;
   1.217 +		}
   1.218 +	stream.zalloc = (alloc_func)0;
   1.219 +	stream.zfree = (free_func)0;
   1.220 +	stream.opaque = (voidpf)0;
   1.221 +
   1.222 +	err= deflateInit2_(&stream, level, 3, 15, 8, 0, zlibVersion(), sizeof(z_stream));
   1.223 +
   1.224 +	if (err != Z_OK) 
   1.225 +		{
   1.226 +		res = KErrNone;
   1.227 +		} 
   1.228 +	else  
   1.229 +		{    	
   1.230 +		res = KErrGeneral; 
   1.231 +		}   
   1.232 +	free(compr);
   1.233 +	return res;
   1.234 +	}
   1.235 +
   1.236 +/**
   1.237 + * Function Name : TestDeflateInit2_level
   1.238 + * TestCase Description: Call deflateInit2_ with window bits = 2 as argument
   1.239 + * Return Value: Returns KErrNone on deflateInit2_ returning Z_OK
   1.240 + */
   1.241 +TInt CTestZlib::TestDeflateInit2_level()
   1.242 +	{
   1.243 +	TInt res = KErrNone ;
   1.244 +	z_stream stream;
   1.245 +	int err;
   1.246 +	int level=Z_DEFAULT_COMPRESSION;
   1.247 +
   1.248 +	uLong sourceLen = (uLong)strlen(hello)+1;
   1.249 +	Byte *compr;
   1.250 +	uLong comprLen = 10*sizeof(int); 
   1.251 +	compr = (Byte*)calloc((uInt)comprLen, 1);
   1.252 +	if (compr == Z_NULL)
   1.253 +		{
   1.254 +		return KErrNoMemory;
   1.255 +		}
   1.256 +
   1.257 +	stream.zalloc = (alloc_func)0;
   1.258 +	stream.zfree = (free_func)0;
   1.259 +	stream.opaque = (voidpf)0;
   1.260 +
   1.261 +	err= deflateInit2_(&stream, level, 3, 2, 8,
   1.262 +			0,  zlibVersion(), sizeof(z_stream));
   1.263 +
   1.264 +	if (err != Z_OK) 
   1.265 +		{
   1.266 +		res = KErrNone;
   1.267 +		} 
   1.268 +	else  
   1.269 +		{    	
   1.270 +		res = KErrGeneral; 
   1.271 +		}   
   1.272 +	free(compr);
   1.273 +	return res;
   1.274 +	}
   1.275 +
   1.276 +/**
   1.277 + * Function Name : TestInflateInit2_bits
   1.278 + * TestCase Description: Call inflateInit2_ with window bits = 5 as argument
   1.279 + * Return Value: Returns KErrNone on inflateInit2_ returning Z_OK
   1.280 + */  
   1.281 +TInt CTestZlib::TestInflateInit2_bits()
   1.282 +	{
   1.283 +	TInt res = KErrNone ;
   1.284 +	z_stream d_stream; // decompression stream
   1.285 +	const char * version;
   1.286 +	d_stream.zalloc = (alloc_func)0;
   1.287 +	d_stream.zfree = (free_func)0;
   1.288 +	d_stream.opaque = (voidpf)0;
   1.289 +
   1.290 +	version = zlibVersion();
   1.291 +	int ret =  inflateInit2_(&d_stream,5,version, sizeof(d_stream));
   1.292 +	if(ret==0)
   1.293 +		{ 
   1.294 +		res = KErrGeneral;    	
   1.295 +		}
   1.296 +	else
   1.297 +		{    
   1.298 +		res = KErrNone;    
   1.299 +		} 
   1.300 +	return res;       
   1.301 +	}
   1.302 +
   1.303 +/**
   1.304 + * Function Name : TestGzread
   1.305 + * TestCase Description: 1. Open a gz file in read mode
   1.306 + *						2. gzRead from the opened file. Reads the given number of uncompressed bytes from the compressed file.
   1.307 + *						3. close the gz file
   1.308 + * Return Value: Returns KErrNone on reading the gzfile successfully
   1.309 + */  
   1.310 +TInt CTestZlib::TestGzread()
   1.311 +	{
   1.312 +	char * buf1 = (char*)malloc(1024);
   1.313 +	if (buf1 == NULL)
   1.314 +		{
   1.315 +		ERR_PRINTF1(_L("Heap out of memory"));
   1.316 +		return KErrNoMemory;
   1.317 +		}
   1.318 +
   1.319 +	int len1;
   1.320 +	TInt res = KErrNone ;
   1.321 +	char  *file=FILETESTGZ;
   1.322 +	char *infile;
   1.323 +	gzFile in;
   1.324 +	infile = file;
   1.325 +	in = gzopen(infile, "rb");           
   1.326 +	if (in == Z_NULL) 
   1.327 +		{
   1.328 +		free(buf1);
   1.329 +		ERR_PRINTF1(_L("Could not open the file"));
   1.330 +		res = KErrGeneral;
   1.331 +		return res;
   1.332 +		}   
   1.333 +	for (;;)
   1.334 +		{
   1.335 +		len1 = gzread(in, buf1, sizeof(buf1));
   1.336 +		if (len1 == 0 )
   1.337 +			break;
   1.338 +		else if(len1 < 0 ) 
   1.339 +			{
   1.340 +			INFO_PRINTF1(_L("Error in reading the file"));
   1.341 +			free(buf1);
   1.342 +			return KErrGeneral;
   1.343 +			}
   1.344 +		}
   1.345 +	if (gzclose(in) != Z_OK)
   1.346 +		{    	
   1.347 +		ERR_PRINTF1(_L("Could not close the file"));
   1.348 +		res=KErrGeneral;     
   1.349 +		}
   1.350 +	free(buf1);
   1.351 +	return res;
   1.352 +	}   
   1.353 +
   1.354 +/**
   1.355 + * Function Name : TestGzread_fail
   1.356 + * TestCase Description: 1. Open a gz file in write mode
   1.357 + *						2. gzRead from the file. 
   1.358 + *						3. close the file
   1.359 + * Return Value: Returns KErrNone on gzread returning -1
   1.360 + */   
   1.361 +TInt CTestZlib::TestGzread_fail()
   1.362 +	{
   1.363 +	char * buf1 = (char*)malloc(1024);
   1.364 +	if(buf1==NULL)
   1.365 +		{
   1.366 +		return KErrNoMemory;
   1.367 +		}
   1.368 +	int len1;
   1.369 +	TInt res = KErrNone ;
   1.370 +	gzFile in = Z_NULL;
   1.371 +	in = gzopen(FILETESTGZ1, "wb"); 
   1.372 +	res=(int)in;
   1.373 +	if (0 == res)
   1.374 +		{
   1.375 +		free(buf1);
   1.376 +		return KErrNoMemory;;
   1.377 +		}
   1.378 +
   1.379 +	len1 = gzread(in, buf1, sizeof(buf1));
   1.380 +	if (len1 < 0) 
   1.381 +		{
   1.382 +		res = KErrNone;
   1.383 +		}
   1.384 +	else if (0 == len1)
   1.385 +		{
   1.386 +		res = KErrGeneral;
   1.387 +		}
   1.388 +
   1.389 +	if (gzclose(in) != Z_OK)
   1.390 +		{
   1.391 +		free(buf1);
   1.392 +		INFO_PRINTF1(_L("Error encountered while closing the file"));
   1.393 +		return KErrGeneral;     
   1.394 +		}
   1.395 +
   1.396 +	free(buf1);
   1.397 +	return res;
   1.398 +	}   
   1.399 +/**
   1.400 + * Function Name : test_uncompress
   1.401 + * TestCase Description: This is a global function used by many test functions
   1.402 + */ 
   1.403 +TInt test_uncompress(Byte * compr,uLong comprLen,Byte * uncompr,uLong uncomprLen)
   1.404 +	{
   1.405 +	TInt res = KErrNone ;
   1.406 +	int err;
   1.407 +	uLong len = (uLong)strlen(hello)+1;
   1.408 +
   1.409 +	err = compress(compr, &comprLen, (const Bytef*)hello, len);
   1.410 +
   1.411 +	if(err == 0)
   1.412 +		{    	
   1.413 +		strcpy((char*)uncompr, "garbage");
   1.414 +		err = uncompress(uncompr, &uncomprLen, compr, comprLen);
   1.415 +		if(err < Z_OK)
   1.416 +			{
   1.417 +			res = KErrGeneral ;
   1.418 +			}    
   1.419 +		} 
   1.420 +	else
   1.421 +		{    	
   1.422 +		res = KErrGeneral;
   1.423 +		}
   1.424 +
   1.425 +	return res;
   1.426 +	}
   1.427 +/**
   1.428 + * Function Name : TestUncompress
   1.429 + * TestCase Description: 1. Compress a text sample
   1.430 + *						2. Uncompress is called with appropriate lengths 
   1.431 + *						   for compressed and uncompressed data
   1.432 + *	
   1.433 + * Return Value: Z_OK
   1.434 + */ 
   1.435 +TInt CTestZlib::TestUncompress()
   1.436 +	{
   1.437 +	TInt res = KErrNone ;
   1.438 +	Byte *compr, *uncompr;
   1.439 +	uLong comprLen = 20*sizeof(int); 
   1.440 +	uLong uncomprLen = comprLen;
   1.441 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
   1.442 +	if (compr == Z_NULL)
   1.443 +		{
   1.444 +		return KErrNoMemory;
   1.445 +		}
   1.446 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   1.447 +	if (uncompr == Z_NULL) 
   1.448 +		{
   1.449 +		free(compr);
   1.450 +		return KErrNoMemory;
   1.451 +		}
   1.452 +	res =  test_uncompress(compr, comprLen, uncompr, uncomprLen);
   1.453 +	free(compr);
   1.454 +	free(uncompr);
   1.455 +	return res;
   1.456 +	}
   1.457 +
   1.458 +/**
   1.459 + * Function Name : TestUncompressfail
   1.460 + * TestCase Description: 1. Uncompress is called with uncompressed length smaller than required
   1.461 + *	
   1.462 + * Return Value: Z_BUF_ERROR
   1.463 + */   
   1.464 +TInt CTestZlib::TestUncompressfail()
   1.465 +	{
   1.466 +	TInt res = KErrNone ;
   1.467 +	Byte *compr, *uncompr;
   1.468 +	uLong comprLen = 1*sizeof(int); 
   1.469 +	uLong uncomprLen = comprLen;
   1.470 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
   1.471 +	if (compr == Z_NULL)
   1.472 +		{
   1.473 +		return Z_MEM_ERROR;
   1.474 +		}
   1.475 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   1.476 +	if (uncompr == Z_NULL) 
   1.477 +		{
   1.478 +		free(compr);
   1.479 +		return KErrNoMemory;
   1.480 +		}
   1.481 +	int err =  test_uncompress(compr, comprLen, uncompr, uncomprLen);
   1.482 +	if(err==0)
   1.483 +		{
   1.484 +		res = KErrGeneral;
   1.485 +		} 
   1.486 +	free(compr);
   1.487 +	free(uncompr);
   1.488 +	return res;
   1.489 +	}
   1.490 +
   1.491 +/**
   1.492 + * Function Name : Test_dict_deflate
   1.493 + * TestCase Description: This is a global function used by many test functions
   1.494 + */ 
   1.495 +TInt CTestZlib::Test_dict_deflate( Byte * compr,uLong comprLen)
   1.496 +	{
   1.497 +	TInt res = KErrNone ;
   1.498 +	z_stream c_stream; /* compression stream */
   1.499 +	int err;
   1.500 +
   1.501 +	c_stream.zalloc = (alloc_func)0;
   1.502 +	c_stream.zfree = (free_func)0;
   1.503 +	c_stream.opaque = (voidpf)0;
   1.504 +
   1.505 +	err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
   1.506 +	if(err<0)
   1.507 +		{
   1.508 +		res = KErrGeneral;
   1.509 +		return res;	
   1.510 +		}
   1.511 +
   1.512 +	err = deflateSetDictionary(&c_stream,
   1.513 +			(const Bytef*)dictionary, sizeof(dictionary));
   1.514 +	if(err<0)
   1.515 +		{
   1.516 +		res = KErrGeneral;
   1.517 +		return res;
   1.518 +		}
   1.519 +	dictId = c_stream.adler;
   1.520 +	c_stream.next_out = compr;
   1.521 +	c_stream.avail_out = (uInt)comprLen;
   1.522 +
   1.523 +	c_stream.next_in = (Bytef*)hello;
   1.524 +	c_stream.avail_in = (uInt)strlen(hello)+1;
   1.525 +
   1.526 +	err = deflate(&c_stream, Z_FINISH);
   1.527 +	if (err != Z_STREAM_END) 
   1.528 +		{
   1.529 +		res = KErrGeneral;
   1.530 +		}
   1.531 +	err = deflateEnd(&c_stream);
   1.532 +	if (err != 0) 
   1.533 +		{
   1.534 +		res = KErrGeneral;
   1.535 +		}
   1.536 +	return res;
   1.537 +	}
   1.538 +
   1.539 +
   1.540 +/**
   1.541 + * Function Name : Test_dict_inflate
   1.542 + * TestCase Description: This is an utility function used by many test functions
   1.543 + */
   1.544 +TInt CTestZlib::Test_dict_inflate(Byte * compr,uLong comprLen, Byte * uncompr,uLong uncomprLen)
   1.545 +	{
   1.546 +	TInt res = KErrNone ;
   1.547 +	int err;
   1.548 +	z_stream d_stream; /* decompression stream */
   1.549 +
   1.550 +	strcpy((char*)uncompr, "garbage");
   1.551 +
   1.552 +	d_stream.zalloc = (alloc_func)0;
   1.553 +	d_stream.zfree = (free_func)0;
   1.554 +	d_stream.opaque = (voidpf)0;
   1.555 +
   1.556 +	d_stream.next_in  = compr;
   1.557 +	d_stream.avail_in = (uInt)comprLen;
   1.558 +
   1.559 +	err = inflateInit(&d_stream);
   1.560 +	if(Z_MEM_ERROR == err)
   1.561 +		{
   1.562 +		return Z_MEM_ERROR;    	
   1.563 +		}
   1.564 +	else if(Z_VERSION_ERROR == err)
   1.565 +		{
   1.566 +		return Z_VERSION_ERROR;    	
   1.567 +		}
   1.568 +
   1.569 +	d_stream.next_out = uncompr;
   1.570 +	d_stream.avail_out = (uInt)uncomprLen;
   1.571 +
   1.572 +	for (;;) 
   1.573 +		{
   1.574 +		err = inflate(&d_stream, Z_NO_FLUSH);
   1.575 +		if (err == Z_NEED_DICT) 
   1.576 +			{
   1.577 +			if (d_stream.adler != dictId) 
   1.578 +				{
   1.579 +				break;
   1.580 +				}
   1.581 +			err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
   1.582 +					sizeof(dictionary));
   1.583 +			if(err < Z_OK)
   1.584 +				{
   1.585 +				INFO_PRINTF1(_L("Error returned by inflateSetDictionary"));
   1.586 +				break;
   1.587 +				}
   1.588 +			}
   1.589 +		else
   1.590 +			{
   1.591 +			break;
   1.592 +			}
   1.593 +		}		// end of for
   1.594 +
   1.595 +		err = inflateEnd(&d_stream);
   1.596 +		if (strcmp((char*)uncompr, hello)) 
   1.597 +			{
   1.598 +			INFO_PRINTF1(_L("Bad inflate with dictionary"));
   1.599 +			res = KErrGeneral;
   1.600 +			} 
   1.601 +		else 
   1.602 +			{
   1.603 +			INFO_PRINTF1(_L("Inflate with dictionary successful"));
   1.604 +			}
   1.605 +		return res;
   1.606 +	}
   1.607 +
   1.608 +/**
   1.609 + * Function Name : TestInflateSetDictionary
   1.610 + * TestCase Description: 1.	Deflate string using an existing dictionary
   1.611 + *						2.	Uncompress the compressed text using an existing dictionary
   1.612 + * Return Value: Z_BUF_ERROR
   1.613 + */ 
   1.614 +TInt CTestZlib::TestInflateSetDictionary()
   1.615 +	{
   1.616 +	TInt res = KErrNone ;
   1.617 +	Byte *compr, *uncompr;
   1.618 +	uLong comprLen = 100*sizeof(int); 
   1.619 +	uLong uncomprLen = comprLen;
   1.620 +
   1.621 +	compr = (Byte*)calloc((uInt)comprLen, 1);
   1.622 +	if (compr == NULL)
   1.623 +		{
   1.624 +		return KErrNoMemory;
   1.625 +		}
   1.626 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   1.627 +	if (uncompr == Z_NULL) 
   1.628 +		{
   1.629 +		free(compr);
   1.630 +		return KErrNoMemory;
   1.631 +		}
   1.632 +	res = Test_dict_deflate(compr, comprLen);
   1.633 +	if(res < 0)
   1.634 +		{
   1.635 +		free(compr);
   1.636 +		free(uncompr);
   1.637 +		return res;
   1.638 +		}
   1.639 +	if(res==0)
   1.640 +		{
   1.641 +		res=Test_dict_inflate(compr, comprLen, uncompr, uncomprLen);	
   1.642 +		}
   1.643 +	else
   1.644 +		{
   1.645 +		res=KErrGeneral;
   1.646 +		}
   1.647 +	free(compr);
   1.648 +	free(uncompr);
   1.649 +	return res;
   1.650 +	}
   1.651 +
   1.652 +
   1.653 +/**
   1.654 + * Function Name : TestInflateSetDictionary_size
   1.655 + * TestCase Description: 1.	Deflate string using an existing dictionary
   1.656 + *						2.	Uncompress the compresses text using a mismatching dictionary
   1.657 + * Return Value: Z_DATA_ERROR
   1.658 + */    
   1.659 +TInt CTestZlib::TestInflateSetDictionary_size()
   1.660 +	{ 
   1.661 +
   1.662 +	TInt res=KErrNone;
   1.663 +	Byte *compr, *uncompr;
   1.664 +	uLong comprLen = 20*sizeof(int); 
   1.665 +	uLong uncomprLen = comprLen;
   1.666 +	z_stream d_stream; /* decompression stream */
   1.667 +
   1.668 +	compr = (Byte*)calloc((uInt)comprLen, 1);
   1.669 +	if (compr == Z_NULL)
   1.670 +		{
   1.671 +		return KErrNoMemory;
   1.672 +		}
   1.673 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   1.674 +	if (uncompr == Z_NULL) 
   1.675 +		{
   1.676 +		free(compr);
   1.677 +		return KErrNoMemory;
   1.678 +		}
   1.679 +
   1.680 +	res = Test_dict_deflate(compr, comprLen);
   1.681 +	if(res<0)
   1.682 +		{
   1.683 +		res=KErrGeneral;
   1.684 +		free(compr);
   1.685 +		free(uncompr);
   1.686 +		return res;
   1.687 +		}
   1.688 +	strcpy((char*)uncompr, "garbage");
   1.689 +
   1.690 +	d_stream.zalloc = (alloc_func)0;
   1.691 +	d_stream.zfree = (free_func)0;
   1.692 +	d_stream.opaque = (voidpf)0;
   1.693 +
   1.694 +	d_stream.next_in  = compr;
   1.695 +	d_stream.avail_in = (uInt)comprLen;
   1.696 +
   1.697 +	int err = inflateInit(&d_stream);
   1.698 +
   1.699 +	d_stream.next_out = uncompr;
   1.700 +	d_stream.avail_out = (uInt)uncomprLen;
   1.701 +
   1.702 +	for (;;) 
   1.703 +		{
   1.704 +		int err = inflate(&d_stream, Z_NO_FLUSH);
   1.705 +		if (err == Z_STREAM_END || err == Z_MEM_ERROR) break;
   1.706 +		err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,sizeof(dictionary)+2);
   1.707 +		if(Z_DATA_ERROR == err)
   1.708 +			{
   1.709 +			res=KErrNone; 
   1.710 +			break;     
   1.711 +			}
   1.712 +		else 
   1.713 +			{
   1.714 +			res=KErrGeneral; 
   1.715 +			break;
   1.716 +			}
   1.717 +		}
   1.718 +	err = inflateEnd(&d_stream);
   1.719 +	if(err != Z_OK)
   1.720 +		{
   1.721 +		INFO_PRINTF1(_L("InflateEnd failed"));
   1.722 +		free(compr);
   1.723 +		free(uncompr);
   1.724 +		return KErrGeneral;
   1.725 +		}
   1.726 +
   1.727 +	free(compr);
   1.728 +	free(uncompr);
   1.729 +	return res;
   1.730 +	}
   1.731 +
   1.732 +/**
   1.733 + * Function Name : TestInflateSetDictionary_null
   1.734 + * TestCase Description: 1.	Deflate string using an existing dictionary
   1.735 + *						2.	Pass null pointer to inflateSetDictionary
   1.736 + * Return Value: Z_DATA_ERROR
   1.737 + */     
   1.738 +TInt CTestZlib::TestInflateSetDictionary_null()
   1.739 +	{
   1.740 +	TInt res=KErrNone;
   1.741 +	Byte *compr, *uncompr;
   1.742 +	uLong comprLen = 20*sizeof(int); 
   1.743 +	uLong uncomprLen = comprLen;
   1.744 +
   1.745 +	compr = (Byte*)calloc((uInt)comprLen, 1);
   1.746 +	if (compr == Z_NULL)
   1.747 +		{
   1.748 +		return KErrNoMemory;
   1.749 +		}
   1.750 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   1.751 +	if (uncompr == Z_NULL) 
   1.752 +		{
   1.753 +		free(compr);
   1.754 +		return KErrNoMemory;
   1.755 +		}
   1.756 +
   1.757 +	res= Test_dict_deflate(compr, comprLen);
   1.758 +	if(res == KErrGeneral)
   1.759 +		{
   1.760 +		free(compr);
   1.761 +		free(uncompr);
   1.762 +		return res;
   1.763 +		}
   1.764 +	int err = inflateSetDictionary(NULL, (const Bytef*)dictionary,sizeof(dictionary));
   1.765 +	if(err != Z_STREAM_ERROR)
   1.766 +		{
   1.767 +		res=KErrGeneral;
   1.768 +		}
   1.769 +	free(compr);
   1.770 +	free(uncompr);
   1.771 +	return res;
   1.772 +	}
   1.773 +
   1.774 +/**
   1.775 + * Function Name : test_compress
   1.776 + * TestCase Description: This is a global function used by many test functions
   1.777 + */
   1.778 +TInt test_compress(Byte * compr,uLong comprLen,Byte * uncompr,uLong uncomprLen)
   1.779 +	{
   1.780 +	int err = KErrNone;
   1.781 +	uLong len = (uLong)strlen(hello)+1;
   1.782 +
   1.783 +	err = compress(compr, &comprLen, (const Bytef*)hello, len);
   1.784 +
   1.785 +	if(err<0)
   1.786 +		{
   1.787 +		return err;
   1.788 +		}
   1.789 +	strcpy((char*)uncompr, "garbage");
   1.790 +
   1.791 +	err = uncompress(uncompr, &uncomprLen, compr, comprLen);
   1.792 +
   1.793 +	if(err<0)
   1.794 +		{
   1.795 +		return err;
   1.796 +		}
   1.797 +	if (strcmp((char*)uncompr, hello)) 
   1.798 +		{
   1.799 +		//INFO_PRINTF1(_L("Uncompressed string does not match with original string"));
   1.800 +		err = KErrGeneral;
   1.801 +		}
   1.802 +	else 
   1.803 +		{
   1.804 +		err=0;
   1.805 +		}
   1.806 +	return err;
   1.807 +	}
   1.808 +
   1.809 +/**
   1.810 + * Function Name : test_gzgets
   1.811 + * TestCase Description: This is a global function used by many test functions
   1.812 + */
   1.813 +int test_gzgets(const char * fname, Byte * uncompr,uLong  uncomprLen)
   1.814 +	{
   1.815 +	int err = KErrNone;
   1.816 +	int len = (int)strlen(hello)+1;
   1.817 +	gzFile file;
   1.818 +
   1.819 +	file = gzopen(fname, "wb");
   1.820 +	if (file == NULL) 
   1.821 +		{
   1.822 +		err = KErrGeneral; 
   1.823 +		return err;        
   1.824 +		}
   1.825 +	gzputc(file, 'h');
   1.826 +	if (gzputs(file, "ello") != 4) 
   1.827 +		{
   1.828 +		err=1;
   1.829 +		}
   1.830 +	if (gzprintf(file, ", %s!", "hello") != 8) 
   1.831 +		{
   1.832 +		err=1;
   1.833 +		}
   1.834 +	err = gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
   1.835 +	if (err < 0)
   1.836 +		{
   1.837 +		//INFO_PRINTF1(_L("Error returned by gzssek"));
   1.838 +		}
   1.839 +	gzclose(file);
   1.840 +
   1.841 +	file = gzopen(fname, "rb");
   1.842 +	if (file == NULL) 
   1.843 +		{
   1.844 +		err = KErrGeneral; 
   1.845 +		return err;        
   1.846 +		}
   1.847 +	strcpy((char*)uncompr, "garbage");
   1.848 +	if (gzread(file, uncompr, (unsigned)uncomprLen) != len) 
   1.849 +		{
   1.850 +		}
   1.851 +	if (strcmp((char*)uncompr, hello))
   1.852 +		{
   1.853 +		err=0;
   1.854 +		}
   1.855 +	else 
   1.856 +		{
   1.857 +		err=1;
   1.858 +		}
   1.859 +
   1.860 +	err = gzseek(file, -8L, SEEK_CUR);
   1.861 +	if (err < 0)
   1.862 +		{
   1.863 +		//INFO_PRINTF1(_L("Error returned by gzssek"));
   1.864 +		}
   1.865 +	gzgets(file, (char*)uncompr, (int)uncomprLen);
   1.866 +
   1.867 +	if (strlen((char*)uncompr) != 7) // " hello!" 
   1.868 +		{ 
   1.869 +		err=0;
   1.870 +		}
   1.871 +	gzclose(file);    
   1.872 +	return err;
   1.873 +	}
   1.874 +
   1.875 +/**
   1.876 + * Function Name : TestGzgets
   1.877 + * TestCase Description: 1. Open a gz compressed file in read mode
   1.878 + *						2. Read certain valid number of bytes from the compressed file
   1.879 + * Return Value: Returns read buffer
   1.880 + */
   1.881 +TInt CTestZlib::TestGzgets()
   1.882 +	{ 	
   1.883 +	TInt res = KErrNone ;
   1.884 +	Byte *compr, *uncompr;
   1.885 +	uLong comprLen = 20*sizeof(int); 
   1.886 +
   1.887 +	uLong uncomprLen = comprLen;
   1.888 +	compr = (Byte*)calloc((uInt)comprLen, 1);
   1.889 +	if (compr == Z_NULL)
   1.890 +		{
   1.891 +		return KErrNoMemory;
   1.892 +		}
   1.893 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   1.894 +	if (uncompr == Z_NULL) 
   1.895 +		{
   1.896 +		free(compr);
   1.897 +		return KErrNoMemory;
   1.898 +		}
   1.899 +
   1.900 +	res = test_compress(compr, comprLen, uncompr, uncomprLen);
   1.901 +	if(res < 0)
   1.902 +		{
   1.903 +		free(compr);
   1.904 +		free(uncompr);
   1.905 +		return KErrNoMemory;
   1.906 +		}
   1.907 +	int err=test_gzgets(MYFILE,uncompr, uncomprLen);
   1.908 +	if(err == 0)
   1.909 +		{    	
   1.910 +		res = KErrGeneral;
   1.911 +		}
   1.912 +	free(compr);
   1.913 +	free(uncompr);
   1.914 +	return res;
   1.915 +	}
   1.916 +
   1.917 +/**
   1.918 + * Function Name : test_gzgetsfail
   1.919 + * TestCase Description: This is a global function used by many test functions
   1.920 + */
   1.921 +TInt test_gzgetsfail(const char * fname, Byte * uncompr,int  uncomprLen)
   1.922 +	{
   1.923 +	TInt res = KErrNone ;
   1.924 +	char* err;
   1.925 +	int len = (int)strlen(hello)+1;
   1.926 +	gzFile file;
   1.927 +
   1.928 +	file = gzopen(fname, "wb");
   1.929 +	if (file == NULL) 
   1.930 +		{
   1.931 +		res = KErrGeneral;
   1.932 +		}
   1.933 +	err = gzgets(file, (char*)uncompr, uncomprLen);
   1.934 +
   1.935 +	if(err == 0)
   1.936 +		{    	
   1.937 +		res = KErrNone ;    	
   1.938 +		}
   1.939 +	else
   1.940 +		{    	
   1.941 +		res = KErrGeneral;
   1.942 +		}
   1.943 +	int  err1=  gzclose(file);
   1.944 +	if (err1 != Z_OK)  
   1.945 +		{
   1.946 +		res = KErrGeneral; 
   1.947 +		}     
   1.948 +	return res;
   1.949 +	}
   1.950 +
   1.951 +
   1.952 +/**
   1.953 + * Function Name : TestgzgetsFail
   1.954 + * TestCase Description: 1. Open a gz compressed file in read mode
   1.955 + *						2. Invalid number of bytes (negative number) for gzgets
   1.956 + * Return Value: Z_NULL
   1.957 + */
   1.958 +TInt CTestZlib::TestgzgetsFail()
   1.959 +	{
   1.960 +	TInt res = KErrNone ; 
   1.961 +	Byte *compr, *uncompr;
   1.962 +	uLong comprLen = 20*sizeof(int); 
   1.963 +	uLong uncomprLen = comprLen;
   1.964 +	compr = (Byte*)calloc((uInt)comprLen, 1);
   1.965 +	if (compr == Z_NULL)
   1.966 +		{
   1.967 +		return KErrNoMemory;
   1.968 +		}
   1.969 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
   1.970 +	if (uncompr == Z_NULL) 
   1.971 +		{
   1.972 +		free(compr);
   1.973 +		return KErrNoMemory;
   1.974 +		}
   1.975 +	test_compress(compr, comprLen, uncompr, uncomprLen);
   1.976 +	int ret=  test_gzgetsfail(TESTFILE,uncompr, -1);
   1.977 +	if(ret == 0)
   1.978 +		{    	
   1.979 +		res = KErrNone ;    	
   1.980 +		}
   1.981 +	else
   1.982 +		{    	
   1.983 +		res = KErrGeneral;
   1.984 +		}
   1.985 +
   1.986 +	free(compr);
   1.987 +	free(uncompr);
   1.988 +	return res;
   1.989 +	}
   1.990 +
   1.991 +
   1.992 +/**
   1.993 + * Function Name : TestgzgetsopenFail
   1.994 + * TestCase Description: 1. Open a gz compressed file in read mode
   1.995 + *						2. Invalid number of bytes (negative number) for gzgets
   1.996 + * Return Value: KErrNone
   1.997 + */   
   1.998 +TInt CTestZlib::TestgzgetsopenFail()
   1.999 +	{
  1.1000 +	TInt res = KErrNone ;
  1.1001 +
  1.1002 +	Byte *compr, *uncompr;
  1.1003 +	uLong comprLen = 20*sizeof(int); 
  1.1004 +	uLong uncomprLen = comprLen;
  1.1005 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.1006 +	if (compr == Z_NULL)
  1.1007 +		{
  1.1008 +		return KErrNoMemory;
  1.1009 +		}
  1.1010 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1011 +	if (uncompr == Z_NULL) 
  1.1012 +		{
  1.1013 +		free(compr);
  1.1014 +		return KErrNoMemory;
  1.1015 +		}
  1.1016 +	res=test_compress(compr, comprLen, uncompr, uncomprLen);
  1.1017 +	if(res < 0)
  1.1018 +		{
  1.1019 +		free(compr);
  1.1020 +		free(uncompr);
  1.1021 +		return KErrNoMemory;
  1.1022 +		}
  1.1023 +	int err = test_gzgetsfail(NOFILE,uncompr, uncomprLen);
  1.1024 +
  1.1025 +	if(err != 0)
  1.1026 +		{    	
  1.1027 +		res = KErrNone ;    	
  1.1028 +		}
  1.1029 +	else
  1.1030 +		{    	
  1.1031 +		res = KErrGeneral;
  1.1032 +		}
  1.1033 +	free(compr);
  1.1034 +	free(uncompr);
  1.1035 +	return res;
  1.1036 +	}
  1.1037 +
  1.1038 +
  1.1039 +/**
  1.1040 + * Function Name : Test_deflate
  1.1041 + * TestCase Description: 1. Call deflateInit with valid arguments
  1.1042 + *						2. Call deflate with necessary valid arguments
  1.1043 + * Return Value: Z_OK
  1.1044 + */ 
  1.1045 +TInt CTestZlib::Test_deflate( Byte *compr, uLong comprLen)
  1.1046 +	{
  1.1047 +	TInt res = KErrNone ;
  1.1048 +	z_stream c_stream; /* compression stream */
  1.1049 +	int err;
  1.1050 +	uLong len = (uLong)strlen(hello)+1;
  1.1051 +
  1.1052 +	c_stream.zalloc = (alloc_func)0;
  1.1053 +	c_stream.zfree = (free_func)0;
  1.1054 +	c_stream.opaque = (voidpf)0;
  1.1055 +
  1.1056 +	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  1.1057 +
  1.1058 +	if(err<0)
  1.1059 +		{
  1.1060 +		return err;
  1.1061 +		}
  1.1062 +	c_stream.next_in = (Bytef*)hello;
  1.1063 +	c_stream.next_out = compr;
  1.1064 +
  1.1065 +	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  1.1066 +		{
  1.1067 +		c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
  1.1068 +		err = deflate(&c_stream, Z_NO_FLUSH);
  1.1069 +		}
  1.1070 +	/* Finish the stream, still forcing small buffers: */
  1.1071 +	for (;;) 
  1.1072 +		{
  1.1073 +		c_stream.avail_out = 1;
  1.1074 +		err = deflate(&c_stream, Z_FINISH);
  1.1075 +		if (err == Z_STREAM_END) break;
  1.1076 +		if(err!=Z_OK)
  1.1077 +			{
  1.1078 +			res = KErrGeneral;
  1.1079 +			}    
  1.1080 +		}
  1.1081 +	err = deflateEnd(&c_stream);
  1.1082 +	if(err!=Z_OK)
  1.1083 +		{
  1.1084 +		res = KErrGeneral;
  1.1085 +		} 
  1.1086 +	return res;
  1.1087 +	}
  1.1088 +
  1.1089 +
  1.1090 +/**
  1.1091 + * Function Name : TestInflate
  1.1092 + * TestCase Description: 1. Compress the data using deflate
  1.1093 + *						2. inflateInit to initialize internal stream state for decompression
  1.1094 + *						3. inflate with necessary valid arguments
  1.1095 + * Return Value: Z_OK
  1.1096 + */
  1.1097 +TInt CTestZlib::TestInflate()
  1.1098 +	{
  1.1099 +	TInt res = KErrNone ;
  1.1100 +	Byte *compr, *uncompr;
  1.1101 +	uLong comprLen = 20*sizeof(int); 
  1.1102 +	uLong uncomprLen = comprLen;
  1.1103 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.1104 +	if (compr == Z_NULL)
  1.1105 +		{
  1.1106 +		return KErrNoMemory;
  1.1107 +		}
  1.1108 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1109 +	if (uncompr == Z_NULL) 
  1.1110 +		{
  1.1111 +		free(compr);
  1.1112 +		return KErrNoMemory;
  1.1113 +		}
  1.1114 +	// test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  1.1115 +	res = Test_deflate(compr, comprLen);
  1.1116 +	if(res<0)
  1.1117 +		{
  1.1118 +		free(compr);
  1.1119 +		free(uncompr);
  1.1120 +		return KErrNoMemory;	
  1.1121 +		}
  1.1122 +
  1.1123 +	int err=0;
  1.1124 +	z_stream d_stream; /* decompression stream */
  1.1125 +
  1.1126 +	strcpy((char*)uncompr, "garbage");
  1.1127 +
  1.1128 +	d_stream.zalloc = (alloc_func)0;
  1.1129 +	d_stream.zfree = (free_func)0;
  1.1130 +	d_stream.opaque = (voidpf)0;
  1.1131 +
  1.1132 +	d_stream.next_in  = compr;
  1.1133 +	d_stream.avail_in = 0;
  1.1134 +	d_stream.next_out = uncompr;
  1.1135 +
  1.1136 +	res = inflateInit(&d_stream);
  1.1137 +
  1.1138 +	if(res<0)
  1.1139 +		{
  1.1140 +		free(compr);
  1.1141 +		free(uncompr);
  1.1142 +		return KErrNoMemory;	
  1.1143 +		}
  1.1144 +	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) 
  1.1145 +		{
  1.1146 +		d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
  1.1147 +		err = inflate(&d_stream, Z_SYNC_FLUSH);
  1.1148 +
  1.1149 +		if (err == Z_STREAM_END || err == Z_MEM_ERROR) break;
  1.1150 +		}
  1.1151 +	//inflate() should normally be called until it returns Z_STREAM_END 
  1.1152 +
  1.1153 +	if(err == Z_MEM_ERROR)
  1.1154 +		{
  1.1155 +		err = inflateEnd(&d_stream);
  1.1156 +		free(compr);
  1.1157 +		free(uncompr);
  1.1158 +		return err;
  1.1159 +		}
  1.1160 +	err = inflateEnd(&d_stream);
  1.1161 +
  1.1162 +	if (err != Z_OK)  
  1.1163 +		{
  1.1164 +		res = KErrGeneral;     			
  1.1165 +		} 
  1.1166 +	else
  1.1167 +		{
  1.1168 +		res=KErrNone ;
  1.1169 +		}
  1.1170 +	free(compr);
  1.1171 +	free(uncompr);
  1.1172 +	return res;
  1.1173 +	}
  1.1174 +
  1.1175 +
  1.1176 +/**
  1.1177 + * Function Name : TestInflate_fail1
  1.1178 + * TestCase Description: 1. Compress the data using deflate
  1.1179 + *						2. inflateInit to initialize internal stream state for decompression
  1.1180 + *						3. Set avail_in = 0 and call inflate
  1.1181 + * Return Value: Z_STREAM_ERROR
  1.1182 + */  
  1.1183 +TInt CTestZlib::TestInflate_fail1()
  1.1184 +	{
  1.1185 +	TInt res = KErrNone ;
  1.1186 +	Byte *compr, *uncompr;
  1.1187 +	uLong comprLen = 20*sizeof(int); 
  1.1188 +	uLong uncomprLen = comprLen;
  1.1189 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.1190 +	if (compr == Z_NULL)
  1.1191 +		{
  1.1192 +		return KErrNoMemory;
  1.1193 +		}
  1.1194 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1195 +	if (uncompr == Z_NULL) 
  1.1196 +		{
  1.1197 +		free(compr);
  1.1198 +		return KErrNoMemory;
  1.1199 +		}
  1.1200 +
  1.1201 +	// test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  1.1202 +	res = Test_deflate(compr, comprLen);
  1.1203 +	if(res<0)
  1.1204 +		{
  1.1205 +		free(compr);
  1.1206 +		free(uncompr);
  1.1207 +		return KErrNoMemory;	
  1.1208 +		}
  1.1209 +
  1.1210 +	int err;
  1.1211 +	z_stream d_stream; /* decompression stream */
  1.1212 +
  1.1213 +	strcpy((char*)uncompr, "garbage");
  1.1214 +
  1.1215 +	d_stream.zalloc = (alloc_func)0;
  1.1216 +	d_stream.zfree = (free_func)0;
  1.1217 +	d_stream.opaque = (voidpf)0;
  1.1218 +
  1.1219 +	d_stream.next_in  = compr;
  1.1220 +	d_stream.avail_in = 0;
  1.1221 +	d_stream.next_out = NULL;
  1.1222 +
  1.1223 +	err = inflateInit(&d_stream);
  1.1224 +
  1.1225 +	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
  1.1226 +		{
  1.1227 +		d_stream.avail_in = 0;
  1.1228 +		d_stream.avail_out = 1; /* force small buffers */
  1.1229 +		err = inflate(&d_stream, Z_NO_FLUSH);
  1.1230 +		if (err == Z_STREAM_ERROR) break;
  1.1231 +		}
  1.1232 +	//inflate() should normally be called until it returns Z_STREAM_END 
  1.1233 +
  1.1234 +	err = inflateEnd(&d_stream);
  1.1235 +
  1.1236 +	if (err != Z_OK)  
  1.1237 +		{
  1.1238 +		res = KErrGeneral;     			
  1.1239 +		} 
  1.1240 +	else
  1.1241 +		{
  1.1242 +		res=KErrNone ;
  1.1243 +		}
  1.1244 +	free(compr);
  1.1245 +	free(uncompr);
  1.1246 +	return res;
  1.1247 +	}
  1.1248 +
  1.1249 +/**
  1.1250 + * Function Name : TestInflate_fail1
  1.1251 + * TestCase Description: 1. Compress the sample data using deflate
  1.1252 + *						2. Call inflateInit to initialize internal stream state for decompression
  1.1253 + *						3. Pass Z_NULL to inflate
  1.1254 + * Return Value: Z_STREAM_ERROR
  1.1255 + */  
  1.1256 +TInt CTestZlib::TestInflate_fail2()
  1.1257 +	{
  1.1258 +	TInt res = KErrNone ;
  1.1259 +	Byte *compr, *uncompr;
  1.1260 +	uLong comprLen = 20*sizeof(int); 
  1.1261 +	uLong uncomprLen = comprLen;
  1.1262 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.1263 +	if (compr == Z_NULL)
  1.1264 +		{
  1.1265 +		return KErrNoMemory;
  1.1266 +		}
  1.1267 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1268 +	if (uncompr == Z_NULL) 
  1.1269 +		{
  1.1270 +		free(compr);
  1.1271 +		return KErrNoMemory;
  1.1272 +		}
  1.1273 +	res = Test_deflate(compr, comprLen);
  1.1274 +	if(res<0)
  1.1275 +		{
  1.1276 +		free(compr);
  1.1277 +		free(uncompr);
  1.1278 +		return KErrNoMemory;	
  1.1279 +		}
  1.1280 +
  1.1281 +	int err;
  1.1282 +	z_stream d_stream; /* decompression stream */
  1.1283 +
  1.1284 +	strcpy((char*)uncompr, "garbage");
  1.1285 +
  1.1286 +	d_stream.zalloc = (alloc_func)0;
  1.1287 +	d_stream.zfree = (free_func)0;
  1.1288 +	d_stream.opaque = (voidpf)0;
  1.1289 +
  1.1290 +	d_stream.next_in  = compr;
  1.1291 +	d_stream.avail_in = 0;
  1.1292 +	d_stream.next_out = uncompr;
  1.1293 +
  1.1294 +	err = inflateInit(&d_stream);
  1.1295 +
  1.1296 +	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) 
  1.1297 +		{
  1.1298 +		d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
  1.1299 +		err = inflate(NULL, Z_NO_FLUSH);
  1.1300 +		if (err == Z_STREAM_ERROR) break;      
  1.1301 +		}
  1.1302 +	//inflate() should normally be called until it returns Z_STREAM_END 
  1.1303 +	err = inflateEnd(&d_stream);
  1.1304 +
  1.1305 +	if (err != Z_OK)  
  1.1306 +		{
  1.1307 +		res = KErrGeneral;     			
  1.1308 +		} 
  1.1309 +	else
  1.1310 +		{
  1.1311 +		res=KErrNone ;
  1.1312 +		}
  1.1313 +	free(compr);
  1.1314 +	free(uncompr);
  1.1315 +	return res;
  1.1316 +	}
  1.1317 +
  1.1318 +/**
  1.1319 + * Function Name : TestInflate_fail3
  1.1320 + * TestCase Description: 1. Compress the sample data using deflate
  1.1321 + *						2. Call inflateInit to initialize internal stream state for decompression
  1.1322 + *						3. Set avail_out = 0 and call inflate with necessary valid arguments
  1.1323 + * Return Value: Z_STREAM_ERROR
  1.1324 + */    
  1.1325 +TInt CTestZlib::TestInflate_fail3()
  1.1326 +	{
  1.1327 +	TInt res = KErrNone ;
  1.1328 +	Byte *compr, *uncompr;
  1.1329 +	uLong comprLen = 20*sizeof(int); 
  1.1330 +	uLong uncomprLen = comprLen;
  1.1331 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.1332 +	if (compr == Z_NULL)
  1.1333 +		{
  1.1334 +		return KErrNoMemory;
  1.1335 +		}
  1.1336 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1337 +	if (uncompr == Z_NULL) 
  1.1338 +		{
  1.1339 +		free(compr);
  1.1340 +		return KErrNoMemory;
  1.1341 +		}
  1.1342 +	res = Test_deflate(compr, comprLen);
  1.1343 +	if(res<0)
  1.1344 +		{
  1.1345 +		free(compr);
  1.1346 +		free(uncompr);
  1.1347 +		return KErrNoMemory;	
  1.1348 +		}
  1.1349 +
  1.1350 +	int err;
  1.1351 +	z_stream d_stream; /* decompression stream */
  1.1352 +
  1.1353 +	strcpy((char*)uncompr, "garbage");
  1.1354 +
  1.1355 +	d_stream.zalloc = (alloc_func)0;
  1.1356 +	d_stream.zfree = (free_func)0;
  1.1357 +	d_stream.opaque = (voidpf)0;
  1.1358 +
  1.1359 +	d_stream.next_in  = NULL;
  1.1360 +	d_stream.avail_in = 0;
  1.1361 +	d_stream.next_out = uncompr;
  1.1362 +
  1.1363 +	err = inflateInit(&d_stream);
  1.1364 +
  1.1365 +	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
  1.1366 +		{
  1.1367 +		d_stream.avail_in = 1;
  1.1368 +		d_stream.avail_out = 0; /* force small buffers */
  1.1369 +		err = inflate(&d_stream, Z_NO_FLUSH);
  1.1370 +		if (err == Z_STREAM_ERROR) break;
  1.1371 +		}
  1.1372 +	//inflate() should normally be called until it returns Z_STREAM_END 
  1.1373 +
  1.1374 +	err = inflateEnd(&d_stream);
  1.1375 +
  1.1376 +	if (err != Z_OK)  
  1.1377 +		{
  1.1378 +		res = KErrGeneral;     			
  1.1379 +		} 
  1.1380 +	else
  1.1381 +		{
  1.1382 +		res=KErrNone ;
  1.1383 +		}
  1.1384 +	free(compr);
  1.1385 +	free(uncompr);
  1.1386 +	return res;
  1.1387 +	}
  1.1388 +
  1.1389 +/**
  1.1390 + * Function Name : test_compress_positive
  1.1391 + * TestCase Description: This is a global function used by many test functions
  1.1392 + */ 
  1.1393 +TInt test_compress_positive(Byte * compr,uLong comprLen,Byte * /*uncompr*/,uLong /*uncomprLen*/)
  1.1394 +	{
  1.1395 +	TInt res = KErrNone ;
  1.1396 +	int err;
  1.1397 +	uLong len = (uLong)strlen(hello)+1;
  1.1398 +
  1.1399 +	err = compress(compr, &comprLen, (const Bytef*)hello, len);
  1.1400 +	if(err < 0)
  1.1401 +		{  	
  1.1402 +		res = KErrNoMemory;
  1.1403 +		}
  1.1404 +
  1.1405 +	if(err == 0)
  1.1406 +		{  	
  1.1407 +		res = KErrNone ;
  1.1408 +		} 
  1.1409 +	else
  1.1410 +		{    	
  1.1411 +		res = KErrGeneral;
  1.1412 +		}   
  1.1413 +	return res;
  1.1414 +	}
  1.1415 +
  1.1416 +/**
  1.1417 + * Function Name : test_inflateend_positive
  1.1418 + * TestCase Description: This is a global function used by many test functions
  1.1419 + */ 
  1.1420 +TInt test_inflateend_positive(Byte * compr,uLong comprLen,Byte * uncompr,uLong uncomprLen)
  1.1421 +	{ 
  1.1422 +	TInt res = KErrNone ;
  1.1423 +	int err;
  1.1424 +	z_stream d_stream; // decompression stream
  1.1425 +
  1.1426 +	strcpy((char*)uncompr, "garbage");
  1.1427 +
  1.1428 +	d_stream.zalloc = (alloc_func)0;
  1.1429 +	d_stream.zfree = (free_func)0;
  1.1430 +	d_stream.opaque = (voidpf)0;
  1.1431 +
  1.1432 +	d_stream.next_in  = compr;
  1.1433 +	d_stream.avail_in = 0;
  1.1434 +	d_stream.next_out = uncompr;
  1.1435 +
  1.1436 +	err = inflateInit(&d_stream);
  1.1437 +	if(err <0)
  1.1438 +		{
  1.1439 +		return KErrNoMemory;
  1.1440 +		}
  1.1441 +
  1.1442 +	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
  1.1443 +		{
  1.1444 +		d_stream.avail_in = d_stream.avail_out = 1; // force small buffers
  1.1445 +		err = inflate(&d_stream, Z_NO_FLUSH);
  1.1446 +		if (err == Z_STREAM_END) break;
  1.1447 +		if(err<0) break;
  1.1448 +		}
  1.1449 +
  1.1450 +	err = inflateEnd(&d_stream);
  1.1451 +	if (err != Z_OK)  
  1.1452 +		{
  1.1453 +		res = KErrGeneral;     			
  1.1454 +		} 
  1.1455 +	else
  1.1456 +		{
  1.1457 +		res=KErrNone ;
  1.1458 +		}
  1.1459 +	return res;
  1.1460 +	}
  1.1461 +
  1.1462 +
  1.1463 +/**
  1.1464 + * Function Name : TestInflateend
  1.1465 + * TestCase Description: 1.	Compress the sample data using deflate
  1.1466 + *						2.	inflate to decompress the data
  1.1467 + *						3.	inflateEnd
  1.1468 + * Return Value: Z_OK
  1.1469 + */
  1.1470 +TInt CTestZlib::TestInflateend()
  1.1471 +	{
  1.1472 +	TInt res = KErrNone ;
  1.1473 +	Byte *compr, *uncompr;
  1.1474 +	uLong comprLen = 20*sizeof(int); 
  1.1475 +	uLong uncomprLen = comprLen;
  1.1476 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.1477 +	if (compr == Z_NULL)
  1.1478 +		{
  1.1479 +		return KErrNoMemory;
  1.1480 +		}
  1.1481 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1482 +	if (uncompr == Z_NULL) 
  1.1483 +		{
  1.1484 +		free(compr);
  1.1485 +		return KErrNoMemory;
  1.1486 +		}
  1.1487 +	res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  1.1488 +	if(res<0)
  1.1489 +		{
  1.1490 +		free(compr);
  1.1491 +		free(uncompr);
  1.1492 +		return KErrNoMemory;	
  1.1493 +		}
  1.1494 +	res = Test_deflate(compr, comprLen);
  1.1495 +	if(res<0)
  1.1496 +		{
  1.1497 +		free(compr);
  1.1498 +		free(uncompr);
  1.1499 +		return KErrNoMemory;	
  1.1500 +		}
  1.1501 +	res = test_inflateend_positive(compr, comprLen, uncompr, uncomprLen);
  1.1502 +	if(res <0)    
  1.1503 +		{
  1.1504 +		free(compr);
  1.1505 +		free(uncompr);
  1.1506 +		return res;
  1.1507 +		}
  1.1508 +	else if(res==0)
  1.1509 +		{ 
  1.1510 +		res = KErrNone;    
  1.1511 +		}
  1.1512 +	else
  1.1513 +		{    
  1.1514 +		res = KErrGeneral;            
  1.1515 +		} 
  1.1516 +	free(compr);
  1.1517 +	free(uncompr);
  1.1518 +	return res;
  1.1519 +	}
  1.1520 +
  1.1521 +/**
  1.1522 + * Function Name : TestInflateend_fail
  1.1523 + * TestCase Description: 1.	Compress the sample data using deflate
  1.1524 + *						2.	inflate to decompress the data
  1.1525 + *						3.	Pass Z_NULL as argument to inflateEnd 
  1.1526 + * Return Value: Z_STREAM_ERROR
  1.1527 + */ 
  1.1528 +TInt CTestZlib::TestInflateend_fail()
  1.1529 +	{
  1.1530 +	TInt res = KErrNone ;
  1.1531 +	Byte *compr, *uncompr;
  1.1532 +	uLong comprLen = 20*sizeof(int); 
  1.1533 +	uLong uncomprLen = comprLen;
  1.1534 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.1535 +	if (compr == Z_NULL)
  1.1536 +		{
  1.1537 +		return KErrNoMemory;
  1.1538 +		}
  1.1539 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1540 +	if (uncompr == Z_NULL) 
  1.1541 +		{
  1.1542 +		free(compr);
  1.1543 +		return KErrNoMemory;
  1.1544 +		}
  1.1545 +	res=test_compress(compr, comprLen, uncompr, uncomprLen);
  1.1546 +	if(res<0)
  1.1547 +		{
  1.1548 +		free(compr);
  1.1549 +		free(uncompr);
  1.1550 +		return KErrNoMemory;	
  1.1551 +		}
  1.1552 +	res = Test_deflate(compr, comprLen);
  1.1553 +	if(res<0)
  1.1554 +		{
  1.1555 +		free(compr);
  1.1556 +		free(uncompr);
  1.1557 +		return KErrNoMemory;	
  1.1558 +		}
  1.1559 +	int ret=  inflateEnd(NULL);
  1.1560 +	if(ret==0)
  1.1561 +		{
  1.1562 +		res = KErrGeneral;    	
  1.1563 +		}
  1.1564 +	else
  1.1565 +		{    	
  1.1566 +		res = KErrNone;
  1.1567 +		}   
  1.1568 +	free(compr);
  1.1569 +	free(uncompr);
  1.1570 +	return res;
  1.1571 +	}
  1.1572 +
  1.1573 +/**
  1.1574 + * Function Name : TestInflateReset
  1.1575 + * TestCase Description: 1. Compress the sample data using deflate
  1.1576 + *						2. Call inflateInit to initialize internal stream state for decompression
  1.1577 + *						3. Call inflateReset with valid arguments 
  1.1578 + * Return Value: Z_OK
  1.1579 + */  
  1.1580 +TInt CTestZlib::TestInflateReset()
  1.1581 +	{  
  1.1582 +	TInt res=KErrNone;
  1.1583 +	z_stream d_stream; /* decompression stream */
  1.1584 +	const char * version;
  1.1585 +	d_stream.zalloc = (alloc_func)0;
  1.1586 +	d_stream.zfree = (free_func)0;
  1.1587 +	d_stream.opaque = (voidpf)0;
  1.1588 +
  1.1589 +	Byte *compr, *uncompr;
  1.1590 +	uLong comprLen = 20*sizeof(int); 
  1.1591 +	uLong uncomprLen = comprLen;
  1.1592 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.1593 +	if (compr == Z_NULL)
  1.1594 +		{
  1.1595 +		return KErrNoMemory;
  1.1596 +		}
  1.1597 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1598 +	if (uncompr == Z_NULL) 
  1.1599 +		{
  1.1600 +		free(compr);
  1.1601 +		return KErrNoMemory;
  1.1602 +		}
  1.1603 +
  1.1604 +	res = Test_deflate(compr, comprLen);
  1.1605 +	if(res<0)
  1.1606 +		{
  1.1607 +		free(compr);
  1.1608 +		free(uncompr);
  1.1609 +		return KErrNoMemory;	
  1.1610 +		}
  1.1611 +	d_stream.next_in  = compr;
  1.1612 +	d_stream.avail_in = 0;
  1.1613 +	d_stream.next_out = uncompr;
  1.1614 +	version=zlibVersion();
  1.1615 +	int err;
  1.1616 +	err = inflateInit_(&d_stream,(char*)version, sizeof(d_stream));
  1.1617 +	if(err<0)
  1.1618 +		{
  1.1619 +		free(compr);
  1.1620 +		free(uncompr);
  1.1621 +		return KErrNoMemory;	
  1.1622 +		}
  1.1623 +
  1.1624 +	err=inflateReset(&d_stream);
  1.1625 +	if(err<0)
  1.1626 +		{
  1.1627 +		inflateEnd(&d_stream);
  1.1628 +		free(compr);
  1.1629 +		free(uncompr);
  1.1630 +		return KErrNoMemory;	
  1.1631 +		}
  1.1632 +	if(err!=0)
  1.1633 +		{
  1.1634 +		res=KErrGeneral;
  1.1635 +		}
  1.1636 +	free(compr);
  1.1637 +	free(uncompr);
  1.1638 +	res=inflateEnd(&d_stream);
  1.1639 +	return res;
  1.1640 +	}
  1.1641 +
  1.1642 +
  1.1643 +/**
  1.1644 + * Function Name : TestInflateResetfail1
  1.1645 + * TestCase Description: 1. Compress the sample data using deflate
  1.1646 + *						2. Call inflateInit to initialize internal stream state for decompression
  1.1647 + *						3. Pass Z_NULL as argument to inflateReset 
  1.1648 + * Return Value: Z_STREAM_ERROR
  1.1649 + */   
  1.1650 +TInt CTestZlib::TestInflateResetfail1()
  1.1651 +	{
  1.1652 +	TInt res=KErrNone;
  1.1653 +	z_stream d_stream; /* decompression stream */
  1.1654 +	const char * version;
  1.1655 +	d_stream.zalloc = (alloc_func)0;
  1.1656 +	d_stream.zfree = (free_func)0;
  1.1657 +	d_stream.opaque = (voidpf)0;
  1.1658 +
  1.1659 +	Byte *compr, *uncompr;
  1.1660 +	uLong comprLen = 20*sizeof(int); 
  1.1661 +	uLong uncomprLen = comprLen;
  1.1662 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.1663 +	if (compr == Z_NULL)
  1.1664 +		{
  1.1665 +		return KErrNoMemory;
  1.1666 +		}
  1.1667 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1668 +	if (uncompr == Z_NULL) 
  1.1669 +		{
  1.1670 +		free(compr);
  1.1671 +		return KErrNoMemory;
  1.1672 +		}
  1.1673 +
  1.1674 +	res = Test_deflate(compr, comprLen);
  1.1675 +	if(res<0)
  1.1676 +		{
  1.1677 +		free(compr);
  1.1678 +		free(uncompr);
  1.1679 +		return KErrNoMemory;	
  1.1680 +		}
  1.1681 +	d_stream.next_in  = compr;
  1.1682 +	d_stream.avail_in = 0;
  1.1683 +	d_stream.next_out = uncompr;
  1.1684 +	version=zlibVersion();
  1.1685 +	inflateInit_(&d_stream,(char*)version, sizeof(d_stream));
  1.1686 +	res=inflateReset(NULL);
  1.1687 +	if(res!=Z_STREAM_ERROR)
  1.1688 +		{
  1.1689 +		res=KErrGeneral;
  1.1690 +		}
  1.1691 +	res=inflateEnd(&d_stream);
  1.1692 +	if(res!=0)
  1.1693 +		{
  1.1694 +		res=KErrGeneral;
  1.1695 +		}
  1.1696 +	free(compr);
  1.1697 +	free(uncompr);
  1.1698 +	return res;
  1.1699 +	}
  1.1700 +
  1.1701 +/**
  1.1702 + * Function Name : TestInflateInit2_
  1.1703 + * TestCase Description: Test inflateInit2_
  1.1704 + * Return Value: Z_OK
  1.1705 + */     
  1.1706 +TInt CTestZlib::TestInflateInit2_()
  1.1707 +	{ 
  1.1708 +	TInt res = KErrNone ;
  1.1709 +	z_stream d_stream; // decompression stream
  1.1710 +	const char * version;
  1.1711 +	d_stream.zalloc = (alloc_func)0;
  1.1712 +	d_stream.zfree = (free_func)0;
  1.1713 +	d_stream.opaque = (voidpf)0;
  1.1714 +
  1.1715 +	version = zlibVersion();
  1.1716 +	TInt ret =  inflateInit2_(&d_stream,15,version, sizeof(d_stream));
  1.1717 +	if(ret==0)
  1.1718 +		{ 
  1.1719 +		res = KErrNone;
  1.1720 +		}
  1.1721 +	else
  1.1722 +		{     	
  1.1723 +		return ret; 
  1.1724 +		} 
  1.1725 +	inflateEnd(&d_stream);
  1.1726 +	return res;       
  1.1727 +	}
  1.1728 +
  1.1729 +/**
  1.1730 + * Function Name : TestInflateInit_
  1.1731 + * TestCase Description: Test inflateInit_
  1.1732 + * Return Value: Z_OK
  1.1733 + */
  1.1734 +TInt CTestZlib::TestInflateInit_()
  1.1735 +	{ 
  1.1736 +	TInt res = KErrNone ;
  1.1737 +	z_stream d_stream; 
  1.1738 +	const char * version;
  1.1739 +	d_stream.zalloc = (alloc_func)0;
  1.1740 +	d_stream.zfree = (free_func)0;
  1.1741 +	d_stream.opaque = (voidpf)0;
  1.1742 +
  1.1743 +	Byte *compr, *uncompr;
  1.1744 +	uLong comprLen = 20*sizeof(int); 
  1.1745 +	uLong uncomprLen = comprLen;
  1.1746 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.1747 +	if (compr == Z_NULL)
  1.1748 +		{
  1.1749 +		return KErrNoMemory;
  1.1750 +		}
  1.1751 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1752 +	if (uncompr == Z_NULL) 
  1.1753 +		{
  1.1754 +		free(compr);
  1.1755 +		return KErrNoMemory;
  1.1756 +		}
  1.1757 +	res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  1.1758 +	if(res<0)
  1.1759 +		{
  1.1760 +		free(compr);
  1.1761 +		free(uncompr);
  1.1762 +		return KErrNoMemory;	
  1.1763 +		}
  1.1764 +
  1.1765 +	res = Test_deflate(compr, comprLen);
  1.1766 +	if(res<0)
  1.1767 +		{
  1.1768 +		free(compr);
  1.1769 +		free(uncompr);
  1.1770 +		return KErrNoMemory;	
  1.1771 +		}
  1.1772 +	d_stream.next_in  = compr;
  1.1773 +	d_stream.avail_in = 0;
  1.1774 +	d_stream.next_out = uncompr;
  1.1775 +	version=zlibVersion();
  1.1776 +	int ret = inflateInit_(&d_stream,(char*)version, sizeof(d_stream));
  1.1777 +	if(ret==0)
  1.1778 +		{ 
  1.1779 +		res = KErrNone;
  1.1780 +		}
  1.1781 +	else
  1.1782 +		{    
  1.1783 +		res = KErrGeneral;   
  1.1784 +		}    
  1.1785 +	inflateEnd(&d_stream);
  1.1786 +	free(compr);
  1.1787 +	free(uncompr);
  1.1788 +	return res;   
  1.1789 +	}
  1.1790 +
  1.1791 +/**
  1.1792 + * Function Name : TestInflateInit2_negative
  1.1793 + * TestCase Description: 1. Compress the sample data using deflate
  1.1794 + *						2. inflateInit2_ with stream size less than required
  1.1795 + * Return Value: Z_MEM_ERROR
  1.1796 + */  
  1.1797 +TInt CTestZlib::TestInflateInit2_negative()
  1.1798 +	{ 
  1.1799 +	TInt res = KErrNone ;
  1.1800 +	z_stream d_stream; // decompression stream
  1.1801 +	const char * version;
  1.1802 +	d_stream.zalloc = (alloc_func)0;
  1.1803 +	d_stream.zfree = (free_func)0;
  1.1804 +	d_stream.opaque = (voidpf)0;
  1.1805 +
  1.1806 +	Byte *compr, *uncompr;
  1.1807 +	uLong comprLen = 20*sizeof(int); // don't overflow on MSDOS
  1.1808 +	uLong uncomprLen = comprLen;
  1.1809 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.1810 +	if (compr == Z_NULL)
  1.1811 +		{
  1.1812 +		return KErrNoMemory;
  1.1813 +		}
  1.1814 +	uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1815 +	if (uncompr == Z_NULL) 
  1.1816 +		{
  1.1817 +		free(compr);
  1.1818 +		return KErrNoMemory;
  1.1819 +		}
  1.1820 +
  1.1821 +	res = Test_deflate(compr, comprLen);
  1.1822 +	if(res<0)
  1.1823 +		{
  1.1824 +		free(compr);
  1.1825 +		free(uncompr);
  1.1826 +		return KErrNoMemory;	
  1.1827 +		}
  1.1828 +	d_stream.next_in  = compr;
  1.1829 +	d_stream.avail_in = 0;
  1.1830 +	d_stream.next_out = uncompr;
  1.1831 +	version=zlibVersion();   
  1.1832 +	int ret =  inflateInit2_(&d_stream, 15, version, sizeof(d_stream)-5);
  1.1833 +	if(ret==0)
  1.1834 +		{
  1.1835 +		res = KErrGeneral;    	
  1.1836 +		}
  1.1837 +	else
  1.1838 +		{    	
  1.1839 +		res = KErrNone;
  1.1840 +		}      
  1.1841 +	free(compr);
  1.1842 +	free(uncompr);
  1.1843 +	// inflateEnd(&d_stream);
  1.1844 +	return res;       
  1.1845 +	}
  1.1846 +
  1.1847 +/**
  1.1848 + * Function Name : TestInflateInit_negative
  1.1849 + * TestCase Description: 1. Compress the sample data using deflate
  1.1850 + *						2. Call inflateInit_ with stream size less than required
  1.1851 + * Return Value: Z_MEM_ERROR
  1.1852 + */ 
  1.1853 +TInt CTestZlib::TestInflateInit_negative()
  1.1854 +	{ 
  1.1855 +	TInt res = KErrNone ;
  1.1856 +	z_stream d_stream; // decompression stream 
  1.1857 +	const char * version;
  1.1858 +	d_stream.zalloc = (alloc_func)0;
  1.1859 +	d_stream.zfree = (free_func)0;
  1.1860 +	d_stream.opaque = (voidpf)0;
  1.1861 +
  1.1862 +	Byte *compr, *uncompr;
  1.1863 +	uLong comprLen = 20*sizeof(int); 
  1.1864 +	uLong uncomprLen = comprLen;
  1.1865 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.1866 +	if (compr == Z_NULL)
  1.1867 +		{
  1.1868 +		return KErrNoMemory;
  1.1869 +		}
  1.1870 +	uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1871 +	if (uncompr == Z_NULL) 
  1.1872 +		{
  1.1873 +		free(compr);
  1.1874 +		return KErrNoMemory;
  1.1875 +		}
  1.1876 +	res = Test_deflate(compr, comprLen);
  1.1877 +	if(res<0)
  1.1878 +		{
  1.1879 +		free(compr);
  1.1880 +		free(uncompr);
  1.1881 +		return KErrNoMemory;	
  1.1882 +		}
  1.1883 +	d_stream.next_in  = compr;
  1.1884 +	d_stream.avail_in = 0;
  1.1885 +	d_stream.next_out = uncompr;
  1.1886 +	version=zlibVersion();
  1.1887 +	int ret = inflateInit_(&d_stream,(char*)version, sizeof(d_stream) - 5);
  1.1888 +	if(ret==0)
  1.1889 +		{
  1.1890 +		res = KErrGeneral;    	
  1.1891 +		}
  1.1892 +	else
  1.1893 +		{    	
  1.1894 +		res = KErrNone;
  1.1895 +		}   
  1.1896 +	// inflateEnd(&d_stream); 
  1.1897 +	free(compr);
  1.1898 +	free(uncompr);
  1.1899 +	return res;    
  1.1900 +	}
  1.1901 +
  1.1902 +/**
  1.1903 + * Function Name : TestInflateInit2_versioncheck
  1.1904 + * TestCase Description: 1. Compress the sample data using deflate
  1.1905 + *						2. inflateInit2_ with valid zlib version as argument
  1.1906 + * Return Value: Z_OK
  1.1907 + */   
  1.1908 +TInt CTestZlib::TestInflateInit2_versioncheck()
  1.1909 +	{ 
  1.1910 +	TInt res = KErrNone ;
  1.1911 +	z_stream d_stream; // decompression stream
  1.1912 +	const char * version;
  1.1913 +	d_stream.zalloc = (alloc_func)0;
  1.1914 +	d_stream.zfree = (free_func)0;
  1.1915 +	d_stream.opaque = (voidpf)0;
  1.1916 +
  1.1917 +	Byte *compr, *uncompr;
  1.1918 +	uLong comprLen = 20*sizeof(int);
  1.1919 +	uLong uncomprLen = comprLen;
  1.1920 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.1921 +	if (compr == Z_NULL)
  1.1922 +		{
  1.1923 +		return KErrNoMemory;
  1.1924 +		}
  1.1925 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1926 +	if (uncompr == Z_NULL) 
  1.1927 +		{
  1.1928 +		free(compr);
  1.1929 +		return KErrNoMemory;
  1.1930 +		}
  1.1931 +
  1.1932 +	res = Test_deflate(compr, comprLen);
  1.1933 +	if(res<0)
  1.1934 +		{
  1.1935 +		free(compr);
  1.1936 +		free(uncompr);
  1.1937 +		return KErrNoMemory;	
  1.1938 +		}
  1.1939 +	d_stream.next_in  = compr;
  1.1940 +	d_stream.avail_in = 0;
  1.1941 +	d_stream.next_out = uncompr;
  1.1942 +	version=zlibVersion();
  1.1943 +	INFO_PRINTF2(_L("Version : %d"),version);
  1.1944 +	int ret =  inflateInit2_(&d_stream, 15,  "1.2.4", sizeof(d_stream)-5);
  1.1945 +	if(ret==0)
  1.1946 +		{
  1.1947 +		res = KErrGeneral;    	
  1.1948 +		}
  1.1949 +	else
  1.1950 +		{    	
  1.1951 +		res = KErrNone;
  1.1952 +		}  
  1.1953 +	free(compr);
  1.1954 +	free(uncompr); 
  1.1955 +	return res;      
  1.1956 +	}
  1.1957 +
  1.1958 +/**
  1.1959 + * Function Name : TestInflateInit_versioncheck
  1.1960 + * TestCase Description: 1. Compress the sample data using deflate
  1.1961 + *						2. inflateInit_ with valid zlib version as argument
  1.1962 + * Return Value: Z_OK
  1.1963 + */ 
  1.1964 +TInt CTestZlib::TestInflateInit_versioncheck()
  1.1965 +	{	 
  1.1966 +	TInt res = KErrNone ;
  1.1967 +
  1.1968 +	z_stream d_stream; // decompression stream
  1.1969 +	const char * version;
  1.1970 +	d_stream.zalloc = (alloc_func)0;
  1.1971 +	d_stream.zfree = (free_func)0;
  1.1972 +	d_stream.opaque = (voidpf)0;
  1.1973 +
  1.1974 +	Byte *compr, *uncompr;
  1.1975 +	uLong comprLen = 20*sizeof(int); // don't overflow on MSDOS
  1.1976 +	uLong uncomprLen = comprLen;
  1.1977 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.1978 +	if (compr == Z_NULL)
  1.1979 +		{
  1.1980 +		return KErrNoMemory;
  1.1981 +		}
  1.1982 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1983 +	if (uncompr == Z_NULL) 
  1.1984 +		{
  1.1985 +		free(compr);
  1.1986 +		return KErrNoMemory;
  1.1987 +		}
  1.1988 +	res = Test_deflate(compr, comprLen);
  1.1989 +	if(res<0)
  1.1990 +		{
  1.1991 +		free(compr);
  1.1992 +		free(uncompr);
  1.1993 +		return KErrNoMemory;	
  1.1994 +		}
  1.1995 +	d_stream.next_in  = compr;
  1.1996 +	d_stream.avail_in = 0;
  1.1997 +	d_stream.next_out = uncompr;
  1.1998 +	version=zlibVersion();
  1.1999 +	INFO_PRINTF2(_L("Version : %d"),version);
  1.2000 +	int ret =  inflateInit_(&d_stream,(char*)  "1.2.4", sizeof(d_stream) - 5);
  1.2001 +	if(ret==0)
  1.2002 +		{
  1.2003 +		res = KErrGeneral;    	
  1.2004 +		}
  1.2005 +	else
  1.2006 +		{    	
  1.2007 +		res = KErrNone;
  1.2008 +		}   
  1.2009 +	free(compr);
  1.2010 +	free(uncompr);
  1.2011 +	return res;   
  1.2012 +	}
  1.2013 +
  1.2014 +/**
  1.2015 + * Function Name : TestCompress
  1.2016 + * TestCase Description: Test compress()
  1.2017 + * Return Value: Z_OK
  1.2018 + */  
  1.2019 +TInt CTestZlib::TestCompress()
  1.2020 +	{ 
  1.2021 +	TInt res = KErrNone ;
  1.2022 +	Byte *compr, *uncompr;
  1.2023 +	uLong comprLen = 20*sizeof(int); 
  1.2024 +	uLong uncomprLen = comprLen;
  1.2025 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.2026 +	if (compr == Z_NULL)
  1.2027 +		{
  1.2028 +		return KErrNoMemory;
  1.2029 +		}
  1.2030 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.2031 +	if (uncompr == Z_NULL) 
  1.2032 +		{
  1.2033 +		free(compr);
  1.2034 +		return KErrNoMemory;
  1.2035 +		}
  1.2036 +	res=test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  1.2037 +	free(compr);
  1.2038 +	free(uncompr);
  1.2039 +	return res;
  1.2040 +	}
  1.2041 +
  1.2042 +/**
  1.2043 + * Function Name : test_compress_negative
  1.2044 + * TestCase Description: This is a global function used by many test functions
  1.2045 + */
  1.2046 +TInt test_compress_negative(Byte * compr,uLong comprLen,Byte * /*uncompr*/,uLong /*uncomprLen*/)
  1.2047 +	{
  1.2048 +	TInt res = KErrNone ;
  1.2049 +	int err;
  1.2050 +	uLong len = (uLong)strlen(hello)+1;
  1.2051 +	err = compress(compr, &comprLen, (const Bytef*)hello, len);
  1.2052 +	if(err == 0)
  1.2053 +		{  
  1.2054 +		res = KErrGeneral;   
  1.2055 +		} 
  1.2056 +	else
  1.2057 +		{    	
  1.2058 +		res =    KErrNone ;
  1.2059 +		}   
  1.2060 +	return res;
  1.2061 +	}
  1.2062 +
  1.2063 +/**
  1.2064 + * Function Name : TestCompress_negative
  1.2065 + * TestCase Description: Call compress with compression length less than required
  1.2066 + * Return Value: Z_BUF_ERROR
  1.2067 + */
  1.2068 +TInt CTestZlib::TestCompress_negative()
  1.2069 +	{
  1.2070 +	TInt res = KErrNone ;
  1.2071 +	Byte *compr, *uncompr;
  1.2072 +	uLong comprLen = 1*sizeof(int);
  1.2073 +	uLong uncomprLen = comprLen;
  1.2074 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.2075 +	if (compr == Z_NULL)
  1.2076 +		{
  1.2077 +		return KErrNoMemory;
  1.2078 +		}
  1.2079 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.2080 +	if (uncompr == Z_NULL) 
  1.2081 +		{
  1.2082 +		free(compr);
  1.2083 +		return KErrNoMemory;
  1.2084 +		}
  1.2085 +	res=test_compress_negative(compr, comprLen, uncompr, uncomprLen);
  1.2086 +	free(compr);
  1.2087 +	free(uncompr);
  1.2088 +	return res;
  1.2089 +	}
  1.2090 +
  1.2091 +/**
  1.2092 + * Function Name : TestCompress2_positive
  1.2093 + * TestCase Description: Test compress2 with valid arguments
  1.2094 + * Return Value: Z_OK
  1.2095 + */
  1.2096 +TInt CTestZlib::TestCompress2_positive()
  1.2097 +	{
  1.2098 +	TInt res = KErrNone ;
  1.2099 +	int err;
  1.2100 +	uLong len = (uLong)strlen(hello)+1;
  1.2101 +
  1.2102 +	Byte *compr, *uncompr;
  1.2103 +	uLong comprLen = 20*sizeof(int); 
  1.2104 +	uLong uncomprLen = comprLen;
  1.2105 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.2106 +	if (compr == Z_NULL)
  1.2107 +		{
  1.2108 +		return KErrNoMemory;
  1.2109 +		}
  1.2110 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.2111 +	if (uncompr == Z_NULL) 
  1.2112 +		{
  1.2113 +		free(compr);
  1.2114 +		return KErrNoMemory;
  1.2115 +		}
  1.2116 +
  1.2117 +	err=compress2(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);      
  1.2118 +
  1.2119 +	if(err == 0)
  1.2120 +		{  	
  1.2121 +		res = KErrNone ;
  1.2122 +		} 
  1.2123 +	else
  1.2124 +		{    	
  1.2125 +		res = KErrGeneral;
  1.2126 +		}   
  1.2127 +	free(compr);
  1.2128 +	free(uncompr);
  1.2129 +	return res;
  1.2130 +	}
  1.2131 +
  1.2132 +/**
  1.2133 + * Function Name : TestCompress2_negative
  1.2134 + * TestCase Description: Test compress2 with compression length less than required  
  1.2135 + * Return Value: Z_BUF_ERROR
  1.2136 + */
  1.2137 +TInt CTestZlib::TestCompress2_negative()
  1.2138 +	{
  1.2139 +	int err;
  1.2140 +	TInt res = KErrNone ;
  1.2141 +	uLong len = (uLong)strlen(hello)+1;
  1.2142 +	Byte *compr;
  1.2143 +	uLong comprLen = 20*sizeof(int); 
  1.2144 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.2145 +	if (compr == Z_NULL)
  1.2146 +		{
  1.2147 +		return KErrNoMemory;
  1.2148 +		}
  1.2149 +	err=compress2(compr, &comprLen, (const Bytef*)hello, len,14);   
  1.2150 +	if(err == 0)
  1.2151 +		{  
  1.2152 +		res = KErrGeneral;     
  1.2153 +		} 
  1.2154 +	else
  1.2155 +		{    	
  1.2156 +		res = KErrNone ;
  1.2157 +		}   
  1.2158 +	free(compr);
  1.2159 +	return res;
  1.2160 +	}
  1.2161 +
  1.2162 +
  1.2163 +/**
  1.2164 + * Function Name : test_compressbound
  1.2165 + * TestCase Description: This is a global function used by many test functions
  1.2166 + */
  1.2167 +TInt test_compressbound(Byte * compr,uLong comprLen)
  1.2168 +	{
  1.2169 +	TInt res = KErrNone ;
  1.2170 +	int err;
  1.2171 +	uLong sourceLen = (uLong)strlen(hello)+1;
  1.2172 +	err=compress(compr, &comprLen, (const Bytef*)hello, sourceLen);
  1.2173 +	if(err==0)
  1.2174 +		{    	
  1.2175 +		int x =  compressBound(sourceLen);
  1.2176 +		if(x > sourceLen)
  1.2177 +			{  	
  1.2178 +			res = KErrNone ;         
  1.2179 +			} 
  1.2180 +		else
  1.2181 +			{    	
  1.2182 +			res = KErrGeneral;     
  1.2183 +			}   
  1.2184 +		}
  1.2185 +	else
  1.2186 +		{
  1.2187 +		res = KErrGeneral;     
  1.2188 +		}
  1.2189 +	return res;
  1.2190 +	}
  1.2191 +
  1.2192 +/**
  1.2193 + * Function Name : TestCompressbound
  1.2194 + * TestCase Description: 1. Call compress with appropriate arguments
  1.2195 + *						2. Then verify the length of the compressed buffer using compressBound  
  1.2196 + * Return Value: Returns an upper bound on the compressed size after compression
  1.2197 + *				
  1.2198 + */
  1.2199 +TInt CTestZlib::TestCompressbound()
  1.2200 +	{     
  1.2201 +	TInt res = KErrNone ;
  1.2202 +	Byte *compr;
  1.2203 +	uLong comprLen =20*sizeof(int);
  1.2204 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.2205 +	if (compr == Z_NULL)
  1.2206 +		{
  1.2207 +		return KErrNoMemory;
  1.2208 +		}
  1.2209 +
  1.2210 +	res = test_compressbound(compr, comprLen);
  1.2211 +	free(compr);
  1.2212 +	return res;
  1.2213 +	}
  1.2214 +
  1.2215 +/**
  1.2216 + * Function Name : test_deflatebound
  1.2217 + * TestCase Description: This is a global function used by many test functions
  1.2218 + */
  1.2219 +TInt test_deflatebound(Bytef *dest,  uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
  1.2220 +	{	 
  1.2221 +	TInt res = KErrNone ;
  1.2222 +	int err;
  1.2223 +	z_stream stream;
  1.2224 +	stream.next_in = (Bytef*)source;
  1.2225 +	stream.avail_in = (uInt)sourceLen;
  1.2226 +	stream.next_out = dest;
  1.2227 +	stream.avail_out = (uInt)*destLen;
  1.2228 +	if ((uLong)stream.avail_out != *destLen) 
  1.2229 +		{
  1.2230 +		res = KErrGeneral; 
  1.2231 +		}
  1.2232 +	stream.zalloc = (alloc_func)0;
  1.2233 +	stream.zfree = (free_func)0;
  1.2234 +	stream.opaque = (voidpf)0;
  1.2235 +
  1.2236 +	err = deflateInit(&stream, level);
  1.2237 +	if (err == Z_OK) 
  1.2238 +		{
  1.2239 +		int y= deflateBound(&stream, sourceLen);
  1.2240 +		if(y > sourceLen)
  1.2241 +			{  
  1.2242 +			res = KErrNone ;
  1.2243 +			} 
  1.2244 +		else
  1.2245 +			{   	
  1.2246 +			res = KErrGeneral;      	
  1.2247 +			}   
  1.2248 +		}
  1.2249 +	else
  1.2250 +		{
  1.2251 +		res = KErrGeneral;      
  1.2252 +		return res;   
  1.2253 +		}    
  1.2254 +	err=deflateEnd(&stream);
  1.2255 +	if (err != Z_OK) 
  1.2256 +		{
  1.2257 +		res = KErrGeneral;      
  1.2258 +		}
  1.2259 +	return res;
  1.2260 +	}
  1.2261 +
  1.2262 +/**
  1.2263 + * Function Name : TestDeflatebound
  1.2264 + * TestCase Description: 1. Compress the sample data using deflate
  1.2265 + *						2. Then verify the length of the compressed buffer using deflateBound  
  1.2266 + * Return Value: Returns an upper bound on the compressed size after compression
  1.2267 + */
  1.2268 +TInt CTestZlib::TestDeflatebound()
  1.2269 +	{    
  1.2270 +	TInt res = KErrNone ;
  1.2271 +
  1.2272 +	uLong len = (uLong)strlen(hello)+1;
  1.2273 +	Byte *compr, *uncompr;
  1.2274 +	uLong comprLen = 20*sizeof(int); 
  1.2275 +	uLong uncomprLen = comprLen;
  1.2276 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.2277 +	if (compr == Z_NULL)
  1.2278 +		{
  1.2279 +		return KErrNoMemory;
  1.2280 +		}
  1.2281 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.2282 +	if(uncompr == Z_NULL) 
  1.2283 +		{
  1.2284 +		free(compr);
  1.2285 +		return KErrNoMemory;
  1.2286 +		}
  1.2287 +	res=test_deflatebound(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);   
  1.2288 +	free(compr);
  1.2289 +	free(uncompr);
  1.2290 +	return res;
  1.2291 +	}
  1.2292 +
  1.2293 +/**
  1.2294 + * Function Name : TestDeflateparams
  1.2295 + * TestCase Description: 1. deflateInit to initialize the internal stream state for compression
  1.2296 + *						2. deflateParams with valid compression level and strategy
  1.2297 + *						
  1.2298 + * Return Value: Z_OK
  1.2299 + */  
  1.2300 +TInt CTestZlib::TestDeflateparams()
  1.2301 +	{     
  1.2302 +	TInt res = KErrNone ;
  1.2303 +	z_stream c_stream; /* compression stream */
  1.2304 +	int err;
  1.2305 +	Byte * compr;
  1.2306 +	uLong comprLen = 20*sizeof(int); 
  1.2307 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.2308 +	if (compr == Z_NULL)
  1.2309 +		{
  1.2310 +		return KErrNoMemory;
  1.2311 +		}
  1.2312 +	uLong len = (uLong)strlen(hello)+1;
  1.2313 +	c_stream.zalloc = (alloc_func)0;
  1.2314 +	c_stream.zfree = (free_func)0;
  1.2315 +	c_stream.opaque = (voidpf)0;
  1.2316 +
  1.2317 +	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  1.2318 +	if(err <0)
  1.2319 +		{
  1.2320 +		free(compr);
  1.2321 +		return err;	
  1.2322 +		}
  1.2323 +	c_stream.next_in  = (Bytef*)hello;
  1.2324 +	c_stream.next_out = compr;
  1.2325 +
  1.2326 +	err= deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
  1.2327 +	if(err != 0)
  1.2328 +		{    	
  1.2329 +		res = KErrGeneral;
  1.2330 +		}
  1.2331 +	deflateEnd(&c_stream);
  1.2332 +	free(compr);
  1.2333 +	return res;
  1.2334 +	}
  1.2335 +
  1.2336 +/**
  1.2337 + * Function Name : TestDeflateparamsfail1
  1.2338 + * TestCase Description: 1. deflateInit to initialize the internal stream state for compression
  1.2339 + *						2. deflateParams with invalid compression level
  1.2340 + * Return Value: Z_STREAM_ERROR
  1.2341 + */  
  1.2342 +TInt CTestZlib::TestDeflateparamsfail1()
  1.2343 +	{     
  1.2344 +	TInt res = KErrNone ;
  1.2345 +	z_stream c_stream; /* compression stream */
  1.2346 +	int err;
  1.2347 +	Byte * compr;
  1.2348 +	uLong comprLen = 20*sizeof(int); 
  1.2349 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.2350 +	if (compr == Z_NULL)
  1.2351 +		{
  1.2352 +		return KErrNoMemory;
  1.2353 +		}
  1.2354 +
  1.2355 +	uLong len = (uLong)strlen(hello)+1;
  1.2356 +	c_stream.zalloc = (alloc_func)0;
  1.2357 +	c_stream.zfree = (free_func)0;
  1.2358 +	c_stream.opaque = (voidpf)0;
  1.2359 +
  1.2360 +	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  1.2361 +	if(err<0)
  1.2362 +		{
  1.2363 +		free(compr);
  1.2364 +		return err;	
  1.2365 +		}
  1.2366 +
  1.2367 +	c_stream.next_in = (Bytef*)hello;
  1.2368 +	c_stream.next_out = compr;
  1.2369 +
  1.2370 +	err= deflateParams(&c_stream, 12, Z_DEFAULT_STRATEGY);
  1.2371 +	if(err != 0)
  1.2372 +		{    	
  1.2373 +		res =  KErrNone;
  1.2374 +		}
  1.2375 +	deflateEnd(&c_stream);
  1.2376 +	free(compr);
  1.2377 +	return res;
  1.2378 +	}
  1.2379 +
  1.2380 +/**
  1.2381 + * Function Name : TestDeflateparamsfail2
  1.2382 + * TestCase Description: 1. deflateInit to initialize the internal stream state for compression
  1.2383 + *						2. Pass NULL stream as argument to deflateParams
  1.2384 + * Return Value: Z_STREAM_ERROR
  1.2385 + */ 
  1.2386 +TInt CTestZlib::TestDeflateparamsfail2()
  1.2387 +	{     
  1.2388 +	TInt res = KErrNone ;   
  1.2389 +	int err= deflateParams(NULL, 12, Z_DEFAULT_STRATEGY);
  1.2390 +	if(err != 0)
  1.2391 +		{    	
  1.2392 +		res =  	KErrNone;
  1.2393 +		}
  1.2394 +
  1.2395 +	return res;
  1.2396 +	}
  1.2397 +
  1.2398 +/**
  1.2399 + * Function Name : TestCrcinit
  1.2400 + * TestCase Description: Test crc32 with proper arguments
  1.2401 + * Return Value: KErrNone
  1.2402 + */   
  1.2403 +TInt CTestZlib::TestCrcinit()
  1.2404 +	{
  1.2405 +	TInt res = KErrNone ;
  1.2406 +	unsigned long j=0L;
  1.2407 +	long crc = crc32(j,0, 0);
  1.2408 +
  1.2409 +	if(crc==0)
  1.2410 +		{  
  1.2411 +		res = KErrNone ;
  1.2412 +		} 
  1.2413 +	else
  1.2414 +		{
  1.2415 +		res = KErrGeneral;      	
  1.2416 +		}   
  1.2417 +
  1.2418 +	return res; 
  1.2419 +	}
  1.2420 +
  1.2421 +/**
  1.2422 + * Function Name : TestCrc
  1.2423 + * TestCase Description: 1. Call crc32 with proper arguments
  1.2424 + *						2. Call crc32 with with one of the arguments as an updated crc generated from previous call to crc32
  1.2425 + * Return Value: KErrNone
  1.2426 + */    
  1.2427 +TInt CTestZlib::TestCrc()
  1.2428 +	{
  1.2429 +	TInt res = KErrNone ;
  1.2430 +	unsigned char  buffer[5]="1234";
  1.2431 +	unsigned int i=4;
  1.2432 +	unsigned long j=0L;
  1.2433 +
  1.2434 +	long crc1 = crc32(j,0, 0);
  1.2435 +
  1.2436 +	long crc = crc32(crc1, &buffer[0], i);
  1.2437 +
  1.2438 +	INFO_PRINTF2(_L("buf %x"),crc);
  1.2439 +
  1.2440 +	if(crc==(long)2615402659LL)
  1.2441 +		{  
  1.2442 +		res = KErrNone ;
  1.2443 +		} 
  1.2444 +	else
  1.2445 +		{
  1.2446 +		res = KErrGeneral;      	
  1.2447 +		}   
  1.2448 +
  1.2449 +	return res;           
  1.2450 +	}
  1.2451 +
  1.2452 +/**
  1.2453 + * Function Name : TestGet_crc_table
  1.2454 + * TestCase Description: Test get_crc_table
  1.2455 + * Return Value: KErrNone
  1.2456 + */    
  1.2457 +TInt CTestZlib::TestGet_crc_table()
  1.2458 +	{ 
  1.2459 +	TInt res = KErrNone ;
  1.2460 +	const unsigned long* pcrc_32_tab;
  1.2461 +
  1.2462 +	pcrc_32_tab = get_crc_table();
  1.2463 +
  1.2464 +	if(pcrc_32_tab)
  1.2465 +		{  
  1.2466 +		res = KErrNone ;
  1.2467 +		} 
  1.2468 +	else
  1.2469 +		{
  1.2470 +		res = KErrGeneral;      	
  1.2471 +		}   
  1.2472 +
  1.2473 +	return res;  
  1.2474 +	}
  1.2475 +
  1.2476 +/**
  1.2477 + * Function Name : TestDeflateInit_
  1.2478 + * TestCase Description: deflateInit_ with all valid arguments
  1.2479 + * Return Value: KErrNone
  1.2480 + */     
  1.2481 +TInt CTestZlib::TestDeflateInit_()
  1.2482 +	{
  1.2483 +	TInt res = KErrNone ;
  1.2484 +	z_stream stream;
  1.2485 +	int err;
  1.2486 +
  1.2487 +	uLong sourceLen = (uLong)strlen(hello)+1;
  1.2488 +	Byte *compr;
  1.2489 +	uLong comprLen = 10*sizeof(int); 
  1.2490 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.2491 +	if (compr == Z_NULL)
  1.2492 +		{
  1.2493 +		return KErrNoMemory;
  1.2494 +		}
  1.2495 +
  1.2496 +	stream.zalloc = (alloc_func)0;
  1.2497 +	stream.zfree = (free_func)0;
  1.2498 +	stream.opaque = (voidpf)0;
  1.2499 +
  1.2500 +	err= deflateInit_(&stream, Z_DEFAULT_COMPRESSION,  zlibVersion(), sizeof(z_stream));
  1.2501 +
  1.2502 +	if (err != Z_OK) 
  1.2503 +		{	 
  1.2504 +		free(compr);
  1.2505 +		res = KErrGeneral; 
  1.2506 +		return res;
  1.2507 +		} 
  1.2508 +	else  
  1.2509 +		{    	
  1.2510 +		res = KErrNone;
  1.2511 +		}   
  1.2512 +	deflateEnd(&stream);
  1.2513 +	free(compr);
  1.2514 +	return res;
  1.2515 +	}
  1.2516 +
  1.2517 +/**
  1.2518 + * Function Name : TestDeflateInit_level
  1.2519 + * TestCase Description: deflateInit_ with invalid compression level
  1.2520 + * Return Value: Z_STREAM_ERROR
  1.2521 + */     
  1.2522 +TInt CTestZlib::TestDeflateInit_level()
  1.2523 +	{
  1.2524 +	TInt res = KErrNone ;
  1.2525 +	z_stream stream;
  1.2526 +	int err;
  1.2527 +	uLong sourceLen = (uLong)strlen(hello)+1;
  1.2528 +	Byte *compr;
  1.2529 +	uLong comprLen = 10*sizeof(int); 
  1.2530 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.2531 +	if (compr == Z_NULL)
  1.2532 +		{
  1.2533 +		return KErrNoMemory;
  1.2534 +		}
  1.2535 +
  1.2536 +	stream.zalloc = (alloc_func)0;
  1.2537 +	stream.zfree = (free_func)0;
  1.2538 +	stream.opaque = (voidpf)0;
  1.2539 +
  1.2540 +	err= deflateInit_(&stream, 11,  zlibVersion(), sizeof(z_stream));
  1.2541 +
  1.2542 +	if (err != Z_OK) 
  1.2543 +		{
  1.2544 +		res = KErrNone;
  1.2545 +		} 
  1.2546 +	else  
  1.2547 +		{    	
  1.2548 +		res = KErrGeneral; 
  1.2549 +		}   
  1.2550 +
  1.2551 +	free(compr);
  1.2552 +	return res;
  1.2553 +	}
  1.2554 +
  1.2555 +
  1.2556 +/**
  1.2557 + * Function Name : TestDeflateInit2_
  1.2558 + * TestCase Description: deflateInit2_ with invalid compression level
  1.2559 + * Return Value: Z_STREAM_ERROR
  1.2560 + */
  1.2561 +TInt CTestZlib::TestDeflateInit2_()
  1.2562 +	{
  1.2563 +	TInt res = KErrNone ;
  1.2564 +	z_stream stream;
  1.2565 +	int err;
  1.2566 +
  1.2567 +	uLong sourceLen = (uLong)strlen(hello)+1;
  1.2568 +	Byte *compr;
  1.2569 +	uLong comprLen = 10*sizeof(int); 
  1.2570 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.2571 +	if (compr == Z_NULL)
  1.2572 +		{
  1.2573 +		return KErrNoMemory;
  1.2574 +		}
  1.2575 +
  1.2576 +	stream.zalloc = (alloc_func)0;
  1.2577 +	stream.zfree = (free_func)0;
  1.2578 +	stream.opaque = (voidpf)0;
  1.2579 +
  1.2580 +	err= deflateInit2_(&stream, 11, 8, 15, 8, 0,  zlibVersion(), sizeof(z_stream));
  1.2581 +
  1.2582 +	if (err != Z_OK) 
  1.2583 +		{  	
  1.2584 +		res = KErrNone; 
  1.2585 +		} 
  1.2586 +	else  
  1.2587 +		{    	
  1.2588 +		res = KErrGeneral;
  1.2589 +		}   
  1.2590 +	free(compr);
  1.2591 +	return res;
  1.2592 +	}
  1.2593 +
  1.2594 +
  1.2595 +/**
  1.2596 + * Function Name : TestDeflatefail
  1.2597 + * TestCase Description: Set stream next_in and next_out to NULL and call deflateEnd
  1.2598 + * Return Value: Z_STREAM_ERROR
  1.2599 + */   
  1.2600 +TInt CTestZlib::TestDeflatefail()
  1.2601 +	{	    
  1.2602 +	TInt res = KErrNone ;
  1.2603 +	z_stream c_stream; /* compression stream */
  1.2604 +	int err;
  1.2605 +	Byte * compr;
  1.2606 +	uLong comprLen = 20*sizeof(int); 
  1.2607 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.2608 +	if (compr == Z_NULL)
  1.2609 +		{
  1.2610 +		return KErrNoMemory;
  1.2611 +		}
  1.2612 +
  1.2613 +	uLong len = (uLong)strlen(hello)+1;
  1.2614 +
  1.2615 +	c_stream.zalloc = (alloc_func)0;
  1.2616 +	c_stream.zfree = (free_func)0;
  1.2617 +	c_stream.opaque = (voidpf)0;
  1.2618 +
  1.2619 +	res = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  1.2620 +	if(res <0)
  1.2621 +		{
  1.2622 +		free(compr);
  1.2623 +		return res;	
  1.2624 +		}
  1.2625 +
  1.2626 +	c_stream.next_in  = NULL;//(Bytef*)hello;
  1.2627 +	c_stream.next_out = NULL;//compr;
  1.2628 +
  1.2629 +	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  1.2630 +		{
  1.2631 +		c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
  1.2632 +		err = deflate(&c_stream, Z_NO_FLUSH);
  1.2633 +		if(err == 0)
  1.2634 +			{    	
  1.2635 +			res = KErrGeneral;
  1.2636 +			}
  1.2637 +		else
  1.2638 +			{
  1.2639 +			res=KErrNone;
  1.2640 +			break;
  1.2641 +			} 
  1.2642 +		}
  1.2643 +	/* Finish the stream, still forcing small buffers: */
  1.2644 +	res = deflateEnd(&c_stream);
  1.2645 +	free(compr);
  1.2646 +	return res;
  1.2647 +	}
  1.2648 +
  1.2649 +/**
  1.2650 + * Function Name : TestDeflatefail
  1.2651 + * TestCase Description: Set stream avail_out to NULL and call deflateEnd
  1.2652 + * Return Value: Z_STREAM_ERROR
  1.2653 + */
  1.2654 +TInt CTestZlib::TestDeflatefail2()
  1.2655 +	{    
  1.2656 +	TInt res = KErrNone ;
  1.2657 +	z_stream c_stream; /* compression stream */
  1.2658 +	int err;
  1.2659 +	Byte * compr;
  1.2660 +	uLong comprLen = 20*sizeof(int); 
  1.2661 +
  1.2662 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.2663 +	if (compr == Z_NULL)
  1.2664 +		{
  1.2665 +		return KErrNoMemory;
  1.2666 +		}
  1.2667 +
  1.2668 +	uLong len = (uLong)strlen(hello)+1;
  1.2669 +	c_stream.zalloc = (alloc_func)0;
  1.2670 +	c_stream.zfree = (free_func)0;
  1.2671 +	c_stream.opaque = (voidpf)0;
  1.2672 +
  1.2673 +	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  1.2674 +
  1.2675 +	if(err <0)
  1.2676 +		{
  1.2677 +		free(compr);
  1.2678 +		return err;	
  1.2679 +		}
  1.2680 +	c_stream.next_in = (Bytef*)hello;
  1.2681 +	c_stream.next_out = compr;
  1.2682 +
  1.2683 +	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  1.2684 +		{
  1.2685 +		c_stream.avail_in = 1;
  1.2686 +		c_stream.avail_out = 0; /* fail */
  1.2687 +		err = deflate(&c_stream, Z_NO_FLUSH);
  1.2688 +		if(err == 0)
  1.2689 +			{    	
  1.2690 +			res =  	 KErrGeneral;
  1.2691 +			}
  1.2692 +		else
  1.2693 +			{
  1.2694 +			res=KErrNone;
  1.2695 +			break;
  1.2696 +			}
  1.2697 +		}
  1.2698 +
  1.2699 +	err = deflateEnd(&c_stream);
  1.2700 +	free(compr);
  1.2701 +	return res;
  1.2702 +	}
  1.2703 +
  1.2704 +/**
  1.2705 + * Function Name : TestZlibversion
  1.2706 + * TestCase Description: Test Zlibversion
  1.2707 + * Return Value: Z_OK
  1.2708 + */  
  1.2709 +TInt CTestZlib::TestZlibversion()
  1.2710 +	{  
  1.2711 +	TInt res = KErrNone ;
  1.2712 +	if(strcmp(zlibVersion(), "1.2.3") != 0) 
  1.2713 +		{
  1.2714 +		res=KErrGeneral;
  1.2715 +		ERR_PRINTF1(_L("using incorrect zlib version "));
  1.2716 +		} 
  1.2717 +	return res;
  1.2718 +	}
  1.2719 +
  1.2720 +/**
  1.2721 + * Function Name : TestGzputc
  1.2722 + * TestCase Description: 1. Open a gzfile in read mode
  1.2723 + *						2. Write a character in the file using gzputc
  1.2724 + *						3. Close the file
  1.2725 + * Return Value: KErrNone
  1.2726 + */    
  1.2727 +TInt CTestZlib::TestGzputc()
  1.2728 +	{    
  1.2729 +	TInt res = KErrNone ;
  1.2730 +	TInt res1 = KErrNone ;
  1.2731 +	gzFile file;
  1.2732 +	const char * fname = TESTFILE ;
  1.2733 +	file = gzopen(fname, "wb");
  1.2734 +	if (file == NULL) 
  1.2735 +		{
  1.2736 +		res = KErrGeneral;
  1.2737 +		return res;
  1.2738 +		}
  1.2739 +	else
  1.2740 +		{
  1.2741 +		res1=gzputc(file, 'r');
  1.2742 +		if(res1<0)
  1.2743 +			{
  1.2744 +			res = KErrGeneral;
  1.2745 +			} 
  1.2746 +		else  
  1.2747 +			{    	
  1.2748 +			res = KErrNone;
  1.2749 +			}     	
  1.2750 +		}
  1.2751 +	int err=  gzclose(file);
  1.2752 +	if (err != Z_OK)  
  1.2753 +		{
  1.2754 +		res = KErrGeneral; 
  1.2755 +		} 
  1.2756 +	else  
  1.2757 +		{    	
  1.2758 +		res = KErrNone;
  1.2759 +		}   
  1.2760 +	return res;
  1.2761 +	}
  1.2762 +
  1.2763 +/**
  1.2764 + * Function Name : TestGzopen
  1.2765 + * TestCase Description: 1. Open a gzfile in read mode
  1.2766 + *						2. Close the file
  1.2767 + * Return Value: KErrNone
  1.2768 + */    
  1.2769 +TInt CTestZlib::TestGzopen()
  1.2770 +	{
  1.2771 +	TInt res = KErrNone ;
  1.2772 +	gzFile file;
  1.2773 +	const char * fname = TESTFILE ;
  1.2774 +	file = gzopen(fname, "rb");
  1.2775 +	if (file == NULL) 
  1.2776 +		{
  1.2777 +		res = KErrGeneral;
  1.2778 +		return res;
  1.2779 +		}    
  1.2780 +	else
  1.2781 +		{    	
  1.2782 +		res = KErrNone;
  1.2783 +		}
  1.2784 +	int err=gzclose(file);
  1.2785 +	if (err != Z_OK)  
  1.2786 +		{
  1.2787 +		res = KErrGeneral; 
  1.2788 +		} 
  1.2789 +	return res;
  1.2790 +	}
  1.2791 +
  1.2792 +/**
  1.2793 + * Function Name : TestGzopenmode
  1.2794 + * TestCase Description: 1.	Open a gzfile mentioning invalid mode
  1.2795 + * Return Value: KErrNone
  1.2796 + */    
  1.2797 +TInt CTestZlib::TestGzopenmode()
  1.2798 +	{
  1.2799 +	TInt res = KErrNone ;
  1.2800 +	gzFile file;
  1.2801 +	const char * fname = TESTFILE ;
  1.2802 +	file = gzopen(fname, "xyz");
  1.2803 +	if (file == NULL) 
  1.2804 +		{
  1.2805 +		res = KErrNone;
  1.2806 +		}    
  1.2807 +	else
  1.2808 +		{    	
  1.2809 +		res = KErrGeneral;
  1.2810 +		}
  1.2811 +	return res;
  1.2812 +	}
  1.2813 +
  1.2814 +/**
  1.2815 + * Function Name : TestGzopenfail
  1.2816 + * TestCase Description: Open a gzfile mentioning invalid path
  1.2817 + * Return Value: KErrNone
  1.2818 + */ 
  1.2819 +TInt CTestZlib::TestGzopenfail()
  1.2820 +	{
  1.2821 +	TInt res = KErrNone ;
  1.2822 +	gzFile file;
  1.2823 +	const char * fname = NOFILE ;
  1.2824 +	file = gzopen(fname, "wb");
  1.2825 +	if (file == NULL) 
  1.2826 +		{
  1.2827 +		res =KErrNone;
  1.2828 +		}    
  1.2829 +	else
  1.2830 +		{    	
  1.2831 +		res = KErrGeneral;
  1.2832 +		}
  1.2833 +	return res;
  1.2834 +	}
  1.2835 +
  1.2836 +/**
  1.2837 + * Function Name : TestGzputcfail
  1.2838 + * TestCase Description: 1. Open a gzfile mentioning invalid path
  1.2839 + *						2. Use gzputc to write a character
  1.2840 + * Return Value: KErrNone
  1.2841 + */    
  1.2842 +TInt CTestZlib::TestGzputcfail()
  1.2843 +	{
  1.2844 +	TInt res = KErrNone ;
  1.2845 +	TInt res1 = KErrNone ;
  1.2846 +	gzFile file;
  1.2847 +	const char * fname = NOFILE ;
  1.2848 +	file = gzopen(fname, "wb");   
  1.2849 +	if (file != NULL) 
  1.2850 +		{
  1.2851 +		res = KErrGeneral;
  1.2852 +		return res;
  1.2853 +		}
  1.2854 +	else
  1.2855 +		{
  1.2856 +		res1=gzputc(file, 'r');
  1.2857 +		if(res1<0)
  1.2858 +			{
  1.2859 +			res = KErrNone;
  1.2860 +			} 
  1.2861 +		else  
  1.2862 +			{    	
  1.2863 +			res = KErrGeneral;
  1.2864 +			}     	
  1.2865 +		}
  1.2866 +
  1.2867 +	int err=  gzclose(file);
  1.2868 +	if (err == Z_OK)  
  1.2869 +		{
  1.2870 +		res = KErrGeneral; 
  1.2871 +		} 
  1.2872 +	else  
  1.2873 +		{    	
  1.2874 +		res = KErrNone;
  1.2875 +		}   
  1.2876 +	return res;
  1.2877 +	}
  1.2878 +
  1.2879 +/**
  1.2880 + * Function Name : TestGzputcreturn
  1.2881 + * TestCase Description: 1. Open a gzfile in write mode
  1.2882 + *						2. Write a character in the file using gzputc
  1.2883 + *						3. Verify the character written by comparing it with what is written
  1.2884 + *						4. Close the file
  1.2885 + * Return Value: returns the value of the character that was written 
  1.2886 + */    
  1.2887 +TInt CTestZlib::TestGzputcreturn()
  1.2888 +	{
  1.2889 +	TInt res = KErrNone ;
  1.2890 +	TInt res1 = KErrNone ;
  1.2891 +	gzFile file;
  1.2892 +	const char * fname = TESTFILE ;
  1.2893 +	file = gzopen(fname, "wb");
  1.2894 +
  1.2895 +	if (file == NULL) 
  1.2896 +		{
  1.2897 +		res = KErrGeneral;
  1.2898 +		return res;
  1.2899 +		}
  1.2900 +	else
  1.2901 +		{
  1.2902 +		res1=gzputc(file, 'r');
  1.2903 +		if(res1!=(int)'r')
  1.2904 +			{
  1.2905 +			res = KErrGeneral;
  1.2906 +			} 
  1.2907 +		else  
  1.2908 +			{    	
  1.2909 +			res = KErrNone;
  1.2910 +			}     	
  1.2911 +		}
  1.2912 +
  1.2913 +	int err=  gzclose(file);
  1.2914 +	if (err != Z_OK)  
  1.2915 +		{
  1.2916 +		res = KErrGeneral; 
  1.2917 +		} 
  1.2918 +	return res;
  1.2919 +	}
  1.2920 +
  1.2921 +/**
  1.2922 + * Function Name : TestGzputs
  1.2923 + * TestCase Description: 1. Open a gzfile in write mode
  1.2924 + *						2. Write a string into file
  1.2925 + *						3. Close the file
  1.2926 + * Return Value: KErrNone
  1.2927 + */    
  1.2928 +TInt CTestZlib::TestGzputs()
  1.2929 +	{
  1.2930 +	TInt res = KErrNone ;
  1.2931 +	gzFile file;
  1.2932 +	const char * fname = TESTFILE ;
  1.2933 +	file = gzopen(fname, "wb");
  1.2934 +	if (file == NULL) 
  1.2935 +		{
  1.2936 +		res = KErrGeneral;
  1.2937 +		return res;
  1.2938 +		}
  1.2939 +	if (gzputs(file, "ello") != 4) 
  1.2940 +		{
  1.2941 +		ERR_PRINTF1(_L("gzputs err"));
  1.2942 +		}
  1.2943 +	int err=  gzclose(file);
  1.2944 +	if (err != Z_OK)  
  1.2945 +		{
  1.2946 +		res = KErrGeneral; 
  1.2947 +		}       
  1.2948 +	return res;    
  1.2949 +	}
  1.2950 +
  1.2951 +/**
  1.2952 + * Function Name : TestGzputsfail
  1.2953 + * TestCase Description: 1. Open a gzfile in read mode
  1.2954 + *						2. Write a string into file
  1.2955 + *						3. Close the file
  1.2956 + * Return Value: KErrNone
  1.2957 + */      
  1.2958 +TInt CTestZlib::TestGzputsfail()
  1.2959 +	{	
  1.2960 +	TInt res = KErrNone ;
  1.2961 +	gzFile file;
  1.2962 +	const char *fname = TESTFILE ;
  1.2963 +	file = gzopen(fname, "rb");
  1.2964 +	if (file == NULL) 
  1.2965 +		{
  1.2966 +		res = KErrGeneral;
  1.2967 +		return res;
  1.2968 +		}
  1.2969 +	if(gzputs(file, "ello") == 4) 
  1.2970 +		{
  1.2971 +		res= KErrGeneral;
  1.2972 +		}
  1.2973 +	int err=  gzclose(file);
  1.2974 +	if (err != Z_OK)  
  1.2975 +		{
  1.2976 +		res = KErrGeneral; 
  1.2977 +		}       
  1.2978 +	return res;    
  1.2979 +	}
  1.2980 +
  1.2981 +/**
  1.2982 + * Function Name : TestGzprintf
  1.2983 + * TestCase Description: 1. Open a gzfile in write mode
  1.2984 + *						2. Write a string into file mentioning the valid format specifier
  1.2985 + *						3. Close the file
  1.2986 + * Return Value: KErrNone
  1.2987 + */     
  1.2988 +TInt CTestZlib::TestGzprintf()
  1.2989 +	{
  1.2990 +	TInt res = KErrNone ;
  1.2991 +	gzFile file;
  1.2992 +	const char * fname = TESTFILE ;
  1.2993 +	file = gzopen(fname, "wb");
  1.2994 +	if(file == NULL) 
  1.2995 +		{
  1.2996 +		res = KErrNoMemory;
  1.2997 +		return res;
  1.2998 +		}   
  1.2999 +	if(gzprintf(file, ", %s!", "hello") != 8) 
  1.3000 +		{
  1.3001 +		ERR_PRINTF1(_L("gzprintf err"));
  1.3002 +		return KErrNone;
  1.3003 +		}
  1.3004 +
  1.3005 +	int err = gzclose(file);
  1.3006 +	if(err == 0)
  1.3007 +		{  	
  1.3008 +		res = KErrNone ;
  1.3009 +		} 
  1.3010 +	else
  1.3011 +		{	    	
  1.3012 +		res =res= KErrGeneral;
  1.3013 +		} 
  1.3014 +	return res;
  1.3015 +	}
  1.3016 +
  1.3017 +/**
  1.3018 + * Function Name : TestGzprintf_trying
  1.3019 + * TestCase Description: 1. Open a gzfile in read mode
  1.3020 + *						2. Write a string into file mentioning the valid format specifier
  1.3021 + *						3. Close the file
  1.3022 + * Return Value: KErrNone
  1.3023 + */    
  1.3024 +TInt CTestZlib::TestGzprintf_trying()
  1.3025 +	{
  1.3026 +	TInt res = KErrNone ;
  1.3027 +	gzFile file;
  1.3028 +	const char * fname = TESTFILE ;
  1.3029 +	file = gzopen(fname, "rb");
  1.3030 +	if (file == NULL) 
  1.3031 +		{
  1.3032 +		res = KErrNoMemory;
  1.3033 +		return res;
  1.3034 +		}   
  1.3035 +	if (gzprintf(file, ", %s!", "hello") != 8) 
  1.3036 +		{
  1.3037 +		gzclose(file);
  1.3038 +		res=KErrGeneral;
  1.3039 +		ERR_PRINTF1(_L("gzprintf err"));
  1.3040 +		return KErrNone;
  1.3041 +		}
  1.3042 +	int err = gzclose(file);
  1.3043 +	if(err == 0)
  1.3044 +		{  	
  1.3045 +		res = KErrNone ;
  1.3046 +		} 
  1.3047 +	else
  1.3048 +		{    	
  1.3049 +		res = KErrGeneral;
  1.3050 +		}   
  1.3051 +	return res;
  1.3052 +	}
  1.3053 +
  1.3054 +/**
  1.3055 + * Function Name : TestGzprintf_trying
  1.3056 + * TestCase Description: 1. Open a gzfile in write mode
  1.3057 + *						2. Write a string into file mentioning the valid arguments for gzwrite
  1.3058 + *						3. Close the file
  1.3059 + * Return Value: KErrNone
  1.3060 + */
  1.3061 +TInt CTestZlib::TestGzwrite()
  1.3062 +	{
  1.3063 +	TInt res = KErrNone ;
  1.3064 +	gzFile file;
  1.3065 +	uInt size ,len;
  1.3066 +	const char *s="ritesh";
  1.3067 +	len=strlen(s);
  1.3068 +	const char * fname = TESTFILE ;
  1.3069 +	file = gzopen(fname, "wb");
  1.3070 +	if (file == Z_NULL)  
  1.3071 +		{
  1.3072 +		res = KErrGeneral; 
  1.3073 +		return res;
  1.3074 +		}     
  1.3075 +	size = gzwrite(file, (char*)s, (unsigned)strlen(s));
  1.3076 +	if(len!=size)
  1.3077 +		{
  1.3078 +		res = KErrGeneral;
  1.3079 +		}
  1.3080 +	int err=  gzclose(file);
  1.3081 +	if (err != Z_OK)  
  1.3082 +		{
  1.3083 +		res = KErrGeneral; 
  1.3084 +		}     
  1.3085 +	return res;
  1.3086 +	}
  1.3087 +
  1.3088 +/**
  1.3089 + * Function Name : TestGzwritefail
  1.3090 + * TestCase Description: 1. Open a gzfile in read mode
  1.3091 + *						2. Write a string into file mentioning the valid arguments for gzwrite
  1.3092 + *						3. Close the file
  1.3093 + * Return Value: Z_NULL
  1.3094 + */
  1.3095 +TInt CTestZlib::TestGzwritefail()
  1.3096 +	{   
  1.3097 +	TInt res = KErrNone ;
  1.3098 +	gzFile file;
  1.3099 +	uInt size ,len;
  1.3100 +	const char *s="ritesh";
  1.3101 +	len=strlen(s);
  1.3102 +	const char * fname = TESTFILE ;
  1.3103 +	file = gzopen(fname, "rb"); //read mode
  1.3104 +	if (file == Z_NULL)  
  1.3105 +		{
  1.3106 +		res = KErrNoMemory; 
  1.3107 +		return res;
  1.3108 +		}     
  1.3109 +	size = gzwrite(file, (char*)s, (unsigned)strlen(s));
  1.3110 +	if(len!=size)
  1.3111 +		{
  1.3112 +		res = KErrNone;
  1.3113 +		}
  1.3114 +	int err=  gzclose(file);
  1.3115 +	if (err != Z_OK)  
  1.3116 +		{
  1.3117 +		res = KErrGeneral;     	    	
  1.3118 +		}     
  1.3119 +	return res;
  1.3120 +	}
  1.3121 +
  1.3122 +TInt testgztell( const char * fname, Byte * uncompr,uLong  uncomprLen)   
  1.3123 +	{
  1.3124 +	int err=0;
  1.3125 +	int len = (int)strlen(hello)+1;
  1.3126 +	gzFile file;
  1.3127 +	z_off_t pos;
  1.3128 +
  1.3129 +	file = gzopen(fname, "wb");
  1.3130 +	if (file == NULL) 
  1.3131 +		{
  1.3132 +		if (file == NULL) 
  1.3133 +			{
  1.3134 +			err = KErrGeneral; 
  1.3135 +			return err;        
  1.3136 +			}
  1.3137 +
  1.3138 +		}
  1.3139 +	gzputc(file, 'h');
  1.3140 +	if(gzputs(file, "ello") != 4) 
  1.3141 +		{
  1.3142 +		//fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
  1.3143 +		}
  1.3144 +	if(gzprintf(file, ", %s!", "hello") != 8) 
  1.3145 +		{
  1.3146 +		//fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
  1.3147 +		}
  1.3148 +	gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
  1.3149 +	gzclose(file);
  1.3150 +
  1.3151 +	file = gzopen(fname, "rb");
  1.3152 +	if(file == NULL) 
  1.3153 +		{
  1.3154 +		err = KErrGeneral; 
  1.3155 +		return err;        
  1.3156 +		}
  1.3157 +	strcpy((char*)uncompr, "garbage");
  1.3158 +	if(gzread(file, uncompr, (unsigned)uncomprLen) != len) 
  1.3159 +		{
  1.3160 +		//fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
  1.3161 +		//exit(1);
  1.3162 +		}
  1.3163 +	if(strcmp((char*)uncompr, hello)) 
  1.3164 +		{
  1.3165 +		//fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
  1.3166 +		////exit(1);
  1.3167 +		}
  1.3168 +	else
  1.3169 +		{
  1.3170 +		//printf("gzread(): %s\n", (char*)uncompr);
  1.3171 +		}
  1.3172 +
  1.3173 +	pos = gzseek(file, -8L, SEEK_CUR);
  1.3174 +	if (pos != 6 || gztell(file) != pos) 
  1.3175 +		{
  1.3176 +		err=-1;   
  1.3177 +		}
  1.3178 +	err=  gzclose(file);
  1.3179 +	return err;
  1.3180 +	}
  1.3181 +
  1.3182 +TInt CTestZlib::TestGztell()
  1.3183 +	{ 
  1.3184 +	TInt res = KErrNone ;
  1.3185 +	Byte *compr, *uncompr;
  1.3186 +	uLong comprLen = 20*sizeof(int); 
  1.3187 +	uLong uncomprLen = comprLen;
  1.3188 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.3189 +	if (compr == Z_NULL)
  1.3190 +		{
  1.3191 +		return KErrNoMemory;
  1.3192 +		}
  1.3193 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.3194 +	if (uncompr == Z_NULL) 
  1.3195 +		{
  1.3196 +		free(compr);
  1.3197 +		return KErrNoMemory;
  1.3198 +		}
  1.3199 +	test_compress(compr, comprLen, uncompr, uncomprLen);
  1.3200 +	int err = testgztell(TESTFILE,uncompr, uncomprLen);
  1.3201 +	if(err<0)
  1.3202 +		{
  1.3203 +		res= KErrGeneral;	
  1.3204 +		}
  1.3205 +	free(compr);
  1.3206 +	free(uncompr);
  1.3207 +	return res;
  1.3208 +	}
  1.3209 +
  1.3210 +TInt CTestZlib::TestGztell1()
  1.3211 +	{ 
  1.3212 +	TInt res = KErrNone ;
  1.3213 +	int err;
  1.3214 +	gzFile file;
  1.3215 +	file = gzopen(TESTFILE, "wb");             
  1.3216 +	if (file == NULL) 
  1.3217 +		{
  1.3218 +		res = KErrGeneral; 
  1.3219 +		return res;        
  1.3220 +		}           
  1.3221 +	err=gztell(file) ;
  1.3222 +	if(err<0)
  1.3223 +		{
  1.3224 +		res = KErrGeneral;
  1.3225 +		return res;	
  1.3226 +		}
  1.3227 +	err=  gzclose(file);
  1.3228 +	if(err != Z_OK)  
  1.3229 +		{
  1.3230 +		res = KErrGeneral; 
  1.3231 +		}
  1.3232 +	return res;
  1.3233 +	}
  1.3234 +
  1.3235 +TInt CTestZlib::TestGztellfail1()
  1.3236 +	{ 
  1.3237 +	TInt res = KErrNone ;
  1.3238 +	int err;
  1.3239 +	gzFile file;
  1.3240 +	file = gzopen(NOFILE, "wb");             
  1.3241 +	if (file == NULL) 
  1.3242 +		{
  1.3243 +		res = KErrNone; 
  1.3244 +		return res;        
  1.3245 +		}          
  1.3246 +	err=gztell(file) ;
  1.3247 +	if(err>0)
  1.3248 +		{
  1.3249 +		res= KErrGeneral;	
  1.3250 +		}
  1.3251 +	return res;
  1.3252 +	}
  1.3253 +
  1.3254 +int  test_deflatecopy (Bytef *dest,  uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
  1.3255 +	{
  1.3256 +	TInt res = KErrNone ;
  1.3257 +	z_stream stream;
  1.3258 +	z_stream stream1;
  1.3259 +	int err;
  1.3260 +
  1.3261 +	stream.zalloc = (alloc_func)0;
  1.3262 +	stream.zfree = (free_func)0;
  1.3263 +	stream.opaque = (voidpf)0;
  1.3264 +
  1.3265 +	stream.next_in = (Bytef*)source;
  1.3266 +	stream.avail_in = (uInt)sourceLen;
  1.3267 +
  1.3268 +	stream.next_out = dest;
  1.3269 +	stream.avail_out = (uInt)*destLen;
  1.3270 +	if ((uLong)stream.avail_out != *destLen)  
  1.3271 +		{
  1.3272 +		res = KErrGeneral; 
  1.3273 +		} 
  1.3274 +
  1.3275 +	err = deflateInit(&stream, level);
  1.3276 +	if (err != Z_OK)  
  1.3277 +		{
  1.3278 +		res = KErrGeneral; 
  1.3279 +		return res;
  1.3280 +		} 
  1.3281 +	err=deflateCopy(&stream1 , &stream); 
  1.3282 +	if (err != Z_OK)  
  1.3283 +		{
  1.3284 +		res = KErrGeneral; 
  1.3285 +		} 
  1.3286 +	err=deflateEnd(&stream);
  1.3287 +	if (err != Z_OK)  
  1.3288 +		{
  1.3289 +		res = KErrGeneral; 
  1.3290 +		} 
  1.3291 +	err=deflateEnd(&stream1);
  1.3292 +	if (err != Z_OK)  
  1.3293 +		{
  1.3294 +		res = KErrGeneral; 
  1.3295 +		}
  1.3296 +	return res;
  1.3297 +	}
  1.3298 +
  1.3299 +TInt CTestZlib::TestDeflatecopy()
  1.3300 +	{
  1.3301 +	TInt res;
  1.3302 +	uLong len = (uLong)strlen(hello)+1;
  1.3303 +
  1.3304 +	Byte *compr, *uncompr;
  1.3305 +	uLong comprLen = 20*sizeof(int); 
  1.3306 +	uLong uncomprLen = comprLen;
  1.3307 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.3308 +	if (compr == Z_NULL)
  1.3309 +		{
  1.3310 +		return KErrNoMemory;
  1.3311 +		}
  1.3312 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.3313 +	if (uncompr == Z_NULL) 
  1.3314 +		{
  1.3315 +		free(compr);
  1.3316 +		return KErrNoMemory;
  1.3317 +		}
  1.3318 +	res= test_deflatecopy(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);
  1.3319 +	free(compr);
  1.3320 +	free(uncompr);
  1.3321 +	return res;
  1.3322 +	}
  1.3323 +
  1.3324 +
  1.3325 +TInt CTestZlib::TestDeflatecopyfail()
  1.3326 +	{
  1.3327 +	TInt res = KErrNone ;int err;
  1.3328 +	z_stream stream1;
  1.3329 +	uLong len = (uLong)strlen(hello)+1;
  1.3330 +
  1.3331 +	Byte *compr;
  1.3332 +	uLong comprLen = 20*sizeof(int); 
  1.3333 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.3334 +
  1.3335 +	if (compr == Z_NULL)
  1.3336 +		{
  1.3337 +		return KErrNoMemory;
  1.3338 +		}
  1.3339 +	err=deflateCopy(&stream1 , NULL); 
  1.3340 +	if (err == Z_OK)  
  1.3341 +		{
  1.3342 +		res = KErrNone;     	    	
  1.3343 +		} 
  1.3344 +
  1.3345 +	free(compr);
  1.3346 +	return res;
  1.3347 +	}
  1.3348 +
  1.3349 +
  1.3350 +TInt CTestZlib::TestGzclose()
  1.3351 +	{     
  1.3352 +	TInt res = KErrNone ;
  1.3353 +	int err;
  1.3354 +	int len = (int)strlen(hello)+1;
  1.3355 +	gzFile file;
  1.3356 +
  1.3357 +	const char * fname = TESTFILE;
  1.3358 +	file = gzopen(fname, "wb");
  1.3359 +	gzputc(file, 'h');
  1.3360 +
  1.3361 +	err= gzclose(file);
  1.3362 +
  1.3363 +	if(err != 0)
  1.3364 +		{    	
  1.3365 +		res =  	 KErrGeneral;
  1.3366 +		}
  1.3367 +	return res;   
  1.3368 +	}
  1.3369 +
  1.3370 +
  1.3371 +TInt CTestZlib::TestGzclose_fail()
  1.3372 +	{
  1.3373 +	TInt res = KErrNone ;
  1.3374 +	int err;
  1.3375 +	int len = (int)strlen(hello)+1;
  1.3376 +	gzFile file;
  1.3377 +	const char * fname = NOFILE;
  1.3378 +
  1.3379 +	file = gzopen(fname, "wb");
  1.3380 +
  1.3381 +	err=gzclose(file);
  1.3382 +	if(err == 0)
  1.3383 +		{    	
  1.3384 +		res =  	 KErrGeneral;
  1.3385 +		}
  1.3386 +	return res;   
  1.3387 +	}
  1.3388 +
  1.3389 +TInt CTestZlib::TestGzeof()
  1.3390 +	{
  1.3391 +	TInt res = KErrNone ;
  1.3392 +	gzFile file;
  1.3393 +	const char * fname = TESTFILE ;
  1.3394 +	file = gzopen(fname, "wb");
  1.3395 +	if (file == NULL) 
  1.3396 +		{
  1.3397 +		res = KErrGeneral;
  1.3398 +		return res;
  1.3399 +		}   
  1.3400 +
  1.3401 +	if (gzputs(file, "ello") != 4) 
  1.3402 +		{
  1.3403 +		ERR_PRINTF1(_L("gzputs err"));
  1.3404 +		return KErrNone;
  1.3405 +		}
  1.3406 +	int x=gzeof(file);
  1.3407 +	if(x!=0)
  1.3408 +		{
  1.3409 +		res= KErrGeneral;	
  1.3410 +		}
  1.3411 +
  1.3412 +	int err=  gzclose(file);
  1.3413 +	if (err != Z_OK)  
  1.3414 +		{
  1.3415 +		res = KErrGeneral; 
  1.3416 +		} 
  1.3417 +	return res;
  1.3418 +	}
  1.3419 +
  1.3420 +TInt CTestZlib::TestGzeoffail1()
  1.3421 +	{
  1.3422 +	TInt res = KErrNone ;
  1.3423 +	gzFile file;
  1.3424 +	const char * fname = TESTFILE ;
  1.3425 +	file = gzopen(fname, "rb");
  1.3426 +	if (file == NULL) 
  1.3427 +		{
  1.3428 +		res = KErrGeneral;
  1.3429 +		return res;
  1.3430 +		}   
  1.3431 +	int x=gzeof(file);
  1.3432 +	if(x!=Z_STREAM_END)
  1.3433 +		{
  1.3434 +		res= KErrNone;	
  1.3435 +		}
  1.3436 +
  1.3437 +	int err=  gzclose(file);
  1.3438 +	if (err != Z_OK)  
  1.3439 +		{
  1.3440 +		res = KErrGeneral; 
  1.3441 +		} 
  1.3442 +	return res;
  1.3443 +	}	
  1.3444 +
  1.3445 +TInt CTestZlib::TestGzeoffail2()
  1.3446 +	{
  1.3447 +	TInt res = KErrNone ;
  1.3448 +	gzFile file;
  1.3449 +	const char * fname = NOFILE ;
  1.3450 +	file = gzopen(fname, "wb");   
  1.3451 +	int x=gzeof(file);
  1.3452 +	if(x!=0)
  1.3453 +		{
  1.3454 +		res= KErrNone;	
  1.3455 +		}    
  1.3456 +	int err=  gzclose(file);
  1.3457 +	if (err == Z_OK)  
  1.3458 +		{
  1.3459 +		res = KErrGeneral;     	    	
  1.3460 +		}       
  1.3461 +	return res;
  1.3462 +	}
  1.3463 +
  1.3464 +TInt CTestZlib::TestGzgetc()
  1.3465 +	{
  1.3466 +	TInt res = KErrNone ;
  1.3467 +	gzFile file;
  1.3468 +	const char * fname = TESTFILE ;
  1.3469 +	file = gzopen(fname, "rb");
  1.3470 +	if (file == Z_NULL)  
  1.3471 +		{
  1.3472 +		res = KErrNoMemory; 
  1.3473 +		return res;
  1.3474 +		} 
  1.3475 +	int l=  gzgetc(file);
  1.3476 +	int err=  gzclose(file);
  1.3477 +	if (err != Z_OK)  
  1.3478 +		{
  1.3479 +		res = KErrGeneral; 
  1.3480 +		}     
  1.3481 +	return res;
  1.3482 +	}
  1.3483 +
  1.3484 +
  1.3485 +TInt CTestZlib::TestGzflush()
  1.3486 +	{
  1.3487 +	TInt res = KErrNone ;
  1.3488 +	gzFile file;
  1.3489 +	const char * fname = TESTFILE ;
  1.3490 +	file = gzopen(fname, "wb");
  1.3491 +	if (file == Z_NULL)  
  1.3492 +		{
  1.3493 +		res = KErrNoMemory; 
  1.3494 +		return res;
  1.3495 +		}     
  1.3496 +	int l= gzflush(file,Z_FULL_FLUSH);
  1.3497 +	if(l != Z_OK)  
  1.3498 +		{
  1.3499 +		res = KErrGeneral;  
  1.3500 +		} 
  1.3501 +
  1.3502 +	int err=gzclose(file);
  1.3503 +	if (err != Z_OK)  
  1.3504 +		{
  1.3505 +		res = KErrGeneral;     	    	
  1.3506 +		}     
  1.3507 +	return res;
  1.3508 +	}
  1.3509 +
  1.3510 +
  1.3511 +TInt CTestZlib::TestGzflushsync()
  1.3512 +	{
  1.3513 +	TInt res = KErrNone ;
  1.3514 +	gzFile file;
  1.3515 +	const char * fname = TESTFILE ;
  1.3516 +	file = gzopen(fname, "wb");
  1.3517 +	if (file == Z_NULL)  
  1.3518 +		{
  1.3519 +		res = KErrNoMemory; 
  1.3520 +		return res;
  1.3521 +		}     
  1.3522 +	int l= gzflush(file,Z_SYNC_FLUSH);
  1.3523 +	if (l != Z_OK)  
  1.3524 +		{
  1.3525 +		res = KErrGeneral;  
  1.3526 +		} 
  1.3527 +	int err=  gzclose(file);
  1.3528 +	if(err != Z_OK)  
  1.3529 +		{
  1.3530 +		res = KErrGeneral;     	    	
  1.3531 +		}     
  1.3532 +	return res;
  1.3533 +	}
  1.3534 +
  1.3535 +TInt CTestZlib::TestGzflushfail()
  1.3536 +	{
  1.3537 +	TInt res = KErrNone ;
  1.3538 +	gzFile file;   
  1.3539 +	const char * fname = TESTFILE ;
  1.3540 +	file = gzopen(fname, "rb");
  1.3541 +	if (file == Z_NULL)  
  1.3542 +		{
  1.3543 +		res = KErrGeneral; 
  1.3544 +		return res;
  1.3545 +		}     
  1.3546 +	int l= gzflush(file,Z_FULL_FLUSH);
  1.3547 +	if (l == Z_OK)  
  1.3548 +		{
  1.3549 +		res = KErrGeneral;  
  1.3550 +		} 
  1.3551 +	int err=  gzclose(file);
  1.3552 +	if (err != Z_OK) 
  1.3553 +		{
  1.3554 +		res = KErrGeneral;     	    	
  1.3555 +		} 
  1.3556 +	return res;
  1.3557 +	}
  1.3558 +
  1.3559 +TInt CTestZlib::TestGzerror()
  1.3560 +	{
  1.3561 +	TInt res = KErrNone ;
  1.3562 +	int err;
  1.3563 +	int len = (int)strlen(hello)+1;
  1.3564 +	gzFile file;
  1.3565 +	const char * fname = TESTFILE ;
  1.3566 +	file = gzopen(fname, "wb");
  1.3567 +	if (file == NULL) 
  1.3568 +		{
  1.3569 +		res=KErrGeneral;
  1.3570 +		}
  1.3571 +	gzputc(file, 'h');
  1.3572 +	if (gzputs(file, "ello") != 5) 
  1.3573 +		{
  1.3574 +		gzprintf(file, "gzputs err: %s\n", gzerror(file, &err));
  1.3575 +		res=KErrGeneral;
  1.3576 +		}
  1.3577 +	err=  gzclose(file);
  1.3578 +	if (err != Z_OK)  
  1.3579 +		{
  1.3580 +		res = KErrGeneral;     	    	
  1.3581 +		}
  1.3582 +	else
  1.3583 +		{
  1.3584 +		res = KErrNone;     	    	
  1.3585 +		} 
  1.3586 +	return res;
  1.3587 +	}
  1.3588 +
  1.3589 +
  1.3590 +TInt CTestZlib::TestGzerrorfail1()
  1.3591 +	{
  1.3592 +	TInt res = KErrNone ;
  1.3593 +	int err;
  1.3594 +	int len = (int)strlen(hello)+1;
  1.3595 +	gzFile file;
  1.3596 +	const char * fname = NOFILE ;
  1.3597 +	file = gzopen(fname, "wb");
  1.3598 +	if (file != NULL) 
  1.3599 +		{
  1.3600 +		res=KErrGeneral;
  1.3601 +		return res;
  1.3602 +		}
  1.3603 +	gzputc(file, 'h');
  1.3604 +	if (gzputs(file, "ello") != 5) 
  1.3605 +		{
  1.3606 +		gzprintf(file, "gzputs err: %s\n", gzerror(file, &err));
  1.3607 +		res=KErrNone;
  1.3608 +		}
  1.3609 +	err=  gzclose(file);
  1.3610 +	if (err == Z_OK)  
  1.3611 +		{
  1.3612 +		res = KErrGeneral; 
  1.3613 +		}       
  1.3614 +	return res;
  1.3615 +	}
  1.3616 +
  1.3617 +
  1.3618 +TInt CTestZlib::TestGzgetcfail()
  1.3619 +	{
  1.3620 +	TInt res = KErrNone ;
  1.3621 +	gzFile file;   
  1.3622 +	const char * fname = TESTFILE ;
  1.3623 +	file = gzopen(fname, "wb");
  1.3624 +	if (file == Z_NULL)  
  1.3625 +		{
  1.3626 +		res = KErrNoMemory; 
  1.3627 +		return res;
  1.3628 +		}     
  1.3629 +	int l=  gzgetc(file);
  1.3630 +	int err=  gzclose(file);
  1.3631 +	if (err != Z_OK)  
  1.3632 +		{
  1.3633 +		res = KErrGeneral;     	    	
  1.3634 +		} 
  1.3635 +	return res;
  1.3636 +	}
  1.3637 +
  1.3638 +
  1.3639 +TInt CTestZlib::TestDeflateSetDictionary()
  1.3640 +	{
  1.3641 +	TInt res = KErrNone ;
  1.3642 +	Byte *compr, *uncompr;
  1.3643 +	uLong comprLen = 20*sizeof(int); 
  1.3644 +	uLong uncomprLen = comprLen;
  1.3645 +
  1.3646 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.3647 +	if (compr == Z_NULL)
  1.3648 +		{
  1.3649 +		return KErrNoMemory;
  1.3650 +		}
  1.3651 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.3652 +	if (uncompr == Z_NULL) 
  1.3653 +		{
  1.3654 +		free(compr);
  1.3655 +		return KErrNoMemory;
  1.3656 +		}
  1.3657 +
  1.3658 +	res = test_compress(compr, comprLen, uncompr, uncomprLen);
  1.3659 +	if(res < 0)
  1.3660 +		{
  1.3661 +		free(compr);
  1.3662 +		free(uncompr);
  1.3663 +		return KErrNoMemory;
  1.3664 +		}
  1.3665 +	res=Test_dict_deflate(compr, comprLen);
  1.3666 +	free(compr);
  1.3667 +	free(uncompr);
  1.3668 +	return res;
  1.3669 +	}
  1.3670 +
  1.3671 +
  1.3672 +
  1.3673 +TInt CTestZlib::TestDeflateSetDictionary_nodict()
  1.3674 +	{
  1.3675 +	TInt res = KErrNone ;
  1.3676 +	Byte *compr, *uncompr;
  1.3677 +	uLong comprLen = 20*sizeof(int); 
  1.3678 +	uLong uncomprLen = comprLen;
  1.3679 +	z_stream c_stream; /* compression stream */
  1.3680 +	int err;
  1.3681 +
  1.3682 +	c_stream.zalloc = (alloc_func)0;
  1.3683 +	c_stream.zfree = (free_func)0;
  1.3684 +	c_stream.opaque = (voidpf)0;
  1.3685 +
  1.3686 +	err = deflateInit(&c_stream, Z_BEST_COMPRESSION);                    
  1.3687 +	if(err < 0)                 
  1.3688 +		{
  1.3689 +		return Z_MEM_ERROR;
  1.3690 +		}
  1.3691 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.3692 +	if (compr == Z_NULL)
  1.3693 +		{
  1.3694 +		return KErrNoMemory;
  1.3695 +		}
  1.3696 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.3697 +	if (uncompr == Z_NULL) 
  1.3698 +		{
  1.3699 +		free(compr);
  1.3700 +		return KErrNoMemory;
  1.3701 +		}
  1.3702 +	err = deflateSetDictionary(&c_stream,NULL, sizeof(dictionary));
  1.3703 +	if(err != 0)
  1.3704 +		{    	
  1.3705 +		res = KErrNone ;    	
  1.3706 +		}
  1.3707 +	else
  1.3708 +		{    	
  1.3709 +		res = KErrGeneral;
  1.3710 +		}
  1.3711 +	err = deflateEnd(&c_stream);
  1.3712 +	if (err)
  1.3713 +		{
  1.3714 +		res =	 KErrGeneral;
  1.3715 +		}
  1.3716 +	free(compr);
  1.3717 +	free(uncompr);
  1.3718 +
  1.3719 +	return res;
  1.3720 +	}
  1.3721 +
  1.3722 +TInt CTestZlib::TestDeflateSetDictionary_fail()
  1.3723 +	{
  1.3724 +	TInt res = KErrNone ;
  1.3725 +	Byte *compr, *uncompr;
  1.3726 +	uLong comprLen = 20*sizeof(int); 
  1.3727 +	uLong uncomprLen = comprLen;
  1.3728 +
  1.3729 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.3730 +	if (compr == Z_NULL)
  1.3731 +		{
  1.3732 +		return KErrNoMemory;
  1.3733 +		}	
  1.3734 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.3735 +	if (uncompr == Z_NULL) 
  1.3736 +		{
  1.3737 +		free(compr);
  1.3738 +		return KErrNoMemory;
  1.3739 +		}
  1.3740 +
  1.3741 +	res=test_compress(compr, comprLen, uncompr, uncomprLen);
  1.3742 +
  1.3743 +	if(res < 0)
  1.3744 +		{
  1.3745 +		free(compr);
  1.3746 +		free(uncompr);
  1.3747 +		return KErrNoMemory;
  1.3748 +		}
  1.3749 +	res = Test_dict_deflate(compr, comprLen);
  1.3750 +	if(res < 0)
  1.3751 +		{
  1.3752 +		free(compr);
  1.3753 +		free(uncompr);
  1.3754 +		return KErrNoMemory;
  1.3755 +		}
  1.3756 +	int  err = deflateSetDictionary(NULL,(const Bytef*)dictionary, sizeof(dictionary));
  1.3757 +	if(err != 0)
  1.3758 +		{    	
  1.3759 +		res = KErrNone ;    	
  1.3760 +		}
  1.3761 +	else
  1.3762 +		{    	
  1.3763 +		res = KErrGeneral;
  1.3764 +		}
  1.3765 +	free(compr);
  1.3766 +	free(uncompr);
  1.3767 +	return res;
  1.3768 +	}
  1.3769 +
  1.3770 +
  1.3771 +TInt CTestZlib::TestDeflateend()
  1.3772 +	{    
  1.3773 +	TInt res = KErrNone ;
  1.3774 +	z_stream c_stream; /* compression stream */
  1.3775 +	int err;
  1.3776 +	uLong len = (uLong)strlen(hello)+1;
  1.3777 +	Byte *compr, *uncompr;
  1.3778 +	uLong comprLen = 20*sizeof(int); 
  1.3779 +	uLong uncomprLen = comprLen;
  1.3780 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.3781 +	if (compr == Z_NULL)
  1.3782 +		{
  1.3783 +		return KErrNoMemory;
  1.3784 +		}
  1.3785 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.3786 +	if (uncompr == Z_NULL) 
  1.3787 +		{
  1.3788 +		free(compr);
  1.3789 +		return KErrNoMemory;
  1.3790 +		}
  1.3791 +
  1.3792 +	c_stream.zalloc = (alloc_func)0;
  1.3793 +	c_stream.zfree = (free_func)0;
  1.3794 +	c_stream.opaque = (voidpf)0;
  1.3795 +	err=test_compress(compr, comprLen, uncompr, uncomprLen);
  1.3796 +	if(err <0)
  1.3797 +		{
  1.3798 +		free(compr);
  1.3799 +		free(uncompr);
  1.3800 +		return err;	
  1.3801 +		}
  1.3802 +	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  1.3803 +	if(err <0)
  1.3804 +		{
  1.3805 +		free(compr);
  1.3806 +		free(uncompr);
  1.3807 +		return err;	
  1.3808 +		}
  1.3809 +
  1.3810 +	c_stream.next_in  = (Bytef*)hello;
  1.3811 +	c_stream.next_out = compr;
  1.3812 +
  1.3813 +	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  1.3814 +		{
  1.3815 +		c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
  1.3816 +		err = deflate(&c_stream, Z_NO_FLUSH);
  1.3817 +		}
  1.3818 +	/* Finish the stream, still forcing small buffers: */
  1.3819 +	for (;;) 
  1.3820 +		{
  1.3821 +		c_stream.avail_out = 1;
  1.3822 +		err = deflate(&c_stream, Z_FINISH);
  1.3823 +		if (err == Z_STREAM_END) break;
  1.3824 +		}
  1.3825 +	err = deflateEnd(&c_stream);
  1.3826 +	if (err)
  1.3827 +		{
  1.3828 +		res =	 KErrGeneral;
  1.3829 +		}
  1.3830 +	free(compr);
  1.3831 +	free(uncompr);
  1.3832 +	return res;
  1.3833 +	}
  1.3834 +
  1.3835 +
  1.3836 +TInt CTestZlib::TestDeflateendfail1()
  1.3837 +	{    
  1.3838 +	TInt res = KErrNone ;
  1.3839 +	z_stream c_stream; /* compression stream */
  1.3840 +	int err;
  1.3841 +	Byte * compr;
  1.3842 +	uLong comprLen = 20*sizeof(int); 
  1.3843 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.3844 +	if (compr == Z_NULL)
  1.3845 +		{
  1.3846 +		return KErrNoMemory;
  1.3847 +		}
  1.3848 +
  1.3849 +	uLong len = (uLong)strlen(hello)+1;
  1.3850 +	c_stream.zalloc = (alloc_func)0;
  1.3851 +	c_stream.zfree = (free_func)0;
  1.3852 +	c_stream.opaque = (voidpf)0;
  1.3853 +
  1.3854 +	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  1.3855 +	if(err<0)
  1.3856 +		{
  1.3857 +		free(compr);
  1.3858 +		return KErrNoMemory;
  1.3859 +		}
  1.3860 +	c_stream.next_in  = (Bytef*)hello;
  1.3861 +	c_stream.next_out = compr;
  1.3862 +
  1.3863 +	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  1.3864 +		{
  1.3865 +		c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
  1.3866 +		err = deflate(&c_stream, Z_NO_FLUSH);
  1.3867 +		}
  1.3868 +
  1.3869 +	err = deflateEnd(&c_stream);
  1.3870 +	if (!err)
  1.3871 +		{
  1.3872 +		res =	 KErrGeneral;
  1.3873 +		}
  1.3874 +	free(compr);
  1.3875 +	return res;
  1.3876 +	}
  1.3877 +
  1.3878 +
  1.3879 +TInt CTestZlib::TestDeflate()
  1.3880 +	{    
  1.3881 +	TInt res = KErrNone ;
  1.3882 +	z_stream c_stream; /* compression stream */
  1.3883 +	int err;
  1.3884 +	Byte * compr;
  1.3885 +	uLong comprLen = 20*sizeof(int); 
  1.3886 +	compr    = (Byte*)calloc((uInt)comprLen, 1);   
  1.3887 +	if (compr == Z_NULL)
  1.3888 +		{
  1.3889 +		return KErrNoMemory;
  1.3890 +		}
  1.3891 +	uLong len = (uLong)strlen(hello)+1;
  1.3892 +
  1.3893 +	c_stream.zalloc = (alloc_func)0;
  1.3894 +	c_stream.zfree = (free_func)0;
  1.3895 +	c_stream.opaque = (voidpf)0;
  1.3896 +
  1.3897 +	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  1.3898 +	if(err <0)
  1.3899 +		{
  1.3900 +		free(compr);
  1.3901 +		return err;	
  1.3902 +		}
  1.3903 +
  1.3904 +	c_stream.next_in  = (Bytef*)hello;
  1.3905 +	c_stream.next_out = compr;
  1.3906 +
  1.3907 +	while (c_stream.total_in != len && c_stream.total_out < comprLen) 
  1.3908 +		{
  1.3909 +		c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
  1.3910 +		err = deflate(&c_stream, Z_NO_FLUSH);
  1.3911 +		if(err != 0)
  1.3912 +			{    	
  1.3913 +			res = KErrGeneral;
  1.3914 +			}
  1.3915 +		}
  1.3916 +
  1.3917 +	err = deflateEnd(&c_stream);
  1.3918 +	free(compr);
  1.3919 +
  1.3920 +	return res;
  1.3921 +	}
  1.3922 +
  1.3923 +
  1.3924 +TInt CTestZlib::TestGzseek()
  1.3925 +	{    
  1.3926 +	TInt res = KErrNone ; 
  1.3927 +	Byte *compr, *uncompr;
  1.3928 +	uLong comprLen = 20*sizeof(int); 
  1.3929 +	uLong uncomprLen = comprLen;
  1.3930 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.3931 +	if (compr == Z_NULL)
  1.3932 +		{
  1.3933 +		return KErrNoMemory;
  1.3934 +		}
  1.3935 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.3936 +	if (uncompr == Z_NULL) 
  1.3937 +		{
  1.3938 +		free(compr);
  1.3939 +		return KErrNoMemory;
  1.3940 +		}
  1.3941 +	int err;
  1.3942 +	err = test_compress(compr, comprLen, uncompr, uncomprLen);
  1.3943 +	if (err < 0)
  1.3944 +		{
  1.3945 +		free(compr);
  1.3946 +		free(uncompr);
  1.3947 +		return KErrNoMemory;
  1.3948 +		}   
  1.3949 +	int len = (int)strlen(hello)+1;
  1.3950 +	gzFile file;
  1.3951 +	file = gzopen(TESTFILE, "wb");
  1.3952 +	if (file == NULL) 
  1.3953 +		{
  1.3954 +		free(compr);
  1.3955 +		free(uncompr);
  1.3956 +		res = KErrNoMemory; 
  1.3957 +		return res;        
  1.3958 +		}
  1.3959 +	gzputc(file, 'h');
  1.3960 +	if (gzputs(file, "ello") != 4)
  1.3961 +		{
  1.3962 +		res = KErrGeneral; 
  1.3963 +		return res;
  1.3964 +		}
  1.3965 +	if (gzprintf(file, ", %s!", "hello") != 8) 
  1.3966 +		{
  1.3967 +		res = KErrGeneral; 
  1.3968 +		return res;
  1.3969 +		}
  1.3970 +	err= gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
  1.3971 +	if(err<0)
  1.3972 +		{
  1.3973 +		res	= KErrGeneral;	
  1.3974 +		}
  1.3975 +	err=  gzclose(file);
  1.3976 +	if (err != Z_OK)  
  1.3977 +		{
  1.3978 +		res = KErrGeneral; 
  1.3979 +		} 
  1.3980 +
  1.3981 +	free(compr);
  1.3982 +	free(uncompr);
  1.3983 +	return res;
  1.3984 +	}
  1.3985 +
  1.3986 +
  1.3987 +TInt CTestZlib::TestGzseekfail1()
  1.3988 +	{    
  1.3989 +	TInt res = KErrNone ; 
  1.3990 +	Byte *compr, *uncompr;
  1.3991 +	uLong comprLen = 20*sizeof(int); 
  1.3992 +	uLong uncomprLen = comprLen;
  1.3993 +
  1.3994 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.3995 +	if (compr == Z_NULL)
  1.3996 +		{
  1.3997 +		return KErrNoMemory;
  1.3998 +		}
  1.3999 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.4000 +	if (uncompr == Z_NULL) 
  1.4001 +		{
  1.4002 +		free(compr);
  1.4003 +		return KErrNoMemory;
  1.4004 +		}
  1.4005 +	int err;
  1.4006 +	err = test_compress(compr, comprLen, uncompr, uncomprLen);
  1.4007 +	if (err < 0)
  1.4008 +		{
  1.4009 +		free(compr);
  1.4010 +		free(uncompr);
  1.4011 +		return KErrNoMemory;
  1.4012 +		}   
  1.4013 +
  1.4014 +	int len = (int)strlen(hello)+1;
  1.4015 +	gzFile file;
  1.4016 +	file = gzopen(NOFILE, "wb");
  1.4017 +
  1.4018 +	err = gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
  1.4019 +	if(err>=0)
  1.4020 +		{
  1.4021 +		res= KErrGeneral;	
  1.4022 +		}
  1.4023 +	err=  gzclose(file);
  1.4024 +	if (err == Z_OK)  
  1.4025 +		{
  1.4026 +		res = KErrGeneral; 
  1.4027 +		} 
  1.4028 +
  1.4029 +	free(compr);
  1.4030 +	free(uncompr);
  1.4031 +	return res;
  1.4032 +	}
  1.4033 +
  1.4034 +TInt CTestZlib::TestGzseekfail2()
  1.4035 +	{    
  1.4036 +	TInt res = KErrNone ; 
  1.4037 +	Byte *compr, *uncompr;
  1.4038 +	uLong comprLen = 20*sizeof(int); 
  1.4039 +	uLong uncomprLen = comprLen;
  1.4040 +
  1.4041 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.4042 +	if (compr == Z_NULL)
  1.4043 +		{
  1.4044 +		return KErrNoMemory;
  1.4045 +		}
  1.4046 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.4047 +	if(uncompr == Z_NULL) 
  1.4048 +		{
  1.4049 +		free(compr);
  1.4050 +		return KErrNoMemory;
  1.4051 +		}
  1.4052 +
  1.4053 +	int err;
  1.4054 +	err = test_compress(compr, comprLen, uncompr, uncomprLen);
  1.4055 +	if (err < 0)
  1.4056 +		{
  1.4057 +		free(compr);
  1.4058 +		free(uncompr);
  1.4059 +		return KErrNoMemory;
  1.4060 +		}   
  1.4061 +	int len = (int)strlen(hello)+1;
  1.4062 +	gzFile file;
  1.4063 +	file = gzopen(TESTFILE, "wb");
  1.4064 +
  1.4065 +	err = gzseek(file, -1L, SEEK_CUR); /* add one zero byte */
  1.4066 +	if(err>=0)
  1.4067 +		{
  1.4068 +		res= KErrGeneral;	
  1.4069 +		}
  1.4070 +	err=  gzclose(file);
  1.4071 +	if (err != Z_OK)  
  1.4072 +		{
  1.4073 +		res = KErrGeneral; 
  1.4074 +		} 
  1.4075 +
  1.4076 +	free(compr);
  1.4077 +	free(uncompr);
  1.4078 +	return res;
  1.4079 +	}
  1.4080 +
  1.4081 +TInt CTestZlib::TestGzsetparams()
  1.4082 +	{    
  1.4083 +	TInt res = KErrNone ;
  1.4084 +	int len = (int)strlen(hello)+1;
  1.4085 +	gzFile file;
  1.4086 +	const char * fname = TESTFILE;
  1.4087 +
  1.4088 +	file = gzopen(fname, "wb");
  1.4089 +	gzputc(file, 'h');
  1.4090 +
  1.4091 +	int u = gzsetparams(file, Z_BEST_SPEED, Z_DEFAULT_STRATEGY);
  1.4092 +	if(u!=0)
  1.4093 +		{
  1.4094 +		res= KErrGeneral;	
  1.4095 +		}
  1.4096 +	int err=  gzclose(file);
  1.4097 +	if (err != Z_OK)  
  1.4098 +		{
  1.4099 +		res = KErrGeneral; 
  1.4100 +		} 
  1.4101 +
  1.4102 +	return res;
  1.4103 +	}
  1.4104 +
  1.4105 +
  1.4106 +TInt CTestZlib::TestGzsetparams_fail1()
  1.4107 +	{   
  1.4108 +	TInt res = KErrNone ; 
  1.4109 +	int len = (int)strlen(hello)+1;
  1.4110 +	gzFile file;
  1.4111 +	const char * fname = TESTFILE;
  1.4112 +	file = gzopen(fname, "wb");
  1.4113 +	gzputc(file, 'h');
  1.4114 +
  1.4115 +	int u = gzsetparams(file, Z_BEST_SPEED, -2);
  1.4116 +	if(u==0)
  1.4117 +		{
  1.4118 +		res= KErrGeneral;	
  1.4119 +		}
  1.4120 +
  1.4121 +	int err=  gzclose(file);
  1.4122 +	if (err != Z_OK)  
  1.4123 +		{
  1.4124 +		res = KErrGeneral; 
  1.4125 +		} 
  1.4126 +
  1.4127 +	return res;
  1.4128 +	}
  1.4129 +
  1.4130 +
  1.4131 +TInt CTestZlib::TestGzsetparams_fail2()
  1.4132 +	{    
  1.4133 +	TInt res = KErrNone ;
  1.4134 +
  1.4135 +	int len = (int)strlen(hello)+1;
  1.4136 +	gzFile file;
  1.4137 +
  1.4138 +	const char * fname = TESTFILE;
  1.4139 +	file = gzopen(fname, "wb");
  1.4140 +	gzputc(file, 'h');
  1.4141 +
  1.4142 +	int u = gzsetparams(file, -2, Z_DEFAULT_STRATEGY);
  1.4143 +	if(u==0)
  1.4144 +		{
  1.4145 +		res= KErrGeneral;	
  1.4146 +		}
  1.4147 +	int err=  gzclose(file);
  1.4148 +	if (err != Z_OK)  
  1.4149 +		{
  1.4150 +		res = KErrGeneral; 
  1.4151 +		} 
  1.4152 +
  1.4153 +	return res;
  1.4154 +	}
  1.4155 +
  1.4156 +TInt CTestZlib::TestGzsetparams_fail3()
  1.4157 +	{   
  1.4158 +	TInt res = KErrNone ; 
  1.4159 +	int len = (int)strlen(hello)+1;
  1.4160 +	gzFile file;
  1.4161 +	const char * fname = TESTFILE;
  1.4162 +
  1.4163 +	file = gzopen(fname, "rb");
  1.4164 +	if (file == NULL) 
  1.4165 +		{
  1.4166 +		res = KErrGeneral; 
  1.4167 +		return res;        
  1.4168 +		}
  1.4169 +	gzputc(file, 'h');
  1.4170 +
  1.4171 +	int u = gzsetparams(file, Z_BEST_SPEED, Z_DEFAULT_STRATEGY);
  1.4172 +	if(u==0)
  1.4173 +		{
  1.4174 +		res	= KErrGeneral;	
  1.4175 +		}
  1.4176 +
  1.4177 +	int err=  gzclose(file);
  1.4178 +	if (err != Z_OK)  
  1.4179 +		{
  1.4180 +		res = KErrGeneral; 
  1.4181 +		} 
  1.4182 +	return res;
  1.4183 +	}
  1.4184 +
  1.4185 +
  1.4186 +TInt CTestZlib::TestGzrewind()
  1.4187 +	{ 
  1.4188 +	TInt res = KErrNone ;
  1.4189 +	int err;
  1.4190 +	int len = (int)strlen(hello)+1;
  1.4191 +	gzFile file;
  1.4192 +
  1.4193 +	const char * fname = TESTFILE;
  1.4194 +	file = gzopen(fname, "rb");
  1.4195 +	if (file == NULL) 
  1.4196 +		{
  1.4197 +		res = KErrGeneral;
  1.4198 +		}
  1.4199 +	gzputc(file, 'h');
  1.4200 +	err = gzrewind(file);
  1.4201 +	if(err == 0)
  1.4202 +		{    	
  1.4203 +		res = KErrNone ;    	
  1.4204 +		}
  1.4205 +	else
  1.4206 +		{    	
  1.4207 +		res = KErrGeneral;
  1.4208 +		}
  1.4209 +	err = gzclose(file);
  1.4210 +	if (err != Z_OK)  
  1.4211 +		{
  1.4212 +		res = KErrGeneral; 
  1.4213 +		} 
  1.4214 +	return res;
  1.4215 +	}
  1.4216 +
  1.4217 +
  1.4218 +
  1.4219 +TInt CTestZlib::TestGzrewindfail()
  1.4220 +	{    
  1.4221 +	TInt res = KErrNone ;
  1.4222 +	int err;
  1.4223 +	int len = (int)strlen(hello)+1;
  1.4224 +	gzFile file;
  1.4225 +
  1.4226 +	const char * fname = TESTFILE;
  1.4227 +	file = gzopen(fname, "wb");
  1.4228 +	if (file == NULL) 
  1.4229 +		{
  1.4230 +		res = KErrGeneral; 
  1.4231 +		}
  1.4232 +	gzputc(file, 'h');
  1.4233 +	err = gzrewind(file);
  1.4234 +	if(err == 0)
  1.4235 +		{    	
  1.4236 +		res =  	 KErrGeneral;
  1.4237 +		}
  1.4238 +	else
  1.4239 +		{    	
  1.4240 +		res = KErrNone ;  
  1.4241 +		}
  1.4242 +	err=  gzclose(file);
  1.4243 +	if (err != Z_OK)  
  1.4244 +		{
  1.4245 +		res = KErrGeneral; 
  1.4246 +		} 
  1.4247 +
  1.4248 +	return res;
  1.4249 +	}
  1.4250 +
  1.4251 +TInt CTestZlib::TestGzdopen()
  1.4252 +	{
  1.4253 +	TInt res = KErrNone ;
  1.4254 +	int len = (int)strlen(hello)+1;
  1.4255 +	gzFile file;
  1.4256 +	const char * fname = TESTFILE ;
  1.4257 +	FILE*  fp = fopen(fname, "rb");
  1.4258 +	file = gzdopen(fileno(fp), "rb");
  1.4259 +	if (file == NULL)
  1.4260 +		{
  1.4261 +		res = Z_MEM_ERROR;
  1.4262 +		fclose(fp);
  1.4263 +		return res;
  1.4264 +		}
  1.4265 +	int err=  gzclose(file);
  1.4266 +	if (err != Z_OK)  
  1.4267 +		{
  1.4268 +		res = KErrGeneral; 
  1.4269 +		}
  1.4270 +	fclose(fp);
  1.4271 +	return res;
  1.4272 +	}
  1.4273 +
  1.4274 +
  1.4275 +TInt CTestZlib::TestGzdopen_fail()
  1.4276 +	{
  1.4277 +	TInt res = KErrNone ;
  1.4278 +	int len = (int)strlen(hello)+1;
  1.4279 +	gzFile file;
  1.4280 +	const char * fname = TESTFILE ;
  1.4281 +	FILE*  fp = fopen(fname, "rb");
  1.4282 +	file = gzdopen(fileno(fp), "xyz");
  1.4283 +	if (file == NULL) 
  1.4284 +		{
  1.4285 +		res=KErrNone; 
  1.4286 +		fclose(fp);
  1.4287 +		return res;
  1.4288 +		}
  1.4289 +	int err=  gzclose(file);
  1.4290 +	if (err == Z_OK)  
  1.4291 +		{
  1.4292 +		res = KErrGeneral; 
  1.4293 +		}  
  1.4294 +	fclose(fp);
  1.4295 +	return res;
  1.4296 +	}
  1.4297 +
  1.4298 +
  1.4299 +TInt CTestZlib::TestGzdopen_fail2()
  1.4300 +	{
  1.4301 +	TInt res = KErrNone ;
  1.4302 +	int len = (int)strlen(hello)+1;
  1.4303 +	gzFile file;
  1.4304 +	const char * fname = TESTFILE ;
  1.4305 +	FILE*  fp = fopen(fname, "rb");
  1.4306 +	file = gzdopen(-1, "xyz");
  1.4307 +	if (file == NULL) 
  1.4308 +		{ 
  1.4309 +		fclose(fp);
  1.4310 +		res=KErrNone;
  1.4311 +		return res;
  1.4312 +		}
  1.4313 +	int err=  gzclose(file);
  1.4314 +	if (err == Z_OK)  
  1.4315 +		{
  1.4316 +		res = KErrGeneral; 
  1.4317 +		}
  1.4318 +	fclose(fp);
  1.4319 +	return res;
  1.4320 +	}
  1.4321 +
  1.4322 +/* ===========================================================================
  1.4323 + * Test deflate() with full flush
  1.4324 + */
  1.4325 +TInt CTestZlib::Test_flush(   Byte * compr,uLong * comprLen)
  1.4326 +	{
  1.4327 +	TInt res = KErrNone ;
  1.4328 +	z_stream c_stream; /* compression stream */
  1.4329 +	int err;
  1.4330 +	uInt len = (uInt)strlen(hello)+1;
  1.4331 +
  1.4332 +	c_stream.zalloc = (alloc_func)0;
  1.4333 +	c_stream.zfree = (free_func)0;
  1.4334 +	c_stream.opaque = (voidpf)0;
  1.4335 +
  1.4336 +	err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
  1.4337 +	if(err<0)
  1.4338 +		{
  1.4339 +		return Z_MEM_ERROR;    	
  1.4340 +		}
  1.4341 +
  1.4342 +	c_stream.next_in  = (Bytef*)hello;
  1.4343 +	c_stream.next_out = compr;
  1.4344 +	c_stream.avail_in = 3;
  1.4345 +	c_stream.avail_out = (uInt)*comprLen;
  1.4346 +	err = deflate(&c_stream, Z_FULL_FLUSH);
  1.4347 +
  1.4348 +	int h=inflateSyncPoint(&c_stream);
  1.4349 +	compr[3]++; /* force an error in first compressed block */
  1.4350 +	c_stream.avail_in = len - 3;
  1.4351 +
  1.4352 +	err = deflate(&c_stream, Z_FINISH);
  1.4353 +	if (err != Z_STREAM_END)
  1.4354 +		{
  1.4355 +		res = KErrGeneral;
  1.4356 +		}
  1.4357 +	err = deflateEnd(&c_stream);  
  1.4358 +	if (err != 0) 
  1.4359 +		{
  1.4360 +		res = KErrGeneral;
  1.4361 +		}
  1.4362 +	*comprLen = c_stream.total_out;
  1.4363 +	return res;
  1.4364 +	}
  1.4365 +
  1.4366 +
  1.4367 +TInt test_sync(Byte * compr,uLong comprLen, Byte * uncompr,uLong uncomprLen)
  1.4368 +	{
  1.4369 +	TInt res = KErrNone ;
  1.4370 +	int err;
  1.4371 +	z_stream d_stream; /* decompression stream */
  1.4372 +
  1.4373 +	strcpy((char*)uncompr, "garbage");
  1.4374 +
  1.4375 +	d_stream.zalloc = (alloc_func)0;
  1.4376 +	d_stream.zfree = (free_func)0;
  1.4377 +	d_stream.opaque = (voidpf)0;
  1.4378 +
  1.4379 +	d_stream.next_in  = compr;
  1.4380 +	d_stream.avail_in = 2; /* just read the zlib header */
  1.4381 +
  1.4382 +	err = inflateInit(&d_stream);
  1.4383 +	if(err!=0)
  1.4384 +		{
  1.4385 +		res=KErrGeneral;
  1.4386 +		}
  1.4387 +	d_stream.next_out = uncompr;
  1.4388 +	d_stream.avail_out = (uInt)uncomprLen;
  1.4389 +
  1.4390 +	err=  inflate(&d_stream, Z_NO_FLUSH);
  1.4391 +	if(err!=0)
  1.4392 +		{
  1.4393 +		res=KErrGeneral;
  1.4394 +		}
  1.4395 +	d_stream.avail_in = (uInt)comprLen-2;   /* read all compressed data */
  1.4396 +	err = inflateSync(&d_stream);           /* but skip the damaged part */
  1.4397 +	if(err!=0)
  1.4398 +		{
  1.4399 +		res=KErrGeneral;
  1.4400 +		}
  1.4401 +	err = inflate(&d_stream, Z_FINISH);
  1.4402 +	if(err==0)
  1.4403 +		{
  1.4404 +		res=KErrGeneral;
  1.4405 +		}
  1.4406 +	err = inflateEnd(&d_stream);
  1.4407 +	if(err!=0)
  1.4408 +		{
  1.4409 +		res=KErrGeneral;
  1.4410 +		}
  1.4411 +	return res;
  1.4412 +	}
  1.4413 +
  1.4414 +
  1.4415 +TInt CTestZlib::TestInflateSync()
  1.4416 +	{   
  1.4417 +	TInt res = KErrNone ;
  1.4418 +	uLong len = (uLong)strlen(hello)+1;
  1.4419 +
  1.4420 +	Byte *compr, *uncompr;
  1.4421 +	uLong comprLen = 20*sizeof(int); 
  1.4422 +	uLong uncomprLen = comprLen;
  1.4423 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.4424 +	if (compr == Z_NULL)
  1.4425 +		{
  1.4426 +		return KErrNoMemory;
  1.4427 +		}
  1.4428 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.4429 +	if(uncompr == Z_NULL) 
  1.4430 +		{
  1.4431 +		free(compr);
  1.4432 +		return KErrNoMemory;
  1.4433 +		}
  1.4434 +	res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  1.4435 +	if(res<0)
  1.4436 +		{
  1.4437 +		free(compr);
  1.4438 +		free(uncompr);
  1.4439 +		return KErrNoMemory;	
  1.4440 +		}
  1.4441 +	Test_flush(compr, &comprLen);
  1.4442 +	res = test_sync(compr, comprLen, uncompr, uncomprLen);
  1.4443 +	free(compr);
  1.4444 +	free(uncompr);
  1.4445 +	return res;
  1.4446 +	}
  1.4447 +
  1.4448 +
  1.4449 +TInt CTestZlib::TestinflateSyncfail()
  1.4450 +	{   
  1.4451 +	TInt res = KErrNone ;
  1.4452 +	uLong len = (uLong)strlen(hello)+1;
  1.4453 +
  1.4454 +	Byte *compr, *uncompr;
  1.4455 +	uLong comprLen = 20*sizeof(int); 
  1.4456 +	uLong uncomprLen = comprLen;
  1.4457 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.4458 +	if (compr == Z_NULL)
  1.4459 +		{
  1.4460 +		return KErrNoMemory;
  1.4461 +		}
  1.4462 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.4463 +	if (uncompr == Z_NULL) 
  1.4464 +		{
  1.4465 +		free(compr);
  1.4466 +		return KErrNoMemory;
  1.4467 +		}
  1.4468 +
  1.4469 +	res= test_compress_positive(compr, comprLen, uncompr, uncomprLen);
  1.4470 +	if(res<0)
  1.4471 +		{
  1.4472 +		free(compr);
  1.4473 +		free(uncompr);
  1.4474 +		return KErrNoMemory;	
  1.4475 +		}
  1.4476 +	int err = test_sync(compr, comprLen, uncompr, uncomprLen);
  1.4477 +	if(err!=0)
  1.4478 +		{
  1.4479 +		res = KErrNone ;
  1.4480 +		}    
  1.4481 +	else
  1.4482 +		{
  1.4483 +		res = KErrGeneral;
  1.4484 +		}    
  1.4485 +	free(compr);
  1.4486 +	free(uncompr);
  1.4487 +	return res;
  1.4488 +	}
  1.4489 +
  1.4490 +
  1.4491 +int  test_syncpoint (Bytef *dest,  uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
  1.4492 +	{
  1.4493 +	TInt res = KErrNone ;
  1.4494 +	z_stream stream;
  1.4495 +	int err;
  1.4496 +
  1.4497 +	stream.next_in = (Bytef*)source;
  1.4498 +	stream.avail_in = (uInt)sourceLen;
  1.4499 +	stream.next_out = dest;
  1.4500 +	stream.avail_out = (uInt)*destLen;
  1.4501 +
  1.4502 +	stream.zalloc = (alloc_func)0;
  1.4503 +	stream.zfree = (free_func)0;
  1.4504 +	stream.opaque = (voidpf)0;
  1.4505 +
  1.4506 +	err = deflateInit(&stream, level);
  1.4507 +	if (err != Z_OK) return err;    
  1.4508 +
  1.4509 +	err = deflate(&stream, Z_FINISH);
  1.4510 +	if (err != Z_STREAM_END) 
  1.4511 +		{
  1.4512 +		deflateEnd(&stream);
  1.4513 +		return err == Z_OK ? Z_BUF_ERROR : err;
  1.4514 +		}
  1.4515 +	*destLen = stream.total_out;    
  1.4516 +	int h=inflateSyncPoint(&stream);
  1.4517 +	if(h!=0)
  1.4518 +		{
  1.4519 +		res=KErrGeneral;
  1.4520 +		}
  1.4521 +	deflateEnd(&stream);
  1.4522 +	return res;
  1.4523 +	}
  1.4524 +
  1.4525 +
  1.4526 +TInt CTestZlib::TestInflateSyncPoint()
  1.4527 +	{
  1.4528 +	TInt res = KErrNone ;
  1.4529 +	uLong len = (uLong)strlen(hello)+1;
  1.4530 +	Byte *compr, *uncompr;
  1.4531 +	uLong comprLen = 20*sizeof(int); 
  1.4532 +	uLong uncomprLen = comprLen;
  1.4533 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.4534 +	if (compr == Z_NULL)
  1.4535 +		{
  1.4536 +		return KErrNoMemory;
  1.4537 +		}
  1.4538 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.4539 +	if (uncompr == Z_NULL) 
  1.4540 +		{
  1.4541 +		free(compr);
  1.4542 +		return KErrNoMemory;
  1.4543 +		}
  1.4544 +	res= test_syncpoint(compr, &comprLen, (const Bytef*)hello, len,Z_DEFAULT_COMPRESSION);
  1.4545 +	free(compr);
  1.4546 +	free(uncompr);
  1.4547 +	return res;
  1.4548 +	}
  1.4549 +
  1.4550 +TInt CTestZlib::TestInflateSyncPoint_null()
  1.4551 +	{
  1.4552 +	TInt res = KErrNone ;
  1.4553 +	uLong len = (uLong)strlen(hello)+1;
  1.4554 +	Byte *compr, *uncompr;
  1.4555 +	uLong comprLen = 20*sizeof(int); 
  1.4556 +	uLong uncomprLen = comprLen;
  1.4557 +	compr    = (Byte*)calloc((uInt)comprLen, 1);
  1.4558 +	if (compr == Z_NULL)
  1.4559 +		{
  1.4560 +		return KErrNoMemory;
  1.4561 +		}
  1.4562 +	uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
  1.4563 +	if (uncompr == Z_NULL) 
  1.4564 +		{
  1.4565 +		free(compr);
  1.4566 +		return KErrNoMemory;
  1.4567 +		}
  1.4568 +	int h=inflateSyncPoint(NULL);
  1.4569 +	if(h==0)
  1.4570 +		{
  1.4571 +		res=KErrGeneral;
  1.4572 +		}
  1.4573 +	free(compr);
  1.4574 +	free(uncompr);
  1.4575 +	return res;
  1.4576 +	}
  1.4577 +
  1.4578 +
  1.4579 +TInt CTestZlib::TestZerror()
  1.4580 +	{
  1.4581 +	TInt res = KErrNone ;
  1.4582 +	const char * s = zError(1);
  1.4583 +	if(strcmp(s,"stream end"))
  1.4584 +		{
  1.4585 +		res=KErrGeneral;
  1.4586 +		}
  1.4587 +	return res;
  1.4588 +	}
  1.4589 +
  1.4590 +TInt CTestZlib::TestZerror1()
  1.4591 +	{
  1.4592 +	TInt res = KErrNone ;
  1.4593 +	const char * s = zError(-3);
  1.4594 +	if(strcmp(s,"data error"))
  1.4595 +		{
  1.4596 +		res=KErrGeneral;
  1.4597 +		}
  1.4598 +
  1.4599 +	return res;
  1.4600 +	} 
  1.4601 +
  1.4602 +TInt CTestZlib::TestZerror2()
  1.4603 +	{
  1.4604 +	TInt res = KErrNone ;
  1.4605 +	const char * s = zError(0);
  1.4606 +	if(strcmp(s,""))
  1.4607 +		{
  1.4608 +		res=KErrGeneral;
  1.4609 +		}
  1.4610 +
  1.4611 +	return res;
  1.4612 +	}
  1.4613 +