os/ossrv/compressionlibs/ziplib/test/tef/tlibz/src/tzlibcases.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/tzlibcases.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2602 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Name        : tzlibcases.cpp
    1.18 +// 
    1.19 +//
    1.20 +#include <errno.h>
    1.21 +#include "tzlib.h"
    1.22 +
    1.23 +#define CHECK_ERR(err, msg) { \
    1.24 +    if (err != Z_OK) { \
    1.25 +       INFO_PRINTF2(_L("Error: %d"), err); \
    1.26 +        return err; \
    1.27 +    } \
    1.28 +}
    1.29 +
    1.30 +// -----------------------------------------------------------------------------
    1.31 +//Function Name :ReadStringParam
    1.32 +//Description:Reads string from ini file
    1.33 +//Param : aString is populated with the read string
    1.34 +// -----------------------------------------------------------------------------	
    1.35 +void CTestZlib::ReadStringParam(char* aString)
    1.36 +	{
    1.37 +	_LIT( Kparam, "Param%d" );
    1.38 +	TBuf<100> pNameBuf;
    1.39 +	TPtrC descriptor;
    1.40 +	TInt i;
    1.41 +
    1.42 +	pNameBuf.Format (Kparam, ++iParamCnt);
    1.43 +	TBool ret = GetStringFromConfig (ConfigSection (), pNameBuf, descriptor);
    1.44 +	if ( descriptor == _L("\"\""))
    1.45 +		{
    1.46 +		i = 0;
    1.47 +		}
    1.48 +	else
    1.49 +		{
    1.50 +		// If the string is quoted, take only the insides
    1.51 +		if ( (descriptor[0] == '\"') && (descriptor[descriptor.Length()-1] == '\"'))
    1.52 +			{
    1.53 +			for (i=0; i<descriptor.Length ()-2; i++)
    1.54 +				{
    1.55 +				aString[i]=descriptor[i+1];
    1.56 +				}
    1.57 +			}
    1.58 +		// Otherwise,take the whole string
    1.59 +		else
    1.60 +			{
    1.61 +			for (i=0; i<descriptor.Length (); i++)
    1.62 +				{
    1.63 +				aString[i]=descriptor[i];
    1.64 +				}
    1.65 +			}
    1.66 +		}
    1.67 +
    1.68 +	aString[i]='\0';
    1.69 +	}
    1.70 +
    1.71 +// -----------------------------------------------------------------------------
    1.72 +//Function Name : ReadIntParam
    1.73 +//TestCase Description:Reads Int value from ini file
    1.74 +//Param : TInt to receive the read integer 
    1.75 +// -----------------------------------------------------------------------------
    1.76 +void CTestZlib::ReadIntParam(TInt &aInt)
    1.77 +	{
    1.78 +	_LIT( Kparam, "Param%d" );
    1.79 +	TBuf<8> pNameBuf;
    1.80 +	TPtrC string;
    1.81 +	pNameBuf.Format (Kparam, ++iParamCnt);
    1.82 +	TBool res = GetIntFromConfig (ConfigSection (), pNameBuf, aInt);
    1.83 +	}
    1.84 +
    1.85 +//---------------/*COMPRESS AND UNCOMPRESS*/----------------------------------
    1.86 +
    1.87 +TInt CTestZlib::sec_compress(Byte * compr, uLong comprLen, Byte * uncompr,
    1.88 +		uLong uncomprLen)
    1.89 +	{
    1.90 +
    1.91 +	int err;
    1.92 +	const char hello[] = "hello, hello!";
    1.93 +	uLong len = (uLong)strlen(hello)+1;
    1.94 +
    1.95 +	err = compress (compr, &comprLen, (const Bytef*)hello, len);
    1.96 +	CHECK_ERR(err, "compress");
    1.97 +
    1.98 +	strcpy ((char*)uncompr, "garbage");
    1.99 +
   1.100 +	err = uncompress (uncompr, &uncomprLen, compr, comprLen);
   1.101 +	CHECK_ERR(err, "uncompress");
   1.102 +
   1.103 +	if ( strcmp ((char*)uncompr, hello))
   1.104 +		{
   1.105 +		printf ("Bad uncompress");
   1.106 +		return KErrGeneral;
   1.107 +		}
   1.108 +	else
   1.109 +		{
   1.110 +		printf ("uncompress(): %s", (char *)uncompr);
   1.111 +		}
   1.112 +	return err;
   1.113 +	}
   1.114 +
   1.115 +//------------------------------//deflateSetDictionary//-----------------------------------
   1.116 +
   1.117 +TInt CTestZlib::sec_deflateSetDictionary01(Byte * compr, uLong comprLen,
   1.118 +		TInt flush, TInt compression)
   1.119 +	{
   1.120 +	z_stream c_stream; // compression stream 
   1.121 +	int err;
   1.122 +	const char hello[] = "hello, hello!";
   1.123 +	uLong len = (uLong)strlen(hello)+1;
   1.124 +	const Bytef* dictionary=(const Bytef *) hello;
   1.125 +	c_stream.zalloc = (alloc_func)0;
   1.126 +	c_stream.zfree = (free_func)0;
   1.127 +	c_stream.opaque = (voidpf)0;
   1.128 +
   1.129 +	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
   1.130 +
   1.131 +	if ( err != Z_OK)
   1.132 +		{
   1.133 +		INFO_PRINTF2(_L("deflateInit error: %d"), err);
   1.134 +		return err;
   1.135 +		}
   1.136 +	err = deflateSetDictionary (&c_stream, dictionary, 3);
   1.137 +	if ( err != Z_OK)
   1.138 +		{
   1.139 +		ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
   1.140 +		deflateEnd (&c_stream);
   1.141 +		return err;
   1.142 +		}
   1.143 +	c_stream.next_in = (Bytef*)hello;
   1.144 +	c_stream.next_out = compr;
   1.145 +
   1.146 +	while (c_stream.total_in != len && c_stream.total_out < comprLen)
   1.147 +		{
   1.148 +		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
   1.149 +		err = deflate (&c_stream, flush);
   1.150 +		if ( err != Z_OK)
   1.151 +			{
   1.152 +			INFO_PRINTF2(_L("deflate return code: %d"), err);
   1.153 +			deflateEnd (&c_stream);
   1.154 +			return err;
   1.155 +			}
   1.156 +		}
   1.157 +	// Finish the stream, still forcing small buffers: 
   1.158 +	for (;;)
   1.159 +		{
   1.160 +		c_stream.avail_out = 1;
   1.161 +		err = deflate (&c_stream, Z_FINISH);
   1.162 +		if ( err == Z_STREAM_END)
   1.163 +			break;
   1.164 +		if ( err != Z_OK)
   1.165 +			{
   1.166 +			INFO_PRINTF2(_L("deflate error: %d"), err);
   1.167 +			deflateEnd (&c_stream);
   1.168 +			return err;
   1.169 +			}
   1.170 +		}
   1.171 +
   1.172 +	deflateEnd (&c_stream);
   1.173 +	return KErrNone;
   1.174 +	}
   1.175 +
   1.176 +TInt CTestZlib::sec_deflateSetDictionary02(TInt compression)
   1.177 +	{
   1.178 +	z_stream c_stream; // compression stream 
   1.179 +	int err;
   1.180 +	const char hello[] = "hello, hello!";
   1.181 +	uLong len = (uLong)strlen(hello)+1;
   1.182 +	const Bytef* dictionary=NULL;
   1.183 +	c_stream.zalloc = (alloc_func)0;
   1.184 +	c_stream.zfree = (free_func)0;
   1.185 +	c_stream.opaque = (voidpf)0;
   1.186 +
   1.187 +	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
   1.188 +
   1.189 +	if ( err != Z_OK)
   1.190 +		{
   1.191 +		INFO_PRINTF2(_L("deflateInit error: %d"), err);
   1.192 +		return err;
   1.193 +		}
   1.194 +	err = deflateSetDictionary (&c_stream, dictionary, 30);
   1.195 +	if ( err != Z_OK)
   1.196 +		{
   1.197 +		ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
   1.198 +		deflateEnd (&c_stream);
   1.199 +		return err;
   1.200 +		}
   1.201 +	deflateEnd (&c_stream);
   1.202 +	return KErrNone;
   1.203 +	}
   1.204 +
   1.205 +//------------------------------//deflateSetDictionary//-----------------------------------
   1.206 +
   1.207 +TInt CTestZlib::sec_deflateSetDictionary03(Byte * compr, uLong comprLen,
   1.208 +		TInt flush, TInt compression)
   1.209 +	{
   1.210 +	z_stream c_stream; // compression stream 
   1.211 +	int err;
   1.212 +	const char hello[] = "hello, hello!";
   1.213 +	uLong len = (uLong)strlen(hello)+1;
   1.214 +	const Bytef* dictionary=(const Bytef *) hello;
   1.215 +	c_stream.zalloc = (alloc_func)0;
   1.216 +	c_stream.zfree = (free_func)0;
   1.217 +	c_stream.opaque = (voidpf)0;
   1.218 +
   1.219 +	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
   1.220 +
   1.221 +	if ( err != Z_OK)
   1.222 +		{
   1.223 +		INFO_PRINTF2(_L("deflateInit error: %d"), err);
   1.224 +		return err;
   1.225 +		}
   1.226 +	c_stream.next_in = (Bytef*)hello;
   1.227 +	c_stream.next_out = compr;
   1.228 +
   1.229 +	while (c_stream.total_in != len && c_stream.total_out < comprLen)
   1.230 +		{
   1.231 +		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
   1.232 +		err = deflate (&c_stream, flush);
   1.233 +		if ( err != Z_OK)
   1.234 +			{
   1.235 +			INFO_PRINTF2(_L("deflate return code: %d"), err);
   1.236 +			deflateEnd (&c_stream);
   1.237 +			return err;
   1.238 +			}
   1.239 +		}
   1.240 +	// Finish the stream, still forcing small buffers: 
   1.241 +	for (;;)
   1.242 +		{
   1.243 +		c_stream.avail_out = 1;
   1.244 +		err = deflate (&c_stream, Z_FINISH);
   1.245 +		if ( err == Z_STREAM_END)
   1.246 +			break;
   1.247 +		if ( err != Z_OK)
   1.248 +			{
   1.249 +			INFO_PRINTF2(_L("deflate error: %d"), err);
   1.250 +			deflateEnd (&c_stream);
   1.251 +			return err;
   1.252 +			}
   1.253 +		}
   1.254 +
   1.255 +	deflateEnd (&c_stream);
   1.256 +	err = deflateSetDictionary (&c_stream, dictionary, 30);
   1.257 +	if ( err != Z_OK)
   1.258 +		{
   1.259 +		ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
   1.260 +		return err;
   1.261 +		}
   1.262 +
   1.263 +	return KErrNone;
   1.264 +	}
   1.265 +
   1.266 +TInt CTestZlib::sec_deflateSetDictionary04(Byte * compr, uLong comprLen,
   1.267 +		TInt flush, TInt compression)
   1.268 +	{
   1.269 +	z_stream c_stream; // compression stream 
   1.270 +	int err;
   1.271 +	const char hello[] = "hello, hello!";
   1.272 +	uLong len = (uLong)strlen(hello)+1;
   1.273 +	const char dict[] = "z";
   1.274 +
   1.275 +	const Bytef* dictionary=(const Bytef *) dict;
   1.276 +	c_stream.zalloc = (alloc_func)0;
   1.277 +	c_stream.zfree = (free_func)0;
   1.278 +	c_stream.opaque = (voidpf)0;
   1.279 +
   1.280 +	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
   1.281 +
   1.282 +	if ( err != Z_OK)
   1.283 +		{
   1.284 +		INFO_PRINTF2(_L("deflateInit error: %d"), err);
   1.285 +		return err;
   1.286 +		}
   1.287 +	err = deflateSetDictionary (&c_stream, dictionary, (uLong)strlen(dict)+1);
   1.288 +	if ( err != Z_OK)
   1.289 +		{
   1.290 +		ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
   1.291 +		deflateEnd (&c_stream);
   1.292 +		return err;
   1.293 +		}
   1.294 +	c_stream.next_in = (Bytef*)hello;
   1.295 +	c_stream.next_out = compr;
   1.296 +
   1.297 +	while (c_stream.total_in != len && c_stream.total_out < comprLen)
   1.298 +		{
   1.299 +		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
   1.300 +		err = deflate (&c_stream, flush);
   1.301 +		if ( err != Z_OK)
   1.302 +			{
   1.303 +			INFO_PRINTF2(_L("deflate return code: %d"), err);
   1.304 +			deflateEnd (&c_stream);
   1.305 +			return err;
   1.306 +			}
   1.307 +		}
   1.308 +	// Finish the stream, still forcing small buffers: 
   1.309 +	for (;;)
   1.310 +		{
   1.311 +		c_stream.avail_out = 1;
   1.312 +		err = deflate (&c_stream, Z_FINISH);
   1.313 +		if ( err == Z_STREAM_END)
   1.314 +			break;
   1.315 +		if ( err != Z_OK)
   1.316 +			{
   1.317 +			INFO_PRINTF2(_L("deflate error: %d"), err);
   1.318 +			deflateEnd (&c_stream);
   1.319 +			return err;
   1.320 +			}
   1.321 +		}
   1.322 +
   1.323 +	deflateEnd (&c_stream);
   1.324 +	return KErrNone;
   1.325 +	}
   1.326 +
   1.327 +TInt CTestZlib::sec_deflateSetDictionary05(Byte * compr, uLong comprLen,
   1.328 +		TInt flush, TInt compression)
   1.329 +	{
   1.330 +	z_stream c_stream; // compression stream 
   1.331 +	int err;
   1.332 +	const char hello[] = "hello, hello!";
   1.333 +	uLong len = (uLong)strlen(hello)+1;
   1.334 +	const char
   1.335 +			dict[] = "abcdefghijklmnopqrstuvwxyz \
   1.336 +    abcdefghijklmnopqrstuvwxyz \
   1.337 +    abcdefghijklmnopqrstuvwxyz \
   1.338 +    abcdefghijklmnopqrstuvwxyz \
   1.339 +    abcdefghijklmnopqrstuvwxyz \
   1.340 +    abcdefghijklmnopqrstuvwxyz \
   1.341 +    abcdefghijklmnopqrstuvwxyz \
   1.342 +    abcdefghijklmnopqrstuvwxyz \
   1.343 +    abcdefghijklmnopqrstuvwxyz \
   1.344 +    abcdefghijklmnopqrstuvwxyz";
   1.345 +
   1.346 +	const Bytef* dictionary=(const Bytef *) dict;
   1.347 +	c_stream.zalloc = (alloc_func)0;
   1.348 +	c_stream.zfree = (free_func)0;
   1.349 +	c_stream.opaque = (voidpf)0;
   1.350 +
   1.351 +	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
   1.352 +
   1.353 +	if ( err != Z_OK)
   1.354 +		{
   1.355 +		INFO_PRINTF2(_L("deflateInit error: %d"), err);
   1.356 +		return err;
   1.357 +		}
   1.358 +	err = deflateSetDictionary (&c_stream, dictionary, (uLong)strlen(dict)+1);
   1.359 +	if ( err != Z_OK)
   1.360 +		{
   1.361 +		ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
   1.362 +		deflateEnd (&c_stream);
   1.363 +		return err;
   1.364 +		}
   1.365 +	c_stream.next_in = (Bytef*)hello;
   1.366 +	c_stream.next_out = compr;
   1.367 +
   1.368 +	while (c_stream.total_in != len && c_stream.total_out < comprLen)
   1.369 +		{
   1.370 +		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
   1.371 +		err = deflate (&c_stream, flush);
   1.372 +		if ( err != Z_OK)
   1.373 +			{
   1.374 +			INFO_PRINTF2(_L("deflate return code: %d"), err);
   1.375 +			deflateEnd (&c_stream);
   1.376 +			return err;
   1.377 +			}
   1.378 +		}
   1.379 +	// Finish the stream, still forcing small buffers: 
   1.380 +	for (;;)
   1.381 +		{
   1.382 +		c_stream.avail_out = 1;
   1.383 +		err = deflate (&c_stream, Z_FINISH);
   1.384 +		if ( err == Z_STREAM_END)
   1.385 +			break;
   1.386 +		if ( err != Z_OK)
   1.387 +			{
   1.388 +			INFO_PRINTF2(_L("deflate error: %d"), err);
   1.389 +			deflateEnd (&c_stream);
   1.390 +			return err;
   1.391 +			}
   1.392 +		}
   1.393 +
   1.394 +	deflateEnd (&c_stream);
   1.395 +	return KErrNone;
   1.396 +	}
   1.397 +//------------------------------//DEFLATE//-----------------------------------
   1.398 +
   1.399 +TInt CTestZlib::sec_deflate01( Byte * compr, uLong comprLen, TInt flush,
   1.400 +		TInt compression)
   1.401 +	{
   1.402 +	z_stream c_stream; // compression stream 
   1.403 +	int err;
   1.404 +	const char hello[] = "hello, hello!";
   1.405 +	uLong len = (uLong)strlen(hello)+1;
   1.406 +
   1.407 +	c_stream.zalloc = (alloc_func)0;
   1.408 +	c_stream.zfree = (free_func)0;
   1.409 +	c_stream.opaque = (voidpf)0;
   1.410 +
   1.411 +	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
   1.412 +
   1.413 +	if ( err != Z_OK)
   1.414 +		{
   1.415 +		INFO_PRINTF2(_L("deflateInit error: %d"), err);
   1.416 +		return err;
   1.417 +		}
   1.418 +
   1.419 +	c_stream.next_in = (Bytef*)hello;
   1.420 +	c_stream.next_out = compr;
   1.421 +
   1.422 +	while (c_stream.total_in != len && c_stream.total_out < comprLen)
   1.423 +		{
   1.424 +		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
   1.425 +		err = deflate (&c_stream, flush);
   1.426 +		if ( err != Z_OK)
   1.427 +			{
   1.428 +			INFO_PRINTF2(_L("deflate return code: %d"), err);
   1.429 +			deflateEnd (&c_stream);
   1.430 +			return err;
   1.431 +			}
   1.432 +		}
   1.433 +	// Finish the stream, still forcing small buffers: 
   1.434 +	for (;;)
   1.435 +		{
   1.436 +		c_stream.avail_out = 1;
   1.437 +		err = deflate (&c_stream, Z_FINISH);
   1.438 +		if ( err == Z_STREAM_END)
   1.439 +			break;
   1.440 +		if ( err != Z_OK)
   1.441 +			{
   1.442 +			INFO_PRINTF2(_L("deflate error: %d"), err);
   1.443 +			deflateEnd (&c_stream);
   1.444 +			return err;
   1.445 +			}
   1.446 +		}
   1.447 +
   1.448 +	deflateEnd (&c_stream);
   1.449 +	return KErrNone;
   1.450 +	}
   1.451 +
   1.452 +TInt CTestZlib::sec_deflate02( Byte * compr, uLong comprLen, TInt flush,
   1.453 +		TInt compression)
   1.454 +	{
   1.455 +	z_stream c_stream; // compression stream 
   1.456 +	int err;
   1.457 +	const char hello[] = "hello, hello!";
   1.458 +	uLong len = (uLong)strlen(hello)+1;
   1.459 +
   1.460 +	c_stream.zalloc = (alloc_func)0;
   1.461 +	c_stream.zfree = (free_func)0;
   1.462 +	c_stream.opaque = (voidpf)0;
   1.463 +
   1.464 +	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
   1.465 +
   1.466 +	if ( err != Z_OK)
   1.467 +		{
   1.468 +		INFO_PRINTF2(_L("deflateInit error: %d"), err);
   1.469 +		return err;
   1.470 +		}
   1.471 +
   1.472 +	c_stream.next_in = (Bytef*)hello;
   1.473 +	c_stream.next_out = compr;
   1.474 +
   1.475 +	while (c_stream.total_in != len && c_stream.total_out < comprLen)
   1.476 +		{
   1.477 +		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
   1.478 +		err = deflate (&c_stream, Z_NO_FLUSH);
   1.479 +		if ( err != Z_OK)
   1.480 +			{
   1.481 +			INFO_PRINTF2(_L("deflate return code: %d"), err);
   1.482 +			deflateEnd (&c_stream);
   1.483 +			return err;
   1.484 +			}
   1.485 +		}
   1.486 +	// Finish the stream, still forcing small buffers: 
   1.487 +	for (;;)
   1.488 +		{
   1.489 +		c_stream.avail_out = 1;
   1.490 +		err = deflate (&c_stream, Z_FINISH);
   1.491 +		if ( err == Z_STREAM_END)
   1.492 +			break;
   1.493 +		if ( err != Z_OK)
   1.494 +			{
   1.495 +			INFO_PRINTF2(_L("deflate error: %d"), err);
   1.496 +			deflateEnd (&c_stream);
   1.497 +			return err;
   1.498 +			}
   1.499 +		}
   1.500 +
   1.501 +	//deflate call after a finish
   1.502 +	err = deflate (&c_stream, flush);
   1.503 +	deflateEnd (&c_stream);
   1.504 +	return err;
   1.505 +	}
   1.506 +//-------------------------------/INFLATE/----------------------------------
   1.507 +
   1.508 +TInt CTestZlib::sec_inflate( Byte * compr, uLong comprLen, Byte * uncompr,
   1.509 +		uLong uncomprLen, TInt flush)
   1.510 +	{
   1.511 +	int err;
   1.512 +	const char hello[] = "hello, hello!";
   1.513 +	z_stream d_stream; // decompression stream 
   1.514 +
   1.515 +	//strcpy((char*)uncompr, "garbage");
   1.516 +
   1.517 +	d_stream.zalloc = (alloc_func)0;
   1.518 +	d_stream.zfree = (free_func)0;
   1.519 +	d_stream.opaque = (voidpf)0;
   1.520 +
   1.521 +	d_stream.next_in = compr;
   1.522 +	d_stream.avail_in = 0;
   1.523 +	d_stream.next_out = uncompr;
   1.524 +
   1.525 +	err = inflateInit (&d_stream);
   1.526 +	CHECK_ERR(err, "inflateInit");
   1.527 +
   1.528 +	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
   1.529 +		{
   1.530 +		d_stream.avail_in = d_stream.avail_out = 1; // force small buffers 
   1.531 +		err = inflate (&d_stream, flush);
   1.532 +		if ( err == Z_STREAM_END)
   1.533 +			break;
   1.534 +		if ( err != Z_OK)
   1.535 +			{
   1.536 +			inflateEnd (&d_stream);
   1.537 +			return err;
   1.538 +			}
   1.539 +		}
   1.540 +
   1.541 +	err = inflateEnd (&d_stream);
   1.542 +	CHECK_ERR(err, "inflateEnd");
   1.543 +
   1.544 +	if ( strcmp ((char*)uncompr, hello))
   1.545 +		{
   1.546 +		ERR_PRINTF1(_L("Bad inflate"));
   1.547 +		return KErrGeneral;
   1.548 +		}
   1.549 +	else
   1.550 +		{
   1.551 +		INFO_PRINTF1(_L("inflate success"));
   1.552 +		}
   1.553 +	return 0;
   1.554 +	}
   1.555 +
   1.556 +//256K buffer size to hold streams
   1.557 +TInt CTestZlib::sec_inflate_large_buf( Byte * compr, uLong comprLen,
   1.558 +		Byte * uncompr, uLong uncomprLen, TInt flush)
   1.559 +	{
   1.560 +	int err;
   1.561 +	const char hello[] = "hello, hello!";
   1.562 +	z_stream d_stream; // decompression stream 
   1.563 +
   1.564 +	//strcpy((char*)uncompr, "garbage");
   1.565 +
   1.566 +	d_stream.zalloc = (alloc_func)0;
   1.567 +	d_stream.zfree = (free_func)0;
   1.568 +	d_stream.opaque = (voidpf)0;
   1.569 +
   1.570 +	d_stream.next_in = compr;
   1.571 +	d_stream.avail_in = 0;
   1.572 +	d_stream.next_out = uncompr;
   1.573 +
   1.574 +	err = inflateInit (&d_stream);
   1.575 +	CHECK_ERR(err, "inflateInit");
   1.576 +
   1.577 +	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
   1.578 +		{
   1.579 +		d_stream.avail_in = d_stream.avail_out = 262144; // 256K
   1.580 +		err = inflate (&d_stream, flush);
   1.581 +		if ( err == Z_STREAM_END)
   1.582 +			break;
   1.583 +		if ( err != Z_OK)
   1.584 +			{
   1.585 +			inflateEnd (&d_stream);
   1.586 +			return err;
   1.587 +			}
   1.588 +		}
   1.589 +
   1.590 +	err = inflateEnd (&d_stream);
   1.591 +	CHECK_ERR(err, "inflateEnd");
   1.592 +
   1.593 +	if ( strcmp ((char*)uncompr, hello))
   1.594 +		{
   1.595 +		ERR_PRINTF1(_L("Bad inflate"));
   1.596 +		return KErrGeneral;
   1.597 +		}
   1.598 +	else
   1.599 +		{
   1.600 +		INFO_PRINTF1(_L("inflate success"));
   1.601 +		}
   1.602 +	return 0;
   1.603 +	}
   1.604 +
   1.605 +//----------------------------//GZ OPERATION//--------------------------------
   1.606 +
   1.607 +TInt CTestZlib::sec_gzio( const char *fname, Byte * uncompr, uLong uncomprLen)
   1.608 +	{
   1.609 +#ifdef NO_GZCOMPRESS
   1.610 +	ERR_PRINTF1(_L("NO_GZCOMPRESS -- gz* functions cannot compress"));
   1.611 +#else
   1.612 +	const char hello[] = "hello, hello!";
   1.613 +	int len = (int)strlen(hello)+1;
   1.614 +	gzFile file;
   1.615 +	z_off_t pos;
   1.616 +
   1.617 +	file = gzopen (fname, "wb");
   1.618 +	if ( file == NULL)
   1.619 +		{
   1.620 +		ERR_PRINTF1(_L("gzopen error"));
   1.621 +		return KErrGeneral;
   1.622 +		}
   1.623 +	gzputc (file, 'h');
   1.624 +	if ( gzputs (file, "ello")!= 4)
   1.625 +		{
   1.626 +		gzclose (file);
   1.627 +		ERR_PRINTF1(_L("gzputs err"));
   1.628 +		return KErrGeneral;
   1.629 +		}
   1.630 +	if ( gzprintf (file, ", %s!", "hello")!= 8)
   1.631 +		{
   1.632 +		gzclose (file);
   1.633 +		ERR_PRINTF1(_L("gzprintf err:"));
   1.634 +		return KErrGeneral;
   1.635 +		}
   1.636 +
   1.637 +	gzseek (file, 1L, SEEK_CUR); // add one zero byte 
   1.638 +	gzclose (file);
   1.639 +
   1.640 +	file = gzopen (fname, "rb");
   1.641 +	if ( file == NULL)
   1.642 +		{
   1.643 +		ERR_PRINTF1(_L("gzopen error"));
   1.644 +		return KErrGeneral;
   1.645 +		}
   1.646 +	strcpy ((char*)uncompr, "garbage");
   1.647 +
   1.648 +	if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len)
   1.649 +		{
   1.650 +		gzclose (file);
   1.651 +		ERR_PRINTF1(_L("gzread err"));
   1.652 +		return KErrGeneral;
   1.653 +		}
   1.654 +
   1.655 +	if ( strcmp ((char*)uncompr, hello))
   1.656 +		{
   1.657 +		gzclose (file);
   1.658 +		ERR_PRINTF1(_L("bad gzread"));
   1.659 +		return KErrGeneral;
   1.660 +		}
   1.661 +
   1.662 +	pos = gzseek (file, -8L, SEEK_CUR);
   1.663 +	if ( pos != 6 || gztell (file)!= pos)
   1.664 +		{
   1.665 +		gzclose (file);
   1.666 +		ERR_PRINTF3(_L("gzseek error, pos=%ld, gztell=%ld"),(long)pos, (long)gztell(file));
   1.667 +		return KErrGeneral;
   1.668 +		}
   1.669 +
   1.670 +	if ( gzgetc (file)!= ' ')
   1.671 +		{
   1.672 +		gzclose (file);
   1.673 +		ERR_PRINTF1(_L("gzgetc error"));
   1.674 +		return KErrGeneral;
   1.675 +		}
   1.676 +
   1.677 +	if ( gzungetc (' ', file)!= ' ')
   1.678 +		{
   1.679 +		gzclose (file);
   1.680 +		ERR_PRINTF1(_L("gzungetc error"));
   1.681 +		return KErrGeneral;
   1.682 +		}
   1.683 +
   1.684 +	gzgets (file, (char*)uncompr, (int)uncomprLen);
   1.685 +
   1.686 +	if ( strlen ((char*)uncompr)!= 7)
   1.687 +		{
   1.688 +		gzclose (file);
   1.689 +		// " hello!" 
   1.690 +		ERR_PRINTF1(_L("gzgets err after gzseek"));
   1.691 +		return KErrGeneral;
   1.692 +		}
   1.693 +
   1.694 +	if ( strcmp ((char*)uncompr, hello + 6))
   1.695 +		{
   1.696 +		gzclose (file);
   1.697 +		ERR_PRINTF1(_L("bad gzgets after gzseek"));
   1.698 +		return KErrGeneral;
   1.699 +		}
   1.700 +
   1.701 +	gzclose (file);
   1.702 +#endif
   1.703 +	return KErrNone;
   1.704 +	}
   1.705 +
   1.706 +TInt CTestZlib::Test_zlibVersion()
   1.707 +	{
   1.708 +	INFO_PRINTF1(_L("Zlib Test zlibVersion"));
   1.709 +	int retVal = 0;
   1.710 +
   1.711 +	const char *version = zlibVersion ();
   1.712 +	if ( strcmp (ZLIB_VERSION, version)== 0)
   1.713 +		{
   1.714 +		INFO_PRINTF1(_L("Returned version matches!"));
   1.715 +		retVal=KErrNone;
   1.716 +		}
   1.717 +
   1.718 +	else
   1.719 +		{
   1.720 +		ERR_PRINTF1(_L("Return version mismatch!"));
   1.721 +		retVal=KErrGeneral;
   1.722 +		}
   1.723 +	return retVal;
   1.724 +	}
   1.725 +
   1.726 +TInt CTestZlib::Test_compress01()
   1.727 +	{
   1.728 +	INFO_PRINTF1(_L("Zlib Test compress"));
   1.729 +	int retVal = 0;
   1.730 +
   1.731 +	Byte *comp, *uncomp;
   1.732 +	uLong compLen, uncompLen;
   1.733 +	compLen = uncompLen = 30;
   1.734 +
   1.735 +	comp = (Byte*)calloc((uInt)compLen, 1);
   1.736 +	if ( comp == NULL)
   1.737 +		{
   1.738 +		INFO_PRINTF1(_L("Could not allocate memory for comp."));
   1.739 +		return KErrNoMemory;
   1.740 +		}
   1.741 +	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
   1.742 +	if ( uncomp == NULL)
   1.743 +		{
   1.744 +		INFO_PRINTF1(_L("Could not allocate memory for uncomp."));
   1.745 +		free (comp);
   1.746 +		return KErrNoMemory;
   1.747 +		}
   1.748 +
   1.749 +	retVal = sec_compress (comp, compLen, uncomp, uncompLen);
   1.750 +	free (comp);
   1.751 +	free (uncomp);
   1.752 +	return retVal;
   1.753 +	}
   1.754 +
   1.755 +// Test deflate - normal flow
   1.756 +TInt CTestZlib::Test_deflate01()
   1.757 +	{
   1.758 +	INFO_PRINTF1(_L("Zlib Test deflate"));
   1.759 +	int retVal = KErrGeneral;
   1.760 +	TInt flush, compression, expRet;
   1.761 +
   1.762 +	Byte *comp;
   1.763 +	uLong compLen;
   1.764 +	compLen = 30;
   1.765 +	comp = (Byte*)calloc((uInt)compLen, 1);
   1.766 +
   1.767 +	ReadIntParam (flush);
   1.768 +	ReadIntParam (compression);
   1.769 +	ReadIntParam (expRet);
   1.770 +
   1.771 +	retVal = sec_deflate01 (comp, compLen, flush, compression);
   1.772 +	free (comp);
   1.773 +	if ( retVal != expRet)
   1.774 +		{
   1.775 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
   1.776 +		retVal= KErrGeneral;
   1.777 +		}
   1.778 +	else
   1.779 +		{
   1.780 +		INFO_PRINTF1(_L("Test passes!"));
   1.781 +		retVal= KErrNone;
   1.782 +		}
   1.783 +	return retVal;
   1.784 +	}
   1.785 +
   1.786 +//Negative test - 
   1.787 +TInt CTestZlib::Test_deflate02()
   1.788 +	{
   1.789 +	INFO_PRINTF1(_L("Zlib Test deflate"));
   1.790 +	int retVal = KErrGeneral;
   1.791 +	TInt flush, compression, expRet;
   1.792 +
   1.793 +	Byte *comp;
   1.794 +	uLong compLen;
   1.795 +	compLen = 30;
   1.796 +	comp = (Byte*)calloc((uInt)compLen, 1);
   1.797 +
   1.798 +	ReadIntParam (flush);
   1.799 +	ReadIntParam (compression);
   1.800 +	ReadIntParam (expRet);
   1.801 +
   1.802 +	retVal = sec_deflate02 (comp, compLen, flush, compression);
   1.803 +	free (comp);
   1.804 +	if ( retVal != expRet)
   1.805 +		{
   1.806 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
   1.807 +		retVal= KErrGeneral;
   1.808 +		}
   1.809 +	else
   1.810 +		{
   1.811 +		INFO_PRINTF1(_L("Test passes!"));
   1.812 +		retVal= KErrNone;
   1.813 +		}
   1.814 +	return retVal;
   1.815 +	}
   1.816 +
   1.817 +// Test deflate small output buffer
   1.818 +TInt CTestZlib::Test_deflateEnd()
   1.819 +	{
   1.820 +	INFO_PRINTF1(_L("Zlib Test deflateEnd"));
   1.821 +
   1.822 +	Byte *comp;
   1.823 +	uLong compLen;
   1.824 +	compLen = 30;
   1.825 +
   1.826 +	comp = (Byte*)calloc((uInt)compLen, 1);
   1.827 +
   1.828 +	z_stream c_stream; // compression stream 
   1.829 +	int err;
   1.830 +	const char hello[] = "hello, hello!";
   1.831 +	uLong len = (uLong)strlen(hello)+1;
   1.832 +
   1.833 +	c_stream.zalloc = (alloc_func)0;
   1.834 +	c_stream.zfree = (free_func)0;
   1.835 +	c_stream.opaque = (voidpf)0;
   1.836 +
   1.837 +	err = deflateInit (&c_stream, Z_DEFAULT_COMPRESSION);
   1.838 +	if ( err != Z_OK)
   1.839 +		{
   1.840 +		INFO_PRINTF2(_L("deflateInit failed: %d"), err);
   1.841 +		free (comp);
   1.842 +		return err;
   1.843 +		}
   1.844 +
   1.845 +	c_stream.next_in = (Bytef*)hello;
   1.846 +	c_stream.next_out = comp;
   1.847 +	err = deflateEnd (&c_stream);
   1.848 +	if ( err != Z_OK)
   1.849 +		{
   1.850 +		ERR_PRINTF2(_L("deflateEnd failed: %d"), err);
   1.851 +		free (comp);
   1.852 +		return err;
   1.853 +		}
   1.854 +	if ( c_stream.state != NULL)
   1.855 +		{
   1.856 +		ERR_PRINTF1(_L("Stream state expected NULL"));
   1.857 +		free (comp);
   1.858 +		return err;
   1.859 +		}
   1.860 +	free (comp);
   1.861 +	return KErrNone;
   1.862 +	}
   1.863 +
   1.864 +TInt CTestZlib::Test_inflate01()
   1.865 +	{
   1.866 +	INFO_PRINTF1(_L("Zlib Test inflate. Positive test"));
   1.867 +	int retVal = KErrGeneral;
   1.868 +	TInt flush, compression, expRet;
   1.869 +	Byte *comp, *uncomp;
   1.870 +	uLong compLen, uncompLen;
   1.871 +	compLen = uncompLen = 60;
   1.872 +
   1.873 +	comp = (Byte*)calloc((uInt)compLen, 1);
   1.874 +	//comp    = (Byte*)malloc(compLen);
   1.875 +	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
   1.876 +	//uncomp  = (Byte*)malloc(uncompLen);
   1.877 +
   1.878 +	ReadIntParam (flush);
   1.879 +	ReadIntParam (compression);
   1.880 +	ReadIntParam (expRet);
   1.881 +
   1.882 +	retVal = sec_deflate01 (comp, compLen, flush, compression);
   1.883 +	if ( retVal != KErrNone)
   1.884 +		{
   1.885 +		ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
   1.886 +		retVal= KErrGeneral;
   1.887 +		}
   1.888 +	retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
   1.889 +	if ( retVal != expRet)
   1.890 +		{
   1.891 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
   1.892 +		retVal= KErrGeneral;
   1.893 +		}
   1.894 +	else
   1.895 +		{
   1.896 +		INFO_PRINTF1(_L("Test passes!"));
   1.897 +		retVal= KErrNone;
   1.898 +		}
   1.899 +	free (comp);
   1.900 +	free (uncomp);
   1.901 +	return retVal;
   1.902 +	}
   1.903 +
   1.904 +//Negative test - invalid deflate data - return Z_DATA_ERROR
   1.905 +TInt CTestZlib::Test_inflate02()
   1.906 +	{
   1.907 +	INFO_PRINTF1(_L("Zlib Test inflate with invalide deflate data"));
   1.908 +	int retVal = KErrGeneral;
   1.909 +	TInt flush, compression, expRet;
   1.910 +	Byte *comp, *uncomp;
   1.911 +	uLong compLen, uncompLen;
   1.912 +	compLen = uncompLen = 30;
   1.913 +
   1.914 +	comp = (Byte*)calloc((uInt)compLen, 1);
   1.915 +	//comp    = (Byte*)malloc(compLen);
   1.916 +	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
   1.917 +	//uncomp  = (Byte*)malloc(uncompLen);
   1.918 +
   1.919 +	ReadIntParam (flush);
   1.920 +	ReadIntParam (compression);
   1.921 +	ReadIntParam (expRet);
   1.922 +
   1.923 +	retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
   1.924 +	if ( retVal != expRet)
   1.925 +		{
   1.926 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
   1.927 +		retVal= KErrGeneral;
   1.928 +		}
   1.929 +	else
   1.930 +		{
   1.931 +		INFO_PRINTF1(_L("Test passes!"));
   1.932 +		retVal= KErrNone;
   1.933 +		}
   1.934 +	free (comp);
   1.935 +	free (uncomp);
   1.936 +	return retVal;
   1.937 +	}
   1.938 +
   1.939 +// uncompressed data buffer inititalized to NULL
   1.940 +TInt CTestZlib::Test_inflate03()
   1.941 +	{
   1.942 +	INFO_PRINTF1(_L("Zlib Test inflate with NULL uncompressed data buffer"));
   1.943 +	int retVal = KErrGeneral;
   1.944 +	TInt flush, compression, expRet;
   1.945 +	Byte *comp=NULL, *uncomp=NULL;
   1.946 +	uLong compLen, uncompLen;
   1.947 +	compLen = uncompLen = 30;
   1.948 +
   1.949 +	comp = (Byte*)calloc((uInt)compLen, 1);
   1.950 +	//uncomp  = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data
   1.951 +
   1.952 +	ReadIntParam (flush);
   1.953 +	ReadIntParam (compression);
   1.954 +	ReadIntParam (expRet);
   1.955 +
   1.956 +	retVal = sec_deflate01 (comp, compLen, flush, compression);
   1.957 +	if ( retVal != KErrNone)
   1.958 +		{
   1.959 +		ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
   1.960 +		retVal= KErrGeneral;
   1.961 +		}
   1.962 +	retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
   1.963 +	if ( retVal != expRet)
   1.964 +		{
   1.965 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
   1.966 +		retVal= KErrGeneral;
   1.967 +		}
   1.968 +	else
   1.969 +		{
   1.970 +		INFO_PRINTF1(_L("Test passes!"));
   1.971 +		retVal= KErrNone;
   1.972 +		}
   1.973 +	free (comp); //free(uncomp);
   1.974 +	return retVal;
   1.975 +	}
   1.976 +
   1.977 +//Not enough buffer size for uncompresed data
   1.978 +TInt CTestZlib::Test_inflate04()
   1.979 +	{
   1.980 +	INFO_PRINTF1(_L("Zlib Test inflatewith not enough buffer size for uncompressed data"));
   1.981 +	int retVal = KErrGeneral;
   1.982 +	TInt flush, compression, expRet;
   1.983 +	Byte *comp=NULL, *uncomp=NULL;
   1.984 +	uLong compLen, uncompLen;
   1.985 +	compLen = 30;
   1.986 +	uncompLen = 5;
   1.987 +
   1.988 +	comp = (Byte*)calloc((uInt)compLen, 1);
   1.989 +	uncomp = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data
   1.990 +
   1.991 +	ReadIntParam (flush);
   1.992 +	ReadIntParam (compression);
   1.993 +	ReadIntParam (expRet);
   1.994 +
   1.995 +	retVal = sec_deflate01 (comp, compLen, flush, compression);
   1.996 +	if ( retVal != KErrNone)
   1.997 +		{
   1.998 +		ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
   1.999 +		retVal= KErrGeneral;
  1.1000 +		}
  1.1001 +	retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
  1.1002 +	if ( retVal != expRet)
  1.1003 +		{
  1.1004 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
  1.1005 +		retVal= KErrGeneral;
  1.1006 +		}
  1.1007 +	else
  1.1008 +		{
  1.1009 +		INFO_PRINTF1(_L("Test passes!"));
  1.1010 +		retVal= KErrNone;
  1.1011 +		}
  1.1012 +	free (comp);
  1.1013 +	free (uncomp);
  1.1014 +	return retVal;
  1.1015 +	}
  1.1016 +
  1.1017 +//Use 256K sized chunks for inflating
  1.1018 +TInt CTestZlib::Test_inflate05()
  1.1019 +	{
  1.1020 +	INFO_PRINTF1(_L("Zlib Test inflate with 256K sized chunks"));
  1.1021 +	int retVal = KErrGeneral;
  1.1022 +	TInt flush, compression, expRet;
  1.1023 +	Byte *comp=NULL, *uncomp=NULL;
  1.1024 +	uLong compLen, uncompLen;
  1.1025 +	compLen = 30;
  1.1026 +	uncompLen = 30;
  1.1027 +
  1.1028 +	comp = (Byte*)calloc((uInt)compLen, 1);
  1.1029 +	uncomp = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data
  1.1030 +
  1.1031 +	ReadIntParam (flush);
  1.1032 +	ReadIntParam (compression);
  1.1033 +	ReadIntParam (expRet);
  1.1034 +
  1.1035 +	retVal = sec_deflate01 (comp, compLen, flush, compression);
  1.1036 +	if ( retVal != KErrNone)
  1.1037 +		{
  1.1038 +		ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
  1.1039 +		retVal= KErrGeneral;
  1.1040 +		}
  1.1041 +	retVal = sec_inflate_large_buf (comp, compLen, uncomp, uncompLen, flush);
  1.1042 +	if ( retVal != expRet)
  1.1043 +		{
  1.1044 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
  1.1045 +		retVal= KErrGeneral;
  1.1046 +		}
  1.1047 +	else
  1.1048 +		{
  1.1049 +		INFO_PRINTF1(_L("Test passes!"));
  1.1050 +		retVal= KErrNone;
  1.1051 +		}
  1.1052 +	free (comp);
  1.1053 +	free (uncomp);
  1.1054 +	return retVal;
  1.1055 +	}
  1.1056 +
  1.1057 +TInt CTestZlib::Test_inflate06()
  1.1058 +	{
  1.1059 +	INFO_PRINTF1(_L("Zlib Test inflate with invalid data"));
  1.1060 +	int retVal = KErrGeneral;
  1.1061 +	TInt flush, compression, expRet;
  1.1062 +	Byte *comp, *uncomp;
  1.1063 +	uLong compLen, uncompLen;
  1.1064 +	compLen = uncompLen = 60;
  1.1065 +
  1.1066 +	comp = (Byte*)calloc((uInt)compLen, 1);
  1.1067 +	//comp    = (Byte*)malloc(compLen);
  1.1068 +	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
  1.1069 +	//uncomp  = (Byte*)malloc(uncompLen);
  1.1070 +
  1.1071 +	ReadIntParam (flush);
  1.1072 +	ReadIntParam (compression);
  1.1073 +	ReadIntParam (expRet);
  1.1074 +
  1.1075 +	retVal = sec_deflate01 (comp, compLen, flush, compression);
  1.1076 +	if ( retVal != KErrNone)
  1.1077 +		{
  1.1078 +		ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
  1.1079 +		retVal= KErrGeneral;
  1.1080 +		}
  1.1081 +	
  1.1082 +	// Corrupt the compressed data
  1.1083 +	comp[0] = 'a';
  1.1084 +	comp[1] = 'a';
  1.1085 +	
  1.1086 +	retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
  1.1087 +	if ( retVal != expRet)
  1.1088 +		{
  1.1089 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
  1.1090 +		retVal= KErrGeneral;
  1.1091 +		}
  1.1092 +	else
  1.1093 +		{
  1.1094 +		INFO_PRINTF1(_L("Test passes!"));
  1.1095 +		retVal= KErrNone;
  1.1096 +		}
  1.1097 +	free (comp);
  1.1098 +	free (uncomp);
  1.1099 +	return retVal;
  1.1100 +	}
  1.1101 +
  1.1102 +TInt CTestZlib::Test_inflateEnd()
  1.1103 +	{
  1.1104 +	INFO_PRINTF1(_L("Zlib Test inflateEnd"));
  1.1105 +	Byte *comp, *uncomp;
  1.1106 +	uLong compLen, uncompLen;
  1.1107 +	compLen = uncompLen = 30;
  1.1108 +
  1.1109 +	comp = (Byte*)calloc((uInt)compLen, 1);
  1.1110 +	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
  1.1111 +
  1.1112 +	int err;
  1.1113 +	z_stream d_stream; // decompression stream 
  1.1114 +
  1.1115 +	//strcpy((char*)uncompr, "garbage");
  1.1116 +
  1.1117 +	d_stream.zalloc = (alloc_func)0;
  1.1118 +	d_stream.zfree = (free_func)0;
  1.1119 +	d_stream.opaque = (voidpf)0;
  1.1120 +
  1.1121 +	d_stream.next_in = comp;
  1.1122 +	d_stream.avail_in = 0;
  1.1123 +	d_stream.next_out = uncomp;
  1.1124 +
  1.1125 +	err = inflateInit (&d_stream);
  1.1126 +	if ( err != Z_OK)
  1.1127 +		{
  1.1128 +		INFO_PRINTF2(_L("inflateInit error: %d"), err);
  1.1129 +		free (comp);
  1.1130 +		free (uncomp);
  1.1131 +		return err;
  1.1132 +		}
  1.1133 +	//Not inflating
  1.1134 +
  1.1135 +	err = inflateEnd (&d_stream);
  1.1136 +	if ( err != Z_OK)
  1.1137 +		{
  1.1138 +		INFO_PRINTF2(_L("inflateEnd error: %d"), err);
  1.1139 +		free (comp);
  1.1140 +		free (uncomp);
  1.1141 +		return err;
  1.1142 +		}
  1.1143 +	if ( d_stream.state != NULL)
  1.1144 +		{
  1.1145 +		INFO_PRINTF2(_L("inflateEnd error: %d"), err);
  1.1146 +		free (comp);
  1.1147 +		free (uncomp);
  1.1148 +		return err;
  1.1149 +		}
  1.1150 +
  1.1151 +	free (comp);
  1.1152 +	free (uncomp);
  1.1153 +	return KErrNone;
  1.1154 +	}
  1.1155 +
  1.1156 +// Test deflateSetDictionary - normal flow
  1.1157 +TInt CTestZlib::Test_deflateSetDictionary01()
  1.1158 +	{
  1.1159 +	INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - positive test"));
  1.1160 +	int retVal = KErrGeneral;
  1.1161 +	TInt flush, compression, expRet;
  1.1162 +
  1.1163 +	Byte *comp;
  1.1164 +	uLong compLen;
  1.1165 +	compLen = 30;
  1.1166 +	comp = (Byte*)calloc((uInt)compLen, 1);
  1.1167 +
  1.1168 +	ReadIntParam (flush);
  1.1169 +	ReadIntParam (compression);
  1.1170 +	ReadIntParam (expRet);
  1.1171 +
  1.1172 +	retVal = sec_deflateSetDictionary01 (comp, compLen, flush, compression);
  1.1173 +	free (comp);
  1.1174 +	if ( retVal != expRet)
  1.1175 +		{
  1.1176 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
  1.1177 +		retVal= KErrGeneral;
  1.1178 +		}
  1.1179 +	else
  1.1180 +		{
  1.1181 +		INFO_PRINTF1(_L("Test passes!"));
  1.1182 +		retVal= KErrNone;
  1.1183 +		}
  1.1184 +	return retVal;
  1.1185 +	}
  1.1186 +
  1.1187 +// Test deflateSetDictionary - dictionary NULL
  1.1188 +TInt CTestZlib::Test_deflateSetDictionary02()
  1.1189 +	{
  1.1190 +	INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary with dictionary NULL"));
  1.1191 +	int retVal = KErrGeneral;
  1.1192 +
  1.1193 +	TInt compression, expRet;
  1.1194 +
  1.1195 +	ReadIntParam (compression);
  1.1196 +	ReadIntParam (expRet);
  1.1197 +	retVal = sec_deflateSetDictionary02 (compression);
  1.1198 +
  1.1199 +	if ( retVal != expRet)
  1.1200 +		{
  1.1201 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
  1.1202 +		retVal= KErrGeneral;
  1.1203 +		}
  1.1204 +	else
  1.1205 +		{
  1.1206 +		INFO_PRINTF1(_L("Test passes!"));
  1.1207 +		retVal= KErrNone;
  1.1208 +		}
  1.1209 +	return retVal;
  1.1210 +	}
  1.1211 +
  1.1212 +// Test deflateSetDictionary - set dictionary after deflate, deflateEnd
  1.1213 +TInt CTestZlib::Test_deflateSetDictionary03()
  1.1214 +	{
  1.1215 +	INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - set dictionary after deflating"));
  1.1216 +	int retVal = KErrGeneral;
  1.1217 +	TInt flush, compression, expRet;
  1.1218 +
  1.1219 +	Byte *comp;
  1.1220 +	uLong compLen;
  1.1221 +	compLen = 30;
  1.1222 +	comp = (Byte*)calloc((uInt)compLen, 1);
  1.1223 +
  1.1224 +	ReadIntParam (flush);
  1.1225 +	ReadIntParam (compression);
  1.1226 +	ReadIntParam (expRet);
  1.1227 +
  1.1228 +	retVal = sec_deflateSetDictionary03 (comp, compLen, flush, compression);
  1.1229 +	free (comp);
  1.1230 +	if ( retVal != expRet)
  1.1231 +		{
  1.1232 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
  1.1233 +		retVal= KErrGeneral;
  1.1234 +		}
  1.1235 +	else
  1.1236 +		{
  1.1237 +		INFO_PRINTF1(_L("Test passes!"));
  1.1238 +		retVal= KErrNone;
  1.1239 +		}
  1.1240 +	return retVal;
  1.1241 +	}
  1.1242 +// Test deflateSetDictionary - set tiny dictionary < MIN_MATCH
  1.1243 +TInt CTestZlib::Test_deflateSetDictionary04()
  1.1244 +	{
  1.1245 +	INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - positive test"));
  1.1246 +	int retVal = KErrGeneral;
  1.1247 +	TInt flush, compression, expRet;
  1.1248 +
  1.1249 +	Byte *comp;
  1.1250 +	uLong compLen;
  1.1251 +	compLen = 30;
  1.1252 +	comp = (Byte*)calloc((uInt)compLen, 1);
  1.1253 +
  1.1254 +	ReadIntParam (flush);
  1.1255 +	ReadIntParam (compression);
  1.1256 +	ReadIntParam (expRet);
  1.1257 +
  1.1258 +	retVal = sec_deflateSetDictionary04 (comp, compLen, flush, compression);
  1.1259 +	free (comp);
  1.1260 +	if ( retVal != expRet)
  1.1261 +		{
  1.1262 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
  1.1263 +		retVal= KErrGeneral;
  1.1264 +		}
  1.1265 +	else
  1.1266 +		{
  1.1267 +		INFO_PRINTF1(_L("Test passes!"));
  1.1268 +		retVal= KErrNone;
  1.1269 +		}
  1.1270 +	return retVal;
  1.1271 +	}
  1.1272 +
  1.1273 +// Test deflateSetDictionary - set large dictionary > MAX_MATCH
  1.1274 +TInt CTestZlib::Test_deflateSetDictionary05()
  1.1275 +	{
  1.1276 +	INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - set large dictionary > MAX_MATCH"));
  1.1277 +	int retVal = KErrGeneral;
  1.1278 +	TInt flush, compression, expRet;
  1.1279 +
  1.1280 +	Byte *comp;
  1.1281 +	uLong compLen;
  1.1282 +	compLen = 30;
  1.1283 +	comp = (Byte*)calloc((uInt)compLen, 1);
  1.1284 +
  1.1285 +	ReadIntParam (flush);
  1.1286 +	ReadIntParam (compression);
  1.1287 +	ReadIntParam (expRet);
  1.1288 +
  1.1289 +	retVal = sec_deflateSetDictionary05 (comp, compLen, flush, compression);
  1.1290 +	free (comp);
  1.1291 +	if ( retVal != expRet)
  1.1292 +		{
  1.1293 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
  1.1294 +		retVal= KErrGeneral;
  1.1295 +		}
  1.1296 +	else
  1.1297 +		{
  1.1298 +		INFO_PRINTF1(_L("Test passes!"));
  1.1299 +		retVal= KErrNone;
  1.1300 +		}
  1.1301 +	return retVal;
  1.1302 +	}
  1.1303 +
  1.1304 +TInt CTestZlib::Test_gzio()
  1.1305 +	{
  1.1306 +	INFO_PRINTF1(_L("Zlib Test gzio"));
  1.1307 +	int retVal = 0;
  1.1308 +
  1.1309 +	Byte *comp, *uncomp;
  1.1310 +	uLong compLen, uncompLen;
  1.1311 +	compLen = uncompLen = 30;
  1.1312 +
  1.1313 +	comp = (Byte*)calloc((uInt)compLen, 1);
  1.1314 +	if ( comp == NULL)
  1.1315 +		{
  1.1316 +		INFO_PRINTF1(_L("Could not allocate memory for comp."));
  1.1317 +		return KErrNoMemory;
  1.1318 +		}
  1.1319 +
  1.1320 +	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
  1.1321 +	if ( uncomp == NULL)
  1.1322 +		{
  1.1323 +		INFO_PRINTF1(_L("Could not allocate memory for uncomp."));
  1.1324 +		free (comp);
  1.1325 +		return KErrNoMemory;
  1.1326 +		}
  1.1327 +
  1.1328 +	retVal = sec_gzio ("C:\\bye.gz", uncomp, uncompLen);
  1.1329 +	free (comp);
  1.1330 +	free (uncomp);
  1.1331 +	return retVal;
  1.1332 +	}
  1.1333 +
  1.1334 +TInt CTestZlib::Test_gzdirect()
  1.1335 +	{
  1.1336 +	INFO_PRINTF1(_L("gzdirect test: read gz file"));
  1.1337 +	TInt res = KErrNone;
  1.1338 +	char mode[3];
  1.1339 +	gzFile file;
  1.1340 +	const char * fname=  TESTFILE;
  1.1341 +	ReadStringParam (mode);
  1.1342 +	file = gzopen (fname, mode);
  1.1343 +	if ( file == NULL)
  1.1344 +		{
  1.1345 +		res = KErrGeneral;
  1.1346 +		return res;
  1.1347 +		}
  1.1348 +	res = gzdirect (file); //0=success
  1.1349 +	gzclose (file);
  1.1350 +	return res;
  1.1351 +	}
  1.1352 +
  1.1353 +TInt CTestZlib::Test_gzdirectnull()
  1.1354 +	{
  1.1355 +	INFO_PRINTF1(_L("gzdirect test: read NULL stream"));
  1.1356 +	TInt res = KErrNone;
  1.1357 +	gzFile file=NULL;
  1.1358 +	res = gzdirect (file); //0=success
  1.1359 +	gzclose (file);
  1.1360 +	return res;
  1.1361 +	}
  1.1362 +
  1.1363 +TInt CTestZlib::Test_gzclearerr_null()
  1.1364 +	{
  1.1365 +	TInt res = KErrNone;
  1.1366 +	int err;
  1.1367 +	gzFile file;
  1.1368 +	const char *fname=  NULL;
  1.1369 +	file = gzopen (fname, "wb");
  1.1370 +	if ( file == NULL)
  1.1371 +		{
  1.1372 +		res=KErrGeneral;
  1.1373 +		}
  1.1374 +	gzputc (file, 'h');
  1.1375 +	if ( gzputs (file, "ello")!= 5)
  1.1376 +		{
  1.1377 +		gzprintf (file, "gzputs err");
  1.1378 +		res=KErrGeneral;
  1.1379 +		}
  1.1380 +	err= gzclose (file);
  1.1381 +	if ( err != Z_OK)
  1.1382 +		{
  1.1383 +		res = KErrGeneral;
  1.1384 +		}
  1.1385 +	gzclearerr (file);
  1.1386 +	z_stream *s = (z_stream*)file;
  1.1387 +	if ( s == NULL)
  1.1388 +		res = KErrNone;
  1.1389 +	else
  1.1390 +		{
  1.1391 +		ERR_PRINTF1(_L("Expected NULL stream. Returned nonNULL"));
  1.1392 +		res = KErrGeneral;
  1.1393 +		}
  1.1394 +	return res;
  1.1395 +	}
  1.1396 +
  1.1397 +TInt CTestZlib::Test_gzclearerr()
  1.1398 +	{
  1.1399 +
  1.1400 +	Byte *compr, *uncompr;
  1.1401 +	uLong comprLen = 20*sizeof(int);
  1.1402 +
  1.1403 +	uLong uncomprLen = comprLen;
  1.1404 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.1405 +	if ( compr == Z_NULL)
  1.1406 +		{
  1.1407 +		return KErrNoMemory;
  1.1408 +		}
  1.1409 +	uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1410 +	if ( uncompr == Z_NULL)
  1.1411 +		{
  1.1412 +		free (compr);
  1.1413 +		return KErrNoMemory;
  1.1414 +		}
  1.1415 +
  1.1416 +	INFO_PRINTF1(_L("gzclearerr test"));
  1.1417 +	int err;
  1.1418 +	int len = (int)strlen(hello)+1;
  1.1419 +	gzFile file;
  1.1420 +
  1.1421 +	file = gzopen (MYFILE, "wb");
  1.1422 +	if ( file == NULL)
  1.1423 +		{
  1.1424 +		err = KErrGeneral;
  1.1425 +		free (compr);
  1.1426 +		free (uncompr);
  1.1427 +		return err;
  1.1428 +		}
  1.1429 +	gzputc (file, 'h');
  1.1430 +	if ( gzputs (file, "ello")!= 4)
  1.1431 +		{
  1.1432 +		err=KErrGeneral;
  1.1433 +		}
  1.1434 +	if ( gzprintf (file, ", %s!", "hello")!= 8)
  1.1435 +		{
  1.1436 +		err=KErrGeneral;
  1.1437 +		}
  1.1438 +	gzseek (file, 1L, SEEK_CUR); // add one zero byte 
  1.1439 +	gzclose (file);
  1.1440 +
  1.1441 +	file = gzopen (MYFILE, "rb");
  1.1442 +	if ( file == NULL)
  1.1443 +		{
  1.1444 +		err = KErrGeneral;
  1.1445 +		free (compr);
  1.1446 +		free (uncompr);
  1.1447 +		return err;
  1.1448 +		}
  1.1449 +	strcpy ((char*)uncompr, "garbage");
  1.1450 +
  1.1451 +	if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len)
  1.1452 +		{
  1.1453 +		}
  1.1454 +	if ( strcmp ((char*)uncompr, hello))
  1.1455 +		{
  1.1456 +		err=KErrGeneral;
  1.1457 +		}
  1.1458 +	else
  1.1459 +		{
  1.1460 +		err=KErrNone;
  1.1461 +		}
  1.1462 +
  1.1463 +	gzseek (file, -8L, SEEK_CUR);
  1.1464 +	gzclearerr (file);
  1.1465 +	gzgets (file, (char*)uncompr, (int)uncomprLen);
  1.1466 +
  1.1467 +	if ( strlen ((char*)uncompr)!= 7)
  1.1468 +		{
  1.1469 +		//1 " hello!" 
  1.1470 +		ERR_PRINTF1(_L("gzegets gets wrong string"));
  1.1471 +		err=KErrGeneral;
  1.1472 +		}
  1.1473 +	gzclose (file);
  1.1474 +
  1.1475 +	free (compr);
  1.1476 +	free (uncompr);
  1.1477 +	return err;
  1.1478 +	}
  1.1479 +
  1.1480 +TInt CTestZlib::Test_gzerror_streamend()
  1.1481 +	{
  1.1482 +#ifdef NO_GZCOMPRESS
  1.1483 +	ERR_PRINTF1(_L("NO_GZCOMPRESS -- gz* functions cannot compress"));
  1.1484 +#else
  1.1485 +	const char *msgptr;
  1.1486 +	char fname[] = "C:\\bye.gz";
  1.1487 +
  1.1488 +	Byte *compr, *uncompr;
  1.1489 +	uLong comprLen, uncomprLen;
  1.1490 +	comprLen = uncomprLen = 30;
  1.1491 +
  1.1492 +	compr = (Byte*)calloc((uInt)comprLen, 1);
  1.1493 +	if ( compr == NULL)
  1.1494 +		{
  1.1495 +		INFO_PRINTF1(_L("Could not allocate memory for compr."));
  1.1496 +		return KErrNoMemory;
  1.1497 +		}
  1.1498 +
  1.1499 +	uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
  1.1500 +	if ( uncompr == NULL)
  1.1501 +		{
  1.1502 +		INFO_PRINTF1(_L("Could not allocate memory for uncompr."));
  1.1503 +		free (compr);
  1.1504 +		return KErrNoMemory;
  1.1505 +		}
  1.1506 +
  1.1507 +	int err;
  1.1508 +	const char hello[] = "hello, hello!";
  1.1509 +	int len = (int)strlen(hello)+1;
  1.1510 +	gzFile file;
  1.1511 +
  1.1512 +	file = gzopen (fname, "wb");
  1.1513 +	if ( file == NULL)
  1.1514 +		{
  1.1515 +		ERR_PRINTF1(_L("gzopen error"));
  1.1516 +		free (compr);
  1.1517 +		free (uncompr);
  1.1518 +		return KErrGeneral;
  1.1519 +		}
  1.1520 +	gzputc (file, 'h');
  1.1521 +	if ( gzputs (file, "ello")!= 4)
  1.1522 +		{
  1.1523 +		ERR_PRINTF1(_L("gzputs err"));
  1.1524 +		free (compr);
  1.1525 +		free (uncompr);
  1.1526 +		return KErrGeneral;
  1.1527 +		}
  1.1528 +	if ( gzprintf (file, ", %s!", "hello")!= 8)
  1.1529 +		{
  1.1530 +		ERR_PRINTF1(_L("gzprintf err="));
  1.1531 +		free (compr);
  1.1532 +		free (uncompr);
  1.1533 +		return KErrGeneral;
  1.1534 +		}
  1.1535 +
  1.1536 +	gzseek (file, 1L, SEEK_CUR); // add one zero byte 
  1.1537 +	gzclose (file);
  1.1538 +
  1.1539 +	file = gzopen (fname, "rb");
  1.1540 +	if ( file == NULL)
  1.1541 +		{
  1.1542 +		ERR_PRINTF1(_L("gzopen error"));
  1.1543 +		free (compr);
  1.1544 +		free (uncompr);
  1.1545 +		return KErrGeneral;
  1.1546 +		}
  1.1547 +	strcpy ((char*)uncompr, "garbage");
  1.1548 +
  1.1549 +	if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len)
  1.1550 +		{
  1.1551 +		ERR_PRINTF1(_L("gzread err"));
  1.1552 +		free (compr);
  1.1553 +		free (uncompr);
  1.1554 +		return KErrGeneral;
  1.1555 +		}
  1.1556 +
  1.1557 +	if ( strcmp ((char*)uncompr, hello))
  1.1558 +		{
  1.1559 +		ERR_PRINTF1(_L("bad gzread"));
  1.1560 +		free (compr);
  1.1561 +		free (uncompr);
  1.1562 +		return KErrGeneral;
  1.1563 +		}
  1.1564 +
  1.1565 +	INFO_PRINTF2(_L("Reached file position %ld"),gzseek(file, -8L, SEEK_CUR));
  1.1566 +
  1.1567 +	gzgets (file, (char*)uncompr, (int)uncomprLen);
  1.1568 +	msgptr = gzerror (file, &err);
  1.1569 +	if ( strcmp (msgptr, "C:\\bye.gz: stream end")!= 0)
  1.1570 +		{
  1.1571 +		// " hello!" 
  1.1572 +		ERR_PRINTF1(_L("gzerror err on streamend"));
  1.1573 +		free (compr);
  1.1574 +		free (uncompr);
  1.1575 +		return KErrGeneral;
  1.1576 +		}
  1.1577 +
  1.1578 +	gzclose (file);
  1.1579 +	free (compr);
  1.1580 +	free (uncompr);
  1.1581 +
  1.1582 +	if ( err != Z_STREAM_END)
  1.1583 +		{
  1.1584 +		return KErrGeneral;
  1.1585 +		}
  1.1586 +	return KErrNone;
  1.1587 +#endif
  1.1588 +	}
  1.1589 +
  1.1590 +TInt CTestZlib::Test_gzungetcnegative()
  1.1591 +	{
  1.1592 +	gzFile file=NULL;
  1.1593 +	int ret = gzungetc (' ', file); //NULL stream
  1.1594 +	if ( ret != EOF)
  1.1595 +		{
  1.1596 +		ERR_PRINTF2(_L("gzungetc NULL stream test: Expected EOF but returned %d"),ret);
  1.1597 +		return KErrGeneral;
  1.1598 +		}
  1.1599 +
  1.1600 +	const char hello[] = "hello, hello!";
  1.1601 +	int len = (int)strlen(hello)+1;
  1.1602 +
  1.1603 +	file = gzopen ("C:\\bye.gz", "wb");
  1.1604 +	if ( file == NULL)
  1.1605 +		{
  1.1606 +		ERR_PRINTF1(_L("gzopen error"));
  1.1607 +		return KErrGeneral;
  1.1608 +		}
  1.1609 +	gzputc (file, 'h');
  1.1610 +	if ( gzputs (file, "ello")!= 4)
  1.1611 +		{
  1.1612 +		ERR_PRINTF1(_L("gzputs err"));
  1.1613 +		gzclose (file);
  1.1614 +		return KErrGeneral;
  1.1615 +		}
  1.1616 +
  1.1617 +	ret = gzungetc (' ', file); //non-read mode
  1.1618 +	if ( ret != EOF)
  1.1619 +		{
  1.1620 +		ERR_PRINTF2(_L("gzungetc non-read mode test: Expected EOF but returned %d"),ret);
  1.1621 +		gzclose (file);
  1.1622 +		return KErrGeneral;
  1.1623 +		}
  1.1624 +
  1.1625 +	gzseek (file, 1L, SEEK_CUR); // add one zero byte 
  1.1626 +	gzclose (file);
  1.1627 +
  1.1628 +	file = gzopen ("C:\\bye.gz", "rb");
  1.1629 +	if ( file == NULL)
  1.1630 +		{
  1.1631 +		ERR_PRINTF1(_L("gzopen error"));
  1.1632 +		return KErrGeneral;
  1.1633 +		}
  1.1634 +
  1.1635 +	if ( gzungetc (EOF, file)!= EOF) //ungetc EOF
  1.1636 +		{
  1.1637 +		gzclose (file);
  1.1638 +		ERR_PRINTF1(_L("gzungetc error"));
  1.1639 +		return KErrGeneral;
  1.1640 +		}
  1.1641 +	gzclose (file);
  1.1642 +
  1.1643 +	return KErrNone;
  1.1644 +	}
  1.1645 +
  1.1646 +TInt CTestZlib::Test_gzseeknegative()
  1.1647 +	{
  1.1648 +
  1.1649 +	int err=0;
  1.1650 +
  1.1651 +	int len = (int)strlen(hello)+1;
  1.1652 +	gzFile file;
  1.1653 +
  1.1654 +	file = gzopen (TESTFILE, "wb");
  1.1655 +	if ( file == NULL)
  1.1656 +		{
  1.1657 +		return KErrNoMemory;
  1.1658 +		}
  1.1659 +	gzputc (file, 'h');
  1.1660 +
  1.1661 +	err= gzseek (file, 1L, SEEK_END); /* add one zero byte */
  1.1662 +	if ( err != -1)
  1.1663 +		{
  1.1664 +		gzclose (file);
  1.1665 +		return KErrGeneral;
  1.1666 +		}
  1.1667 +
  1.1668 +	err= gzclose (file);
  1.1669 +	file = gzopen (TESTFILE, "rb");
  1.1670 +	if ( gzgetc (file)!= 'h')
  1.1671 +		{
  1.1672 +		gzclose (file);
  1.1673 +		ERR_PRINTF1(_L("gzgetc error"));
  1.1674 +		return KErrGeneral;
  1.1675 +		}
  1.1676 +	if ( gzgetc (file)!= EOF)
  1.1677 +		{
  1.1678 +		gzclose (file);
  1.1679 +		ERR_PRINTF1(_L("gzgetc error"));
  1.1680 +		return KErrGeneral;
  1.1681 +		}
  1.1682 +	err= gzseek (file, 1L, SEEK_CUR);
  1.1683 +	if ( gzgetc (file)!= -1L)
  1.1684 +		{
  1.1685 +		gzclose (file);
  1.1686 +		ERR_PRINTF1(_L("gzseek error"));
  1.1687 +		return KErrGeneral;
  1.1688 +		}
  1.1689 +	gzclose (file);
  1.1690 +	return KErrNone;
  1.1691 +	}
  1.1692 +
  1.1693 +/*TInt CTestZlib::TestGzopenRw()
  1.1694 + {
  1.1695 + TInt res = KErrNone ;
  1.1696 + gzFile file;
  1.1697 + char c;
  1.1698 + const char *fname = "c:\\Bytes.gz";
  1.1699 + file = gzopen(fname, "wr");
  1.1700 + if (file == NULL) 
  1.1701 + {
  1.1702 + res = KErrGeneral;
  1.1703 + return res;
  1.1704 + }
  1.1705 + else
  1.1706 + {
  1.1707 + res=gzputc(file, 'r');
  1.1708 + if(res<0)
  1.1709 + {
  1.1710 + res = KErrGeneral;
  1.1711 + } 
  1.1712 + else  
  1.1713 + {    	
  1.1714 + res = KErrNone;
  1.1715 + //gzclearerr(file);
  1.1716 + gzseek(file,0, SEEK_SET);
  1.1717 + c = gzgetc(file);
  1.1718 + if(c == 'r')
  1.1719 + {
  1.1720 + res = KErrNone;
  1.1721 + }
  1.1722 + else
  1.1723 + {
  1.1724 + ERR_PRINTF1(_L("gzgetc error in rw mode. Expected r"));
  1.1725 + res=KErrGeneral;		        	
  1.1726 + }
  1.1727 + }     	
  1.1728 + }
  1.1729 + gzclose(file);
  1.1730 + return res;
  1.1731 + }
  1.1732 + */
  1.1733 +/**
  1.1734 + * Function Name : Test_gzdirecttxt
  1.1735 + * TestCase Description: 1. Checks whether a normal txt file gives a compressed stream or not
  1.1736 + */
  1.1737 +TInt CTestZlib::Test_gzdirecttxt()
  1.1738 +	{
  1.1739 +	gzFile file;
  1.1740 +	int ret=KErrGeneral;
  1.1741 +	char fname[] = "C:\\gzdirecttest.txt";
  1.1742 +	FILE *fp=NULL;
  1.1743 +	fp=fopen (fname, "w");
  1.1744 +	fputc ('\n', fp);
  1.1745 +	fclose (fp);
  1.1746 +	file = gzopen (fname, "rb");
  1.1747 +	ret = gzdirect (file);
  1.1748 +	if ( ret)
  1.1749 +		{
  1.1750 +		INFO_PRINTF1(_L("Reading a Non GzFile"));
  1.1751 +		ret=KErrNone;
  1.1752 +		}
  1.1753 +	else
  1.1754 +		{
  1.1755 +		ERR_PRINTF1(_L("Error in gzdirect. Expeceted 1, returned 0"));
  1.1756 +		ret=KErrGeneral;
  1.1757 +		}
  1.1758 +	gzclose (file);
  1.1759 +	return ret;
  1.1760 +	}
  1.1761 +
  1.1762 +/**
  1.1763 + * Function Name : TestGzungetcChain
  1.1764 + * TestCase Description: 1. Checks whether gzungetc ungets the read chars using getc
  1.1765 + */
  1.1766 +TInt CTestZlib::TestGzungetcChain()
  1.1767 +	{
  1.1768 +	gzFile file;
  1.1769 +	char tmp;
  1.1770 +	char fname[] = "C:\\Hello.gz";
  1.1771 +	file = gzopen (fname, "wb");
  1.1772 +	gzputc (file, 'h');
  1.1773 +	if ( gzputs (file, "ello World")!= 10)
  1.1774 +		{
  1.1775 +		gzclose (file);
  1.1776 +		printf ("Error: gzputs\n");
  1.1777 +		}
  1.1778 +	gzclose (file);
  1.1779 +	file = gzopen (fname, "rb");
  1.1780 +	while (' ' != ( tmp = gzgetc(file) ))
  1.1781 +		{
  1.1782 +		gzungetc (tmp, file);
  1.1783 +		gzseek (file, 1L, SEEK_CUR);
  1.1784 +		}
  1.1785 +	gzclose (file);
  1.1786 +	return KErrNone;
  1.1787 +	}
  1.1788 +
  1.1789 +/**
  1.1790 + * Function Name : TestGzseekBack
  1.1791 + * TestCase Description: 1. Checks whether gzseek returns -1
  1.1792 + * for backward seeks in files opened in write mode.
  1.1793 + */
  1.1794 +TInt CTestZlib::TestGzseekBack()
  1.1795 +	{
  1.1796 +	int err;
  1.1797 +	int len = (int)strlen(hello)+1;
  1.1798 +	gzFile file;
  1.1799 +
  1.1800 +	const char * fname=  TESTFILE;
  1.1801 +
  1.1802 +	file = gzopen (fname, "wb");
  1.1803 +	if ( file == NULL)
  1.1804 +		{
  1.1805 +		err = KErrGeneral;
  1.1806 +		return err;
  1.1807 +		}
  1.1808 +	gzputc (file, 'h');
  1.1809 +	if ( gzputs (file, "ello")!= 4)
  1.1810 +		{
  1.1811 +		err=1;
  1.1812 +		}
  1.1813 +	if ( gzprintf (file, ", %s!", "hello")!= 8)
  1.1814 +		{
  1.1815 +		err=1;
  1.1816 +		}
  1.1817 +	err = (int) gzseek(file,0, SEEK_SET); /* to beg */
  1.1818 +	gzclose (file);
  1.1819 +	if ( err == -1)
  1.1820 +		{
  1.1821 +		return KErrNone;
  1.1822 +		}
  1.1823 +	else
  1.1824 +		{
  1.1825 +		ERR_PRINTF2(_L("Expected -1, returned %d"),err);
  1.1826 +		return KErrGeneral;
  1.1827 +		}
  1.1828 +	}
  1.1829 +
  1.1830 +/**
  1.1831 + * Function Name : TestGzseekAppend
  1.1832 + * TestCase Description: 
  1.1833 + * 1. Writes a text file, closes.
  1.1834 + * 2. Open using gzopen in append mode
  1.1835 + * 3. Writes another character.
  1.1836 + * 4. Seek one down from current position
  1.1837 + * 5. Checks whether gzseek returns 2
  1.1838 + */
  1.1839 +TInt CTestZlib::TestGzseekAppend()
  1.1840 +	{
  1.1841 +	const char hello[] = "hello, hello!";
  1.1842 +	int len = (int)strlen(hello)+1;
  1.1843 +	int err;
  1.1844 +	gzFile file;
  1.1845 +
  1.1846 +	FILE *fp = fopen ("c:\\file.txt", "wb");
  1.1847 +	fputc ('h', fp);
  1.1848 +	fclose (fp);
  1.1849 +	file = gzopen ("c:\\file.txt", "a");
  1.1850 +	if ( file == NULL)
  1.1851 +		{
  1.1852 +		ERR_PRINTF1(_L("gzopen error"));
  1.1853 +		return KErrGeneral;
  1.1854 +		}
  1.1855 +	gzputc (file, 'h');
  1.1856 +	err = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */
  1.1857 +	gzclose (file);
  1.1858 +	if ( err == 2)
  1.1859 +		return KErrNone;
  1.1860 +	else
  1.1861 +		{
  1.1862 +		ERR_PRINTF2(_L("Expected 2, returned %d"),err);
  1.1863 +		return KErrGeneral;
  1.1864 +		}
  1.1865 +	}
  1.1866 +
  1.1867 +/**
  1.1868 + * Function Name : TestGzseekHugeOffset
  1.1869 + * TestCase Description: 
  1.1870 + * 1. Writes a text file, closes.
  1.1871 + * 2. Open using gzopen in append mode
  1.1872 + * 3. Writes another character.
  1.1873 + * 4. Seek 4097 up from current position
  1.1874 + * 5. Checks whether gzseek returns 16386 or not.
  1.1875 + */
  1.1876 +TInt CTestZlib::TestGzseekHugeOffset()
  1.1877 +	{
  1.1878 +	const char hello[] = "hello, hello!";
  1.1879 +	int len = (int)strlen(hello)+1;
  1.1880 +	int err;
  1.1881 +	gzFile file;
  1.1882 +
  1.1883 +	FILE *fp = fopen ("c:\\file.txt", "wb");
  1.1884 +	fputc ('h', fp);
  1.1885 +	fclose (fp);
  1.1886 +	file = gzopen ("c:\\file.txt", "a");
  1.1887 +	if ( file == NULL)
  1.1888 +		{
  1.1889 +		ERR_PRINTF1(_L("gzopen error"));
  1.1890 +		return KErrGeneral;
  1.1891 +		}
  1.1892 +	gzputc (file, 'h');
  1.1893 +	err = (int) gzseek(file,16385L, SEEK_CUR); /* advance pos by 16385*/
  1.1894 +	gzclose (file);
  1.1895 +	if ( err == 16386)
  1.1896 +		return KErrNone;
  1.1897 +	else
  1.1898 +		{
  1.1899 +		ERR_PRINTF2(_L("Expected 2, returned %d"),err);
  1.1900 +		return KErrGeneral;
  1.1901 +		}
  1.1902 +	}
  1.1903 +
  1.1904 +/**
  1.1905 + * Function Name : TestGzseekNoSize
  1.1906 + * TestCase Description: 
  1.1907 + * 1. Seeks a zero sized file
  1.1908 + * 2. Checks whether it returns -1 or not
  1.1909 + */
  1.1910 +TInt CTestZlib::TestGzseekNoSize()
  1.1911 +	{
  1.1912 +	TInt res = KErrNone;
  1.1913 +	gzFile file;
  1.1914 +	uInt size, len;
  1.1915 +	const char *s="\0";
  1.1916 +	len=strlen (s);
  1.1917 +	const char * fname=  TESTFILE;
  1.1918 +	file = gzopen (fname, "wb");
  1.1919 +	if ( file == Z_NULL)
  1.1920 +		{
  1.1921 +		ERR_PRINTF1(_L("gzopen error"));
  1.1922 +		return KErrGeneral;
  1.1923 +		}
  1.1924 +	size = gzwrite (file, (char*)s, (unsigned)strlen(s));
  1.1925 +	if ( len!=size)
  1.1926 +		{
  1.1927 +		ERR_PRINTF1(_L("gzwrite error"));
  1.1928 +		return KErrGeneral;
  1.1929 +		}
  1.1930 +
  1.1931 +	res = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */
  1.1932 +	gzclose (file);
  1.1933 +	if ( res == 1)
  1.1934 +		{
  1.1935 +		return KErrNone;
  1.1936 +		}
  1.1937 +	else
  1.1938 +		{
  1.1939 +		ERR_PRINTF2(_L("Expected -1, returned %d"), res);
  1.1940 +		return KErrGeneral;
  1.1941 +		}
  1.1942 +	}
  1.1943 +
  1.1944 +/**
  1.1945 + * Function Name : TestGzopenLongPath
  1.1946 + * TestCase Description: 
  1.1947 + * 1. Seeks a file with long name
  1.1948 + * 2. Checks whether gzopen returns NULL or not
  1.1949 + */
  1.1950 +TInt CTestZlib::TestGzopenLongPath01()
  1.1951 +	{
  1.1952 +	gzFile file;
  1.1953 +	const char
  1.1954 +			* fname = "c:\\fffff\
  1.1955 +    fffffffffffffffffffffffffffffff\
  1.1956 +    fffffffffffffffffffffffffffffff\
  1.1957 +    fffffffffffffffffffffffffffffff\
  1.1958 +    fffffffffffffffffffffffffffffff\
  1.1959 +    fffffffffffffffffffffffffffffff\
  1.1960 +    fffffffffffffffffffffffffffffff\
  1.1961 +    fffffffffffffffffffffffffffffff\
  1.1962 +    fffffffffffffffffffffffffffffff\
  1.1963 +    fffffffffffffffffffffffffffffff\
  1.1964 +    fffffffffffffffffffffffffffffff\
  1.1965 +    fffffffffffffffffffffffffffffff.txt";
  1.1966 +	file = gzopen (fname, "wb");
  1.1967 +	if ( file == Z_NULL)
  1.1968 +		{
  1.1969 +		INFO_PRINTF1(_L("Returned NULL"));
  1.1970 +		return KErrNone;
  1.1971 +		}
  1.1972 +	else
  1.1973 +		{
  1.1974 +		ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
  1.1975 +		return KErrGeneral;
  1.1976 +		}
  1.1977 +	}
  1.1978 +
  1.1979 +/**
  1.1980 + * Function Name : TestGzseekLongPath
  1.1981 + * TestCase Description: 
  1.1982 + * 1. Seeks a acceptable long file name
  1.1983 + * 2. Checks whether it returns 1 or not
  1.1984 + */
  1.1985 +TInt CTestZlib::TestGzseekLongPath01()
  1.1986 +	{
  1.1987 +	TInt res = KErrNone;
  1.1988 +	gzFile file;
  1.1989 +	uInt size, len;
  1.1990 +	const char *s="\0";
  1.1991 +	len=strlen (s);
  1.1992 +	const char
  1.1993 +			* fname = "c:\\fffff\
  1.1994 +    fffffffffffffffffffffffffffffff\
  1.1995 +    fffffffffffffffffffffffffffffff\
  1.1996 +    fffffffffffffffffffffffffffffff\
  1.1997 +    fffffffffffffffffffffffffffffff\
  1.1998 +    fffffffffffffffffffffffffffffff\
  1.1999 +    fffffffffffffffffffffffffffffff.txt";
  1.2000 +	file = gzopen (fname, "wb");
  1.2001 +	if ( file == Z_NULL)
  1.2002 +		{
  1.2003 +		ERR_PRINTF1(_L("gzopen error"));
  1.2004 +		return KErrGeneral;
  1.2005 +		}
  1.2006 +	size = gzwrite (file, (char*)s, (unsigned)strlen(s));
  1.2007 +	if ( len!=size)
  1.2008 +		{
  1.2009 +		ERR_PRINTF1(_L("gzwrite error"));
  1.2010 +		return KErrGeneral;
  1.2011 +		}
  1.2012 +
  1.2013 +	res = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */
  1.2014 +	gzclose (file);
  1.2015 +	if ( res == 1)
  1.2016 +		{
  1.2017 +		return KErrNone;
  1.2018 +		}
  1.2019 +	else
  1.2020 +		{
  1.2021 +		ERR_PRINTF2(_L("Expected -1, returned %d"), res);
  1.2022 +		return KErrGeneral;
  1.2023 +		}
  1.2024 +	}
  1.2025 +
  1.2026 +/**
  1.2027 + * Function Name : TestGzopenLongPath
  1.2028 + * TestCase Description: 
  1.2029 + * 1. Seeks a long pathed file
  1.2030 + * 2. Checks whether it returns NULL or not
  1.2031 + */
  1.2032 +TInt CTestZlib::TestGzopenLongPath02()
  1.2033 +	{
  1.2034 +	gzFile file;
  1.2035 +	int ret = KErrNone;
  1.2036 +	const char
  1.2037 +			* fname = "C:\\fffff\
  1.2038 +    fffffffffffffffffffffffffffffff\
  1.2039 +    fffffffffffffffffffffffffffffff\
  1.2040 +    fffffffffffffffffffffffffffffff\
  1.2041 +    fffffffffffffffffffffffffffffff\
  1.2042 +    fffffffffffffffffffffffffffffff\
  1.2043 +    fffffffffffffffffffffffffffffff";
  1.2044 +
  1.2045 +	file = gzopen (fname, "wb");
  1.2046 +	if ( file == Z_NULL)
  1.2047 +		{
  1.2048 +		ERR_PRINTF1(_L("gzopen error- File NULL"));
  1.2049 +		return KErrGeneral;
  1.2050 +		}
  1.2051 +	else
  1.2052 +		{
  1.2053 +		INFO_PRINTF1(_L("Expected file pointer, returned Success"));
  1.2054 +		}
  1.2055 +	gzclose (file);
  1.2056 +	return ret;
  1.2057 +	}
  1.2058 +
  1.2059 +/**
  1.2060 + * Function Name : TestGzseekMixedFile01
  1.2061 + * TestCase Description: 
  1.2062 + * 1. Open using gzopen in write mode
  1.2063 + * 2. gzputs a string.
  1.2064 + * 3. fopen it, writes a text, close.
  1.2065 + * 4. Seek one down from current position
  1.2066 + * 5. Checks whether gzseek returns 1 for offset 1L, 
  1.2067 + *    1000L for offset 1000L, -1 for -1L, -1 for -1000L
  1.2068 + */
  1.2069 +TInt CTestZlib::TestGzseekMixedFile01()
  1.2070 +	{
  1.2071 +	const char hello[] = "hello, hello!";
  1.2072 +	int len = (int)strlen(hello)+1;
  1.2073 +	int err;
  1.2074 +	gzFile file;
  1.2075 +
  1.2076 +	TInt offset, expRes;
  1.2077 +
  1.2078 +	ReadIntParam (offset);
  1.2079 +	ReadIntParam (expRes);
  1.2080 +
  1.2081 +	file = gzopen ("c:\\file.txt", "wb");
  1.2082 +	gzputs (file, hello);
  1.2083 +	gzclose (file);
  1.2084 +	FILE *fp = fopen ("c:\\file.txt", "w+");
  1.2085 +	fputc ('h', fp);
  1.2086 +	fclose (fp);
  1.2087 +	file = gzopen ("c:\\file.txt", "rb");
  1.2088 +	if ( file == NULL)
  1.2089 +		{
  1.2090 +		ERR_PRINTF1(_L("gzopen error"));
  1.2091 +		return KErrGeneral;
  1.2092 +		}
  1.2093 +	err = (int) gzseek(file,offset, SEEK_CUR); /* to next pos */
  1.2094 +	gzclose (file);
  1.2095 +	if ( err == expRes)
  1.2096 +		return KErrNone;
  1.2097 +	else
  1.2098 +		{
  1.2099 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err);
  1.2100 +		return KErrGeneral;
  1.2101 +		}
  1.2102 +	}
  1.2103 +
  1.2104 +/**
  1.2105 + * Function Name : TestGzopenNoMode
  1.2106 + * TestCase Description: 
  1.2107 + * 1. gzopen a file with NULL mode
  1.2108 + * 2. Checks whether gzopen returns NULL or not
  1.2109 + */
  1.2110 +TInt CTestZlib::TestGzopenNoMode()
  1.2111 +	{
  1.2112 +	gzFile file;
  1.2113 +	const char * fname = "c:\\file.txt";
  1.2114 +	file = gzopen (fname, NULL);
  1.2115 +	if ( file == Z_NULL)
  1.2116 +		{
  1.2117 +		INFO_PRINTF1(_L("Returned NULL"));
  1.2118 +		return KErrNone;
  1.2119 +		}
  1.2120 +	else
  1.2121 +		{
  1.2122 +		ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
  1.2123 +		return KErrGeneral;
  1.2124 +		}
  1.2125 +	}
  1.2126 +
  1.2127 +/**
  1.2128 + * Function Name : TestGzopenNoPath
  1.2129 + * TestCase Description: 
  1.2130 + * 1. gzopen a file with NULL path
  1.2131 + * 2. Checks whether gzopen returns NULL or not
  1.2132 + */
  1.2133 +TInt CTestZlib::TestGzopenNoPath()
  1.2134 +	{
  1.2135 +	gzFile file;
  1.2136 +	file = gzopen (NULL, "wb");
  1.2137 +	if ( file == Z_NULL)
  1.2138 +		{
  1.2139 +		INFO_PRINTF1(_L("Returned NULL"));
  1.2140 +		return KErrNone;
  1.2141 +		}
  1.2142 +	else
  1.2143 +		{
  1.2144 +		ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
  1.2145 +		return KErrGeneral;
  1.2146 +		}
  1.2147 +	}
  1.2148 +
  1.2149 +/**
  1.2150 + * Function Name : TestGzopenNoPath
  1.2151 + * TestCase Description: 
  1.2152 + * 1. gzopen a file with path,mode empty string, 
  1.2153 + * 2. Checks whether gzopen returns NULL or not
  1.2154 + */
  1.2155 +TInt CTestZlib::TestGzopenNoPathMode()
  1.2156 +	{
  1.2157 +	gzFile file;
  1.2158 +	file = gzopen ("", "");
  1.2159 +	if ( file == Z_NULL)
  1.2160 +		{
  1.2161 +		INFO_PRINTF1(_L("Returned NULL"));
  1.2162 +		return KErrNone;
  1.2163 +		}
  1.2164 +	else
  1.2165 +		{
  1.2166 +		ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
  1.2167 +		return KErrGeneral;
  1.2168 +		}
  1.2169 +	}
  1.2170 +/**
  1.2171 + * Function Name : TestGzseekConcatedFile01
  1.2172 + * TestCase Description: 
  1.2173 + * 1. Open a manually concatinated gz file using gzopen in read mode
  1.2174 + * 2. Seek one down from current position
  1.2175 + * 3. Checks whether gzseek returns 1 for offset 1L, 
  1.2176 + *    -1 for offset 1000L, -1 for -1L, -1 for -1000L
  1.2177 + */
  1.2178 +TInt CTestZlib::TestGzseekConcatedFile01()
  1.2179 +	{
  1.2180 +	int err;
  1.2181 +	gzFile file;
  1.2182 +
  1.2183 +	TInt offset, expRes;
  1.2184 +	ReadIntParam (offset);
  1.2185 +	ReadIntParam (expRes);
  1.2186 +
  1.2187 +	file = gzopen (FILETESTGZCONCAT, "rb");
  1.2188 +	if ( file == NULL)
  1.2189 +		{
  1.2190 +		ERR_PRINTF1(_L("gzopen error"));
  1.2191 +		return KErrGeneral;
  1.2192 +		}
  1.2193 +	err = (int) gzseek(file,offset, SEEK_CUR); // to next pos 
  1.2194 +	gzclose (file);
  1.2195 +	if ( err == expRes)
  1.2196 +		{
  1.2197 +		return KErrNone;
  1.2198 +		}
  1.2199 +	else
  1.2200 +		{
  1.2201 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err);
  1.2202 +		return KErrGeneral;
  1.2203 +		}
  1.2204 +	}
  1.2205 +
  1.2206 +/**
  1.2207 + * Function Name : TestGzopenNoPath
  1.2208 + * TestCase Description: 
  1.2209 + * 1. gzopen a file with valid path, mode: 9, f, h, R, 9, fb, hb, Rb, 
  1.2210 + *    and wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
  1.2211 + * 2. Checks whether gzopen returns NULL all cases, except the last one.
  1.2212 + */
  1.2213 +TInt CTestZlib::TestGzopenDiffMode()
  1.2214 +	{
  1.2215 +	TInt res = KErrNone;
  1.2216 +	gzFile file=Z_NULL;
  1.2217 +	const char * fname=  TESTFILE;
  1.2218 +	char mode[100];
  1.2219 +	TInt expRes;
  1.2220 +	ReadStringParam (mode);
  1.2221 +	ReadIntParam (expRes);
  1.2222 +	file = gzopen (fname, "wb");
  1.2223 +	res = gzputc (file, 'h');
  1.2224 +	res = gzclose (file);
  1.2225 +	file = gzopen (fname, mode);
  1.2226 +	if ( (file == Z_NULL && expRes == 0) || (file != Z_NULL && expRes == 1))
  1.2227 +		{
  1.2228 +		res = KErrNone;
  1.2229 +		}
  1.2230 +	else
  1.2231 +		{
  1.2232 +		res = KErrGeneral;
  1.2233 +		ERR_PRINTF1(_L("Expected NULL, returned nonNULL"));
  1.2234 +		}
  1.2235 +	if ( file)
  1.2236 +		{
  1.2237 +		gzclose (file);
  1.2238 +		}
  1.2239 +	return res;
  1.2240 +	}
  1.2241 +
  1.2242 +/**
  1.2243 + * Function Name : TestGzseekConcatedFile02
  1.2244 + * TestCase Description: 
  1.2245 + * 1. Open a programmatically concatinated gz file using gzopen 
  1.2246 + *    in read mode
  1.2247 + * 2. Seek one down from current position
  1.2248 + * 3. Checks whether gzseek returns 1 for offset 1L, 
  1.2249 + *    -1 for offset 1000L, -1 for -1L, -1 for -1000L
  1.2250 + */
  1.2251 +TInt CTestZlib::TestGzseekConcatedFile02()
  1.2252 +	{
  1.2253 +	int err;
  1.2254 +	gzFile file;
  1.2255 +
  1.2256 +	TInt offset, expRes;
  1.2257 +
  1.2258 +	ReadIntParam (offset);
  1.2259 +	ReadIntParam (expRes);
  1.2260 +	char fname1[13]="c:\\first.gz";
  1.2261 +	char fname2[14]="c:\\second.gz";
  1.2262 +
  1.2263 +	//create 2 gz files
  1.2264 +	file = gzopen (fname1, "w");
  1.2265 +	if ( file == NULL)
  1.2266 +		{
  1.2267 +		ERR_PRINTF1(_L("gzopen error"));
  1.2268 +		return KErrGeneral;
  1.2269 +		}
  1.2270 +	gzputc (file, 'h');
  1.2271 +	gzclose (file);
  1.2272 +	file = gzopen (fname2, "w");
  1.2273 +	if ( file == NULL)
  1.2274 +		{
  1.2275 +		unlink (fname1);
  1.2276 +		ERR_PRINTF1(_L("gzopen error"));
  1.2277 +		return KErrGeneral;
  1.2278 +		}
  1.2279 +	gzputc (file, 'e');
  1.2280 +	gzclose (file);
  1.2281 +
  1.2282 +	//concatenate the two
  1.2283 +	FILE *fpFirst=NULL, *fpSecond=NULL;
  1.2284 +	fpFirst = fopen (fname1, "a");
  1.2285 +	fpSecond = fopen (fname2, "r");
  1.2286 +	char c;
  1.2287 +	for (; !feof(fpSecond);)
  1.2288 +		{
  1.2289 +		c=fgetc (fpSecond);
  1.2290 +		fputc (c, fpFirst);
  1.2291 +		}
  1.2292 +	fclose (fpFirst);
  1.2293 +	fclose (fpSecond);
  1.2294 +
  1.2295 +	//Now seek
  1.2296 +	file = gzopen (fname1, "r");
  1.2297 +	err = (int) gzseek(file,offset, SEEK_CUR); // to next pos 
  1.2298 +	gzclose (file);
  1.2299 +	if ( err == expRes)
  1.2300 +		{
  1.2301 +		unlink (fname1);
  1.2302 +		unlink (fname2);
  1.2303 +		return KErrNone;
  1.2304 +		}
  1.2305 +	else
  1.2306 +		{
  1.2307 +		unlink (fname1);
  1.2308 +		unlink (fname2);
  1.2309 +		ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err);
  1.2310 +		return KErrGeneral;
  1.2311 +		}
  1.2312 +	}
  1.2313 +
  1.2314 +/**
  1.2315 + * Function Name : TestGzprintf01
  1.2316 + * TestCase Description: 
  1.2317 + * 1. Prints an empty string
  1.2318 + * 2. Checks whether  returns 0 
  1.2319 + */
  1.2320 +TInt CTestZlib::TestGzprintf01()
  1.2321 +	{
  1.2322 +	TInt res = KErrGeneral;
  1.2323 +	gzFile file;
  1.2324 +	const char * fname=  TESTFILE;
  1.2325 +	file = gzopen (fname, "wb");
  1.2326 +	if ( file == NULL)
  1.2327 +		{
  1.2328 +		res = KErrNoMemory;
  1.2329 +		return res;
  1.2330 +		}
  1.2331 +	res = gzprintf (file, "");
  1.2332 +	if ( res != 0)
  1.2333 +		{
  1.2334 +		ERR_PRINTF1(_L("gzprintf err"));
  1.2335 +		}
  1.2336 +	else
  1.2337 +		{
  1.2338 +		res = KErrNone;
  1.2339 +		}
  1.2340 +	gzclose (file);
  1.2341 +	return res;
  1.2342 +	}
  1.2343 +/**
  1.2344 + * Function Name : TestGzprintf02
  1.2345 + * TestCase Description: 
  1.2346 + * 1. Prints an large string of length 4097, 4096
  1.2347 + * 2. Checks whether  returns 0, 4095 
  1.2348 + */
  1.2349 +TInt CTestZlib::TestGzprintf02()
  1.2350 +	{
  1.2351 +	TInt res = KErrGeneral;
  1.2352 +	gzFile file;
  1.2353 +	const char * fname=  TESTFILE;
  1.2354 +
  1.2355 +	char largeStr[4098];
  1.2356 +	TInt strLength, expRes;
  1.2357 +	ReadIntParam (strLength);
  1.2358 +	ReadIntParam (expRes);
  1.2359 +
  1.2360 +	//create alarge string
  1.2361 +	for (int i=0; i<strLength;i++)
  1.2362 +		{
  1.2363 +		largeStr[i]='a';
  1.2364 +		}
  1.2365 +	largeStr[strLength]='\0';
  1.2366 +	file = gzopen (fname, "wb");
  1.2367 +	if ( file == NULL)
  1.2368 +		{
  1.2369 +		res = KErrNoMemory;
  1.2370 +		return res;
  1.2371 +		}
  1.2372 +	res = gzprintf (file, largeStr);
  1.2373 +	if ( res != expRes)
  1.2374 +		{
  1.2375 +		ERR_PRINTF1(_L("gzprintf err"));
  1.2376 +		}
  1.2377 +	else
  1.2378 +		{
  1.2379 +		res = KErrNone;
  1.2380 +		}
  1.2381 +	gzclose (file);
  1.2382 +	unlink (TESTFILE);
  1.2383 +	return res;
  1.2384 +	}
  1.2385 +
  1.2386 +/**
  1.2387 + * Function Name : TestGzflushNull
  1.2388 + * TestCase Description: 
  1.2389 + * 1. Flushes a NULL stream
  1.2390 + * 2. Checks whether  returns Z_STREAM_ERROR(-2)
  1.2391 + */
  1.2392 +TInt CTestZlib::TestGzflushNull()
  1.2393 +	{
  1.2394 +	TInt res = KErrNone;
  1.2395 +	gzFile file=  NULL;
  1.2396 +	int l= gzflush (file, Z_FULL_FLUSH);
  1.2397 +	if ( l != Z_STREAM_ERROR)
  1.2398 +		{
  1.2399 +		res = KErrGeneral;
  1.2400 +		}
  1.2401 +	return res;
  1.2402 +	}
  1.2403 +
  1.2404 +/**
  1.2405 + * Function Name : TestGzflushRepeat
  1.2406 + * TestCase Description: 
  1.2407 + * 1. Flushes a valid stream twice
  1.2408 + * 2. Checks whether  returns 0
  1.2409 + */
  1.2410 +TInt CTestZlib::TestGzflushRepeat()
  1.2411 +	{
  1.2412 +	TInt res = KErrNone;
  1.2413 +	gzFile file;
  1.2414 +
  1.2415 +	const char * fname=  TESTFILE;
  1.2416 +	file = gzopen (fname, "wb");
  1.2417 +	if ( file == Z_NULL)
  1.2418 +		{
  1.2419 +		res = KErrNoMemory;
  1.2420 +		return res;
  1.2421 +		}
  1.2422 +	int l= gzflush (file, Z_FULL_FLUSH);
  1.2423 +	if ( l != Z_OK)
  1.2424 +		{
  1.2425 +		res = KErrGeneral;
  1.2426 +		}
  1.2427 +	l= gzflush (file, Z_SYNC_FLUSH);
  1.2428 +	if ( l != Z_OK)
  1.2429 +		{
  1.2430 +		res = KErrGeneral;
  1.2431 +		}
  1.2432 +	int err= gzclose (file);
  1.2433 +	if ( err != Z_OK)
  1.2434 +		{
  1.2435 +		res = KErrGeneral;
  1.2436 +		}
  1.2437 +	return res;
  1.2438 +	}
  1.2439 +
  1.2440 +/**
  1.2441 + * Function Name : TestGzflushHugeBuf
  1.2442 + * TestCase Description: 
  1.2443 + * 1. Flushes a valid stream 
  1.2444 + * 2. Checks whether  returns 0
  1.2445 + */
  1.2446 +TInt CTestZlib::TestGzflushHugeBuf()
  1.2447 +	{
  1.2448 +	TInt res = KErrNone;
  1.2449 +	gzFile file;
  1.2450 +
  1.2451 +	const char * fname=  TESTFILE;
  1.2452 +	file = gzopen (fname, "wb");
  1.2453 +	if ( file == Z_NULL)
  1.2454 +		{
  1.2455 +		res = KErrNoMemory;
  1.2456 +		return res;
  1.2457 +		}
  1.2458 +	for (int i=0; i<16385;i++)
  1.2459 +		{
  1.2460 +		gzputc (file, 'a');
  1.2461 +		}
  1.2462 +
  1.2463 +	int l= gzflush (file, Z_FULL_FLUSH);
  1.2464 +	if ( l != Z_OK)
  1.2465 +		{
  1.2466 +		res = KErrGeneral;
  1.2467 +		}
  1.2468 +	int err= gzclose (file);
  1.2469 +	if ( err != Z_OK)
  1.2470 +		{
  1.2471 +		res = KErrGeneral;
  1.2472 +		}
  1.2473 +	return res;
  1.2474 +	}
  1.2475 +
  1.2476 +/**
  1.2477 + * Function Name : TestGzrewindNull
  1.2478 + * TestCase Description: 
  1.2479 + * 1. Rewinds a NULL stream 
  1.2480 + * 2. Checks whether  returns -1
  1.2481 + */
  1.2482 +TInt CTestZlib::TestGzrewindNull()
  1.2483 +	{
  1.2484 +	TInt res = KErrNone;
  1.2485 +	res = gzrewind (NULL);
  1.2486 +	if ( res == -1)
  1.2487 +		{
  1.2488 +		res = KErrNone;
  1.2489 +		}
  1.2490 +	else
  1.2491 +		{
  1.2492 +		res = KErrGeneral;
  1.2493 +		}
  1.2494 +	return res;
  1.2495 +	}
  1.2496 +
  1.2497 +/**
  1.2498 + * Function Name : TestGzrewindTransparent
  1.2499 + * TestCase Description: 
  1.2500 + * 1. Rewinds a non-gz file stream 
  1.2501 + * 2. Checks whether  returns 1 or not
  1.2502 + */
  1.2503 +TInt CTestZlib::TestGzrewindTransparent()
  1.2504 +	{
  1.2505 +
  1.2506 +	gzFile file;
  1.2507 +	int ret=KErrGeneral;
  1.2508 +	char fname[] = "C:\\gzdirecttest.txt";
  1.2509 +	FILE *fp=NULL;
  1.2510 +	fp=fopen (fname, "w");
  1.2511 +	fputc ('\n', fp);
  1.2512 +	fclose (fp);
  1.2513 +	file = gzopen (fname, "rb");
  1.2514 +	ret = gzdirect (file);
  1.2515 +	if ( ret)
  1.2516 +		{
  1.2517 +		INFO_PRINTF1(_L("Reading a Non GzFile"));
  1.2518 +		ret = gzrewind (file);
  1.2519 +		if ( ret)
  1.2520 +			{
  1.2521 +			ret=KErrGeneral;
  1.2522 +			}
  1.2523 +		else
  1.2524 +			{
  1.2525 +			ret = KErrNone;
  1.2526 +			}
  1.2527 +		}
  1.2528 +	else
  1.2529 +		{
  1.2530 +		ERR_PRINTF1(_L("Error in gzdirect. Expeceted 1, returned 0"));
  1.2531 +		ret=KErrGeneral;
  1.2532 +		}
  1.2533 +	gzclose (file);
  1.2534 +	return ret;
  1.2535 +	}
  1.2536 +
  1.2537 +/**
  1.2538 + * Function Name : TestGzgetsBufNull
  1.2539 + * TestCase Description: 
  1.2540 + * 1. Gets from file into a NULL buffer
  1.2541 + * 2. Checks whether  returns NULL or not
  1.2542 + */
  1.2543 +TInt CTestZlib::TestGzgetsBufNull()
  1.2544 +	{
  1.2545 +
  1.2546 +	const char hello[] = "hello, hello!";
  1.2547 +	int len = (int)strlen(hello)+1;
  1.2548 +	gzFile file;
  1.2549 +	char *buf=NULL;
  1.2550 +	file = gzopen ("c:\\file.gz", "w");
  1.2551 +	if ( file == NULL)
  1.2552 +		{
  1.2553 +		ERR_PRINTF1(_L("gzopen error"));
  1.2554 +		return KErrGeneral;
  1.2555 +		}
  1.2556 +	gzputs (file, hello);
  1.2557 +	gzclose (file);
  1.2558 +	file = gzopen ("c:\\file.gz", "r");
  1.2559 +	buf = gzgets (file, buf, len);
  1.2560 +	gzclose (file);
  1.2561 +	if ( buf == Z_NULL)
  1.2562 +		return KErrNone;
  1.2563 +	else
  1.2564 +		return KErrGeneral;
  1.2565 +	}
  1.2566 +
  1.2567 +/**
  1.2568 + * Function Name : TestGzgetsSmallBuf
  1.2569 + * TestCase Description: 
  1.2570 + * 1. Gets from file into a small buffer
  1.2571 + * 2. Checks whether  returns the string correctly or not
  1.2572 + */
  1.2573 +TInt CTestZlib::TestGzgetsSmallBuf()
  1.2574 +	{
  1.2575 +	const char hello[] = "hello, hello!\n";
  1.2576 +	int len;
  1.2577 +	char expBuf[100];
  1.2578 +	ReadIntParam (len);
  1.2579 +	ReadStringParam (expBuf);
  1.2580 +	gzFile file;
  1.2581 +	char *buf=(char *)malloc(strlen(hello));
  1.2582 +	file = gzopen ("c:\\file.gz", "w");
  1.2583 +	if ( file == NULL)
  1.2584 +		{
  1.2585 +		ERR_PRINTF1(_L("gzopen error"));
  1.2586 +		free (buf);
  1.2587 +		return KErrGeneral;
  1.2588 +		}
  1.2589 +	gzputs (file, hello);
  1.2590 +	gzclose (file);
  1.2591 +	file = gzopen ("c:\\file.gz", "r");
  1.2592 +	buf = gzgets (file, (char *)buf, len);
  1.2593 +	gzclose (file);
  1.2594 +
  1.2595 +	if ( !strcmp(buf,expBuf))
  1.2596 +		{
  1.2597 +		free (buf);
  1.2598 +		return KErrNone;
  1.2599 +		}
  1.2600 +	else
  1.2601 +		{
  1.2602 +		free (buf);
  1.2603 +		return KErrGeneral;
  1.2604 +		}
  1.2605 +	}