compressionlibs/ziplib/test/tef/tlibz/src/tzlibcases.cpp
changeset 31 ce057bb09d0b
child 45 4b03adbd26ca
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name        : tzlibcases.cpp
       
    15 // 
       
    16 //
       
    17 #include <errno.h>
       
    18 #include "tzlib.h"
       
    19 
       
    20 #define CHECK_ERR(err, msg) { \
       
    21     if (err != Z_OK) { \
       
    22        INFO_PRINTF2(_L("Error: %d"), err); \
       
    23         return err; \
       
    24     } \
       
    25 }
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 //Function Name :ReadStringParam
       
    29 //Description:Reads string from ini file
       
    30 //Param : aString is populated with the read string
       
    31 // -----------------------------------------------------------------------------	
       
    32 void CTestZlib::ReadStringParam(char* aString)
       
    33 	{
       
    34 	_LIT( Kparam, "Param%d" );
       
    35 	TBuf<100> pNameBuf;
       
    36 	TPtrC descriptor;
       
    37 	TInt i;
       
    38 
       
    39 	pNameBuf.Format (Kparam, ++iParamCnt);
       
    40 	TBool ret = GetStringFromConfig (ConfigSection (), pNameBuf, descriptor);
       
    41 	if ( descriptor == _L("\"\""))
       
    42 		{
       
    43 		i = 0;
       
    44 		}
       
    45 	else
       
    46 		{
       
    47 		// If the string is quoted, take only the insides
       
    48 		if ( (descriptor[0] == '\"') && (descriptor[descriptor.Length()-1] == '\"'))
       
    49 			{
       
    50 			for (i=0; i<descriptor.Length ()-2; i++)
       
    51 				{
       
    52 				aString[i]=descriptor[i+1];
       
    53 				}
       
    54 			}
       
    55 		// Otherwise,take the whole string
       
    56 		else
       
    57 			{
       
    58 			for (i=0; i<descriptor.Length (); i++)
       
    59 				{
       
    60 				aString[i]=descriptor[i];
       
    61 				}
       
    62 			}
       
    63 		}
       
    64 
       
    65 	aString[i]='\0';
       
    66 	}
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 //Function Name : ReadIntParam
       
    70 //TestCase Description:Reads Int value from ini file
       
    71 //Param : TInt to receive the read integer 
       
    72 // -----------------------------------------------------------------------------
       
    73 void CTestZlib::ReadIntParam(TInt &aInt)
       
    74 	{
       
    75 	_LIT( Kparam, "Param%d" );
       
    76 	TBuf<8> pNameBuf;
       
    77 	TPtrC string;
       
    78 	pNameBuf.Format (Kparam, ++iParamCnt);
       
    79 	TBool res = GetIntFromConfig (ConfigSection (), pNameBuf, aInt);
       
    80 	}
       
    81 
       
    82 //---------------/*COMPRESS AND UNCOMPRESS*/----------------------------------
       
    83 
       
    84 TInt CTestZlib::sec_compress(Byte * compr, uLong comprLen, Byte * uncompr,
       
    85 		uLong uncomprLen)
       
    86 	{
       
    87 
       
    88 	int err;
       
    89 	const char hello[] = "hello, hello!";
       
    90 	uLong len = (uLong)strlen(hello)+1;
       
    91 
       
    92 	err = compress (compr, &comprLen, (const Bytef*)hello, len);
       
    93 	CHECK_ERR(err, "compress");
       
    94 
       
    95 	strcpy ((char*)uncompr, "garbage");
       
    96 
       
    97 	err = uncompress (uncompr, &uncomprLen, compr, comprLen);
       
    98 	CHECK_ERR(err, "uncompress");
       
    99 
       
   100 	if ( strcmp ((char*)uncompr, hello))
       
   101 		{
       
   102 		printf ("Bad uncompress");
       
   103 		return KErrGeneral;
       
   104 		}
       
   105 	else
       
   106 		{
       
   107 		printf ("uncompress(): %s", (char *)uncompr);
       
   108 		}
       
   109 	return err;
       
   110 	}
       
   111 
       
   112 //------------------------------//deflateSetDictionary//-----------------------------------
       
   113 
       
   114 TInt CTestZlib::sec_deflateSetDictionary01(Byte * compr, uLong comprLen,
       
   115 		TInt flush, TInt compression)
       
   116 	{
       
   117 	z_stream c_stream; // compression stream 
       
   118 	int err;
       
   119 	const char hello[] = "hello, hello!";
       
   120 	uLong len = (uLong)strlen(hello)+1;
       
   121 	const Bytef* dictionary=(const Bytef *) hello;
       
   122 	c_stream.zalloc = (alloc_func)0;
       
   123 	c_stream.zfree = (free_func)0;
       
   124 	c_stream.opaque = (voidpf)0;
       
   125 
       
   126 	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
       
   127 
       
   128 	if ( err != Z_OK)
       
   129 		{
       
   130 		INFO_PRINTF2(_L("deflateInit error: %d"), err);
       
   131 		return err;
       
   132 		}
       
   133 	err = deflateSetDictionary (&c_stream, dictionary, 3);
       
   134 	if ( err != Z_OK)
       
   135 		{
       
   136 		ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
       
   137 		deflateEnd (&c_stream);
       
   138 		return err;
       
   139 		}
       
   140 	c_stream.next_in = (Bytef*)hello;
       
   141 	c_stream.next_out = compr;
       
   142 
       
   143 	while (c_stream.total_in != len && c_stream.total_out < comprLen)
       
   144 		{
       
   145 		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
       
   146 		err = deflate (&c_stream, flush);
       
   147 		if ( err != Z_OK)
       
   148 			{
       
   149 			INFO_PRINTF2(_L("deflate return code: %d"), err);
       
   150 			deflateEnd (&c_stream);
       
   151 			return err;
       
   152 			}
       
   153 		}
       
   154 	// Finish the stream, still forcing small buffers: 
       
   155 	for (;;)
       
   156 		{
       
   157 		c_stream.avail_out = 1;
       
   158 		err = deflate (&c_stream, Z_FINISH);
       
   159 		if ( err == Z_STREAM_END)
       
   160 			break;
       
   161 		if ( err != Z_OK)
       
   162 			{
       
   163 			INFO_PRINTF2(_L("deflate error: %d"), err);
       
   164 			deflateEnd (&c_stream);
       
   165 			return err;
       
   166 			}
       
   167 		}
       
   168 
       
   169 	deflateEnd (&c_stream);
       
   170 	return KErrNone;
       
   171 	}
       
   172 
       
   173 TInt CTestZlib::sec_deflateSetDictionary02(TInt compression)
       
   174 	{
       
   175 	z_stream c_stream; // compression stream 
       
   176 	int err;
       
   177 	const char hello[] = "hello, hello!";
       
   178 	uLong len = (uLong)strlen(hello)+1;
       
   179 	const Bytef* dictionary=NULL;
       
   180 	c_stream.zalloc = (alloc_func)0;
       
   181 	c_stream.zfree = (free_func)0;
       
   182 	c_stream.opaque = (voidpf)0;
       
   183 
       
   184 	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
       
   185 
       
   186 	if ( err != Z_OK)
       
   187 		{
       
   188 		INFO_PRINTF2(_L("deflateInit error: %d"), err);
       
   189 		return err;
       
   190 		}
       
   191 	err = deflateSetDictionary (&c_stream, dictionary, 30);
       
   192 	if ( err != Z_OK)
       
   193 		{
       
   194 		ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
       
   195 		deflateEnd (&c_stream);
       
   196 		return err;
       
   197 		}
       
   198 	deflateEnd (&c_stream);
       
   199 	return KErrNone;
       
   200 	}
       
   201 
       
   202 //------------------------------//deflateSetDictionary//-----------------------------------
       
   203 
       
   204 TInt CTestZlib::sec_deflateSetDictionary03(Byte * compr, uLong comprLen,
       
   205 		TInt flush, TInt compression)
       
   206 	{
       
   207 	z_stream c_stream; // compression stream 
       
   208 	int err;
       
   209 	const char hello[] = "hello, hello!";
       
   210 	uLong len = (uLong)strlen(hello)+1;
       
   211 	const Bytef* dictionary=(const Bytef *) hello;
       
   212 	c_stream.zalloc = (alloc_func)0;
       
   213 	c_stream.zfree = (free_func)0;
       
   214 	c_stream.opaque = (voidpf)0;
       
   215 
       
   216 	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
       
   217 
       
   218 	if ( err != Z_OK)
       
   219 		{
       
   220 		INFO_PRINTF2(_L("deflateInit error: %d"), err);
       
   221 		return err;
       
   222 		}
       
   223 	c_stream.next_in = (Bytef*)hello;
       
   224 	c_stream.next_out = compr;
       
   225 
       
   226 	while (c_stream.total_in != len && c_stream.total_out < comprLen)
       
   227 		{
       
   228 		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
       
   229 		err = deflate (&c_stream, flush);
       
   230 		if ( err != Z_OK)
       
   231 			{
       
   232 			INFO_PRINTF2(_L("deflate return code: %d"), err);
       
   233 			deflateEnd (&c_stream);
       
   234 			return err;
       
   235 			}
       
   236 		}
       
   237 	// Finish the stream, still forcing small buffers: 
       
   238 	for (;;)
       
   239 		{
       
   240 		c_stream.avail_out = 1;
       
   241 		err = deflate (&c_stream, Z_FINISH);
       
   242 		if ( err == Z_STREAM_END)
       
   243 			break;
       
   244 		if ( err != Z_OK)
       
   245 			{
       
   246 			INFO_PRINTF2(_L("deflate error: %d"), err);
       
   247 			deflateEnd (&c_stream);
       
   248 			return err;
       
   249 			}
       
   250 		}
       
   251 
       
   252 	deflateEnd (&c_stream);
       
   253 	err = deflateSetDictionary (&c_stream, dictionary, 30);
       
   254 	if ( err != Z_OK)
       
   255 		{
       
   256 		ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
       
   257 		return err;
       
   258 		}
       
   259 
       
   260 	return KErrNone;
       
   261 	}
       
   262 
       
   263 TInt CTestZlib::sec_deflateSetDictionary04(Byte * compr, uLong comprLen,
       
   264 		TInt flush, TInt compression)
       
   265 	{
       
   266 	z_stream c_stream; // compression stream 
       
   267 	int err;
       
   268 	const char hello[] = "hello, hello!";
       
   269 	uLong len = (uLong)strlen(hello)+1;
       
   270 	const char dict[] = "z";
       
   271 
       
   272 	const Bytef* dictionary=(const Bytef *) dict;
       
   273 	c_stream.zalloc = (alloc_func)0;
       
   274 	c_stream.zfree = (free_func)0;
       
   275 	c_stream.opaque = (voidpf)0;
       
   276 
       
   277 	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
       
   278 
       
   279 	if ( err != Z_OK)
       
   280 		{
       
   281 		INFO_PRINTF2(_L("deflateInit error: %d"), err);
       
   282 		return err;
       
   283 		}
       
   284 	err = deflateSetDictionary (&c_stream, dictionary, (uLong)strlen(dict)+1);
       
   285 	if ( err != Z_OK)
       
   286 		{
       
   287 		ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
       
   288 		deflateEnd (&c_stream);
       
   289 		return err;
       
   290 		}
       
   291 	c_stream.next_in = (Bytef*)hello;
       
   292 	c_stream.next_out = compr;
       
   293 
       
   294 	while (c_stream.total_in != len && c_stream.total_out < comprLen)
       
   295 		{
       
   296 		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
       
   297 		err = deflate (&c_stream, flush);
       
   298 		if ( err != Z_OK)
       
   299 			{
       
   300 			INFO_PRINTF2(_L("deflate return code: %d"), err);
       
   301 			deflateEnd (&c_stream);
       
   302 			return err;
       
   303 			}
       
   304 		}
       
   305 	// Finish the stream, still forcing small buffers: 
       
   306 	for (;;)
       
   307 		{
       
   308 		c_stream.avail_out = 1;
       
   309 		err = deflate (&c_stream, Z_FINISH);
       
   310 		if ( err == Z_STREAM_END)
       
   311 			break;
       
   312 		if ( err != Z_OK)
       
   313 			{
       
   314 			INFO_PRINTF2(_L("deflate error: %d"), err);
       
   315 			deflateEnd (&c_stream);
       
   316 			return err;
       
   317 			}
       
   318 		}
       
   319 
       
   320 	deflateEnd (&c_stream);
       
   321 	return KErrNone;
       
   322 	}
       
   323 
       
   324 TInt CTestZlib::sec_deflateSetDictionary05(Byte * compr, uLong comprLen,
       
   325 		TInt flush, TInt compression)
       
   326 	{
       
   327 	z_stream c_stream; // compression stream 
       
   328 	int err;
       
   329 	const char hello[] = "hello, hello!";
       
   330 	uLong len = (uLong)strlen(hello)+1;
       
   331 	const char
       
   332 			dict[] = "abcdefghijklmnopqrstuvwxyz \
       
   333     abcdefghijklmnopqrstuvwxyz \
       
   334     abcdefghijklmnopqrstuvwxyz \
       
   335     abcdefghijklmnopqrstuvwxyz \
       
   336     abcdefghijklmnopqrstuvwxyz \
       
   337     abcdefghijklmnopqrstuvwxyz \
       
   338     abcdefghijklmnopqrstuvwxyz \
       
   339     abcdefghijklmnopqrstuvwxyz \
       
   340     abcdefghijklmnopqrstuvwxyz \
       
   341     abcdefghijklmnopqrstuvwxyz";
       
   342 
       
   343 	const Bytef* dictionary=(const Bytef *) dict;
       
   344 	c_stream.zalloc = (alloc_func)0;
       
   345 	c_stream.zfree = (free_func)0;
       
   346 	c_stream.opaque = (voidpf)0;
       
   347 
       
   348 	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
       
   349 
       
   350 	if ( err != Z_OK)
       
   351 		{
       
   352 		INFO_PRINTF2(_L("deflateInit error: %d"), err);
       
   353 		return err;
       
   354 		}
       
   355 	err = deflateSetDictionary (&c_stream, dictionary, (uLong)strlen(dict)+1);
       
   356 	if ( err != Z_OK)
       
   357 		{
       
   358 		ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
       
   359 		deflateEnd (&c_stream);
       
   360 		return err;
       
   361 		}
       
   362 	c_stream.next_in = (Bytef*)hello;
       
   363 	c_stream.next_out = compr;
       
   364 
       
   365 	while (c_stream.total_in != len && c_stream.total_out < comprLen)
       
   366 		{
       
   367 		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
       
   368 		err = deflate (&c_stream, flush);
       
   369 		if ( err != Z_OK)
       
   370 			{
       
   371 			INFO_PRINTF2(_L("deflate return code: %d"), err);
       
   372 			deflateEnd (&c_stream);
       
   373 			return err;
       
   374 			}
       
   375 		}
       
   376 	// Finish the stream, still forcing small buffers: 
       
   377 	for (;;)
       
   378 		{
       
   379 		c_stream.avail_out = 1;
       
   380 		err = deflate (&c_stream, Z_FINISH);
       
   381 		if ( err == Z_STREAM_END)
       
   382 			break;
       
   383 		if ( err != Z_OK)
       
   384 			{
       
   385 			INFO_PRINTF2(_L("deflate error: %d"), err);
       
   386 			deflateEnd (&c_stream);
       
   387 			return err;
       
   388 			}
       
   389 		}
       
   390 
       
   391 	deflateEnd (&c_stream);
       
   392 	return KErrNone;
       
   393 	}
       
   394 //------------------------------//DEFLATE//-----------------------------------
       
   395 
       
   396 TInt CTestZlib::sec_deflate01( Byte * compr, uLong comprLen, TInt flush,
       
   397 		TInt compression)
       
   398 	{
       
   399 	z_stream c_stream; // compression stream 
       
   400 	int err;
       
   401 	const char hello[] = "hello, hello!";
       
   402 	uLong len = (uLong)strlen(hello)+1;
       
   403 
       
   404 	c_stream.zalloc = (alloc_func)0;
       
   405 	c_stream.zfree = (free_func)0;
       
   406 	c_stream.opaque = (voidpf)0;
       
   407 
       
   408 	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
       
   409 
       
   410 	if ( err != Z_OK)
       
   411 		{
       
   412 		INFO_PRINTF2(_L("deflateInit error: %d"), err);
       
   413 		return err;
       
   414 		}
       
   415 
       
   416 	c_stream.next_in = (Bytef*)hello;
       
   417 	c_stream.next_out = compr;
       
   418 
       
   419 	while (c_stream.total_in != len && c_stream.total_out < comprLen)
       
   420 		{
       
   421 		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
       
   422 		err = deflate (&c_stream, flush);
       
   423 		if ( err != Z_OK)
       
   424 			{
       
   425 			INFO_PRINTF2(_L("deflate return code: %d"), err);
       
   426 			deflateEnd (&c_stream);
       
   427 			return err;
       
   428 			}
       
   429 		}
       
   430 	// Finish the stream, still forcing small buffers: 
       
   431 	for (;;)
       
   432 		{
       
   433 		c_stream.avail_out = 1;
       
   434 		err = deflate (&c_stream, Z_FINISH);
       
   435 		if ( err == Z_STREAM_END)
       
   436 			break;
       
   437 		if ( err != Z_OK)
       
   438 			{
       
   439 			INFO_PRINTF2(_L("deflate error: %d"), err);
       
   440 			deflateEnd (&c_stream);
       
   441 			return err;
       
   442 			}
       
   443 		}
       
   444 
       
   445 	deflateEnd (&c_stream);
       
   446 	return KErrNone;
       
   447 	}
       
   448 
       
   449 TInt CTestZlib::sec_deflate02( Byte * compr, uLong comprLen, TInt flush,
       
   450 		TInt compression)
       
   451 	{
       
   452 	z_stream c_stream; // compression stream 
       
   453 	int err;
       
   454 	const char hello[] = "hello, hello!";
       
   455 	uLong len = (uLong)strlen(hello)+1;
       
   456 
       
   457 	c_stream.zalloc = (alloc_func)0;
       
   458 	c_stream.zfree = (free_func)0;
       
   459 	c_stream.opaque = (voidpf)0;
       
   460 
       
   461 	err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
       
   462 
       
   463 	if ( err != Z_OK)
       
   464 		{
       
   465 		INFO_PRINTF2(_L("deflateInit error: %d"), err);
       
   466 		return err;
       
   467 		}
       
   468 
       
   469 	c_stream.next_in = (Bytef*)hello;
       
   470 	c_stream.next_out = compr;
       
   471 
       
   472 	while (c_stream.total_in != len && c_stream.total_out < comprLen)
       
   473 		{
       
   474 		c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers 
       
   475 		err = deflate (&c_stream, Z_NO_FLUSH);
       
   476 		if ( err != Z_OK)
       
   477 			{
       
   478 			INFO_PRINTF2(_L("deflate return code: %d"), err);
       
   479 			deflateEnd (&c_stream);
       
   480 			return err;
       
   481 			}
       
   482 		}
       
   483 	// Finish the stream, still forcing small buffers: 
       
   484 	for (;;)
       
   485 		{
       
   486 		c_stream.avail_out = 1;
       
   487 		err = deflate (&c_stream, Z_FINISH);
       
   488 		if ( err == Z_STREAM_END)
       
   489 			break;
       
   490 		if ( err != Z_OK)
       
   491 			{
       
   492 			INFO_PRINTF2(_L("deflate error: %d"), err);
       
   493 			deflateEnd (&c_stream);
       
   494 			return err;
       
   495 			}
       
   496 		}
       
   497 
       
   498 	//deflate call after a finish
       
   499 	err = deflate (&c_stream, flush);
       
   500 	deflateEnd (&c_stream);
       
   501 	return err;
       
   502 	}
       
   503 //-------------------------------/INFLATE/----------------------------------
       
   504 
       
   505 TInt CTestZlib::sec_inflate( Byte * compr, uLong comprLen, Byte * uncompr,
       
   506 		uLong uncomprLen, TInt flush)
       
   507 	{
       
   508 	int err;
       
   509 	const char hello[] = "hello, hello!";
       
   510 	z_stream d_stream; // decompression stream 
       
   511 
       
   512 	//strcpy((char*)uncompr, "garbage");
       
   513 
       
   514 	d_stream.zalloc = (alloc_func)0;
       
   515 	d_stream.zfree = (free_func)0;
       
   516 	d_stream.opaque = (voidpf)0;
       
   517 
       
   518 	d_stream.next_in = compr;
       
   519 	d_stream.avail_in = 0;
       
   520 	d_stream.next_out = uncompr;
       
   521 
       
   522 	err = inflateInit (&d_stream);
       
   523 	CHECK_ERR(err, "inflateInit");
       
   524 
       
   525 	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
       
   526 		{
       
   527 		d_stream.avail_in = d_stream.avail_out = 1; // force small buffers 
       
   528 		err = inflate (&d_stream, flush);
       
   529 		if ( err == Z_STREAM_END)
       
   530 			break;
       
   531 		if ( err != Z_OK)
       
   532 			{
       
   533 			inflateEnd (&d_stream);
       
   534 			return err;
       
   535 			}
       
   536 		}
       
   537 
       
   538 	err = inflateEnd (&d_stream);
       
   539 	CHECK_ERR(err, "inflateEnd");
       
   540 
       
   541 	if ( strcmp ((char*)uncompr, hello))
       
   542 		{
       
   543 		ERR_PRINTF1(_L("Bad inflate"));
       
   544 		return KErrGeneral;
       
   545 		}
       
   546 	else
       
   547 		{
       
   548 		INFO_PRINTF1(_L("inflate success"));
       
   549 		}
       
   550 	return 0;
       
   551 	}
       
   552 
       
   553 //256K buffer size to hold streams
       
   554 TInt CTestZlib::sec_inflate_large_buf( Byte * compr, uLong comprLen,
       
   555 		Byte * uncompr, uLong uncomprLen, TInt flush)
       
   556 	{
       
   557 	int err;
       
   558 	const char hello[] = "hello, hello!";
       
   559 	z_stream d_stream; // decompression stream 
       
   560 
       
   561 	//strcpy((char*)uncompr, "garbage");
       
   562 
       
   563 	d_stream.zalloc = (alloc_func)0;
       
   564 	d_stream.zfree = (free_func)0;
       
   565 	d_stream.opaque = (voidpf)0;
       
   566 
       
   567 	d_stream.next_in = compr;
       
   568 	d_stream.avail_in = 0;
       
   569 	d_stream.next_out = uncompr;
       
   570 
       
   571 	err = inflateInit (&d_stream);
       
   572 	CHECK_ERR(err, "inflateInit");
       
   573 
       
   574 	while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
       
   575 		{
       
   576 		d_stream.avail_in = d_stream.avail_out = 262144; // 256K
       
   577 		err = inflate (&d_stream, flush);
       
   578 		if ( err == Z_STREAM_END)
       
   579 			break;
       
   580 		if ( err != Z_OK)
       
   581 			{
       
   582 			inflateEnd (&d_stream);
       
   583 			return err;
       
   584 			}
       
   585 		}
       
   586 
       
   587 	err = inflateEnd (&d_stream);
       
   588 	CHECK_ERR(err, "inflateEnd");
       
   589 
       
   590 	if ( strcmp ((char*)uncompr, hello))
       
   591 		{
       
   592 		ERR_PRINTF1(_L("Bad inflate"));
       
   593 		return KErrGeneral;
       
   594 		}
       
   595 	else
       
   596 		{
       
   597 		INFO_PRINTF1(_L("inflate success"));
       
   598 		}
       
   599 	return 0;
       
   600 	}
       
   601 
       
   602 //----------------------------//GZ OPERATION//--------------------------------
       
   603 
       
   604 TInt CTestZlib::sec_gzio( const char *fname, Byte * uncompr, uLong uncomprLen)
       
   605 	{
       
   606 #ifdef NO_GZCOMPRESS
       
   607 	ERR_PRINTF1(_L("NO_GZCOMPRESS -- gz* functions cannot compress"));
       
   608 #else
       
   609 	const char hello[] = "hello, hello!";
       
   610 	int len = (int)strlen(hello)+1;
       
   611 	gzFile file;
       
   612 	z_off_t pos;
       
   613 
       
   614 	file = gzopen (fname, "wb");
       
   615 	if ( file == NULL)
       
   616 		{
       
   617 		ERR_PRINTF1(_L("gzopen error"));
       
   618 		return KErrGeneral;
       
   619 		}
       
   620 	gzputc (file, 'h');
       
   621 	if ( gzputs (file, "ello")!= 4)
       
   622 		{
       
   623 		gzclose (file);
       
   624 		ERR_PRINTF1(_L("gzputs err"));
       
   625 		return KErrGeneral;
       
   626 		}
       
   627 	if ( gzprintf (file, ", %s!", "hello")!= 8)
       
   628 		{
       
   629 		gzclose (file);
       
   630 		ERR_PRINTF1(_L("gzprintf err:"));
       
   631 		return KErrGeneral;
       
   632 		}
       
   633 
       
   634 	gzseek (file, 1L, SEEK_CUR); // add one zero byte 
       
   635 	gzclose (file);
       
   636 
       
   637 	file = gzopen (fname, "rb");
       
   638 	if ( file == NULL)
       
   639 		{
       
   640 		ERR_PRINTF1(_L("gzopen error"));
       
   641 		return KErrGeneral;
       
   642 		}
       
   643 	strcpy ((char*)uncompr, "garbage");
       
   644 
       
   645 	if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len)
       
   646 		{
       
   647 		gzclose (file);
       
   648 		ERR_PRINTF1(_L("gzread err"));
       
   649 		return KErrGeneral;
       
   650 		}
       
   651 
       
   652 	if ( strcmp ((char*)uncompr, hello))
       
   653 		{
       
   654 		gzclose (file);
       
   655 		ERR_PRINTF1(_L("bad gzread"));
       
   656 		return KErrGeneral;
       
   657 		}
       
   658 
       
   659 	pos = gzseek (file, -8L, SEEK_CUR);
       
   660 	if ( pos != 6 || gztell (file)!= pos)
       
   661 		{
       
   662 		gzclose (file);
       
   663 		ERR_PRINTF3(_L("gzseek error, pos=%ld, gztell=%ld"),(long)pos, (long)gztell(file));
       
   664 		return KErrGeneral;
       
   665 		}
       
   666 
       
   667 	if ( gzgetc (file)!= ' ')
       
   668 		{
       
   669 		gzclose (file);
       
   670 		ERR_PRINTF1(_L("gzgetc error"));
       
   671 		return KErrGeneral;
       
   672 		}
       
   673 
       
   674 	if ( gzungetc (' ', file)!= ' ')
       
   675 		{
       
   676 		gzclose (file);
       
   677 		ERR_PRINTF1(_L("gzungetc error"));
       
   678 		return KErrGeneral;
       
   679 		}
       
   680 
       
   681 	gzgets (file, (char*)uncompr, (int)uncomprLen);
       
   682 
       
   683 	if ( strlen ((char*)uncompr)!= 7)
       
   684 		{
       
   685 		gzclose (file);
       
   686 		// " hello!" 
       
   687 		ERR_PRINTF1(_L("gzgets err after gzseek"));
       
   688 		return KErrGeneral;
       
   689 		}
       
   690 
       
   691 	if ( strcmp ((char*)uncompr, hello + 6))
       
   692 		{
       
   693 		gzclose (file);
       
   694 		ERR_PRINTF1(_L("bad gzgets after gzseek"));
       
   695 		return KErrGeneral;
       
   696 		}
       
   697 
       
   698 	gzclose (file);
       
   699 #endif
       
   700 	return KErrNone;
       
   701 	}
       
   702 
       
   703 TInt CTestZlib::Test_zlibVersion()
       
   704 	{
       
   705 	INFO_PRINTF1(_L("Zlib Test zlibVersion"));
       
   706 	int retVal = 0;
       
   707 
       
   708 	const char *version = zlibVersion ();
       
   709 	if ( strcmp (ZLIB_VERSION, version)== 0)
       
   710 		{
       
   711 		INFO_PRINTF1(_L("Returned version matches!"));
       
   712 		retVal=KErrNone;
       
   713 		}
       
   714 
       
   715 	else
       
   716 		{
       
   717 		ERR_PRINTF1(_L("Return version mismatch!"));
       
   718 		retVal=KErrGeneral;
       
   719 		}
       
   720 	return retVal;
       
   721 	}
       
   722 
       
   723 TInt CTestZlib::Test_compress01()
       
   724 	{
       
   725 	INFO_PRINTF1(_L("Zlib Test compress"));
       
   726 	int retVal = 0;
       
   727 
       
   728 	Byte *comp, *uncomp;
       
   729 	uLong compLen, uncompLen;
       
   730 	compLen = uncompLen = 30;
       
   731 
       
   732 	comp = (Byte*)calloc((uInt)compLen, 1);
       
   733 	if ( comp == NULL)
       
   734 		{
       
   735 		INFO_PRINTF1(_L("Could not allocate memory for comp."));
       
   736 		return KErrNoMemory;
       
   737 		}
       
   738 	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
       
   739 	if ( uncomp == NULL)
       
   740 		{
       
   741 		INFO_PRINTF1(_L("Could not allocate memory for uncomp."));
       
   742 		free (comp);
       
   743 		return KErrNoMemory;
       
   744 		}
       
   745 
       
   746 	retVal = sec_compress (comp, compLen, uncomp, uncompLen);
       
   747 	free (comp);
       
   748 	free (uncomp);
       
   749 	return retVal;
       
   750 	}
       
   751 
       
   752 // Test deflate - normal flow
       
   753 TInt CTestZlib::Test_deflate01()
       
   754 	{
       
   755 	INFO_PRINTF1(_L("Zlib Test deflate"));
       
   756 	int retVal = KErrGeneral;
       
   757 	TInt flush, compression, expRet;
       
   758 
       
   759 	Byte *comp;
       
   760 	uLong compLen;
       
   761 	compLen = 30;
       
   762 	comp = (Byte*)calloc((uInt)compLen, 1);
       
   763 
       
   764 	ReadIntParam (flush);
       
   765 	ReadIntParam (compression);
       
   766 	ReadIntParam (expRet);
       
   767 
       
   768 	retVal = sec_deflate01 (comp, compLen, flush, compression);
       
   769 	free (comp);
       
   770 	if ( retVal != expRet)
       
   771 		{
       
   772 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
   773 		retVal= KErrGeneral;
       
   774 		}
       
   775 	else
       
   776 		{
       
   777 		INFO_PRINTF1(_L("Test passes!"));
       
   778 		retVal= KErrNone;
       
   779 		}
       
   780 	return retVal;
       
   781 	}
       
   782 
       
   783 //Negative test - 
       
   784 TInt CTestZlib::Test_deflate02()
       
   785 	{
       
   786 	INFO_PRINTF1(_L("Zlib Test deflate"));
       
   787 	int retVal = KErrGeneral;
       
   788 	TInt flush, compression, expRet;
       
   789 
       
   790 	Byte *comp;
       
   791 	uLong compLen;
       
   792 	compLen = 30;
       
   793 	comp = (Byte*)calloc((uInt)compLen, 1);
       
   794 
       
   795 	ReadIntParam (flush);
       
   796 	ReadIntParam (compression);
       
   797 	ReadIntParam (expRet);
       
   798 
       
   799 	retVal = sec_deflate02 (comp, compLen, flush, compression);
       
   800 	free (comp);
       
   801 	if ( retVal != expRet)
       
   802 		{
       
   803 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
   804 		retVal= KErrGeneral;
       
   805 		}
       
   806 	else
       
   807 		{
       
   808 		INFO_PRINTF1(_L("Test passes!"));
       
   809 		retVal= KErrNone;
       
   810 		}
       
   811 	return retVal;
       
   812 	}
       
   813 
       
   814 // Test deflate small output buffer
       
   815 TInt CTestZlib::Test_deflateEnd()
       
   816 	{
       
   817 	INFO_PRINTF1(_L("Zlib Test deflateEnd"));
       
   818 
       
   819 	Byte *comp;
       
   820 	uLong compLen;
       
   821 	compLen = 30;
       
   822 
       
   823 	comp = (Byte*)calloc((uInt)compLen, 1);
       
   824 
       
   825 	z_stream c_stream; // compression stream 
       
   826 	int err;
       
   827 	const char hello[] = "hello, hello!";
       
   828 	uLong len = (uLong)strlen(hello)+1;
       
   829 
       
   830 	c_stream.zalloc = (alloc_func)0;
       
   831 	c_stream.zfree = (free_func)0;
       
   832 	c_stream.opaque = (voidpf)0;
       
   833 
       
   834 	err = deflateInit (&c_stream, Z_DEFAULT_COMPRESSION);
       
   835 	if ( err != Z_OK)
       
   836 		{
       
   837 		INFO_PRINTF2(_L("deflateInit failed: %d"), err);
       
   838 		free (comp);
       
   839 		return err;
       
   840 		}
       
   841 
       
   842 	c_stream.next_in = (Bytef*)hello;
       
   843 	c_stream.next_out = comp;
       
   844 	err = deflateEnd (&c_stream);
       
   845 	if ( err != Z_OK)
       
   846 		{
       
   847 		ERR_PRINTF2(_L("deflateEnd failed: %d"), err);
       
   848 		free (comp);
       
   849 		return err;
       
   850 		}
       
   851 	if ( c_stream.state != NULL)
       
   852 		{
       
   853 		ERR_PRINTF1(_L("Stream state expected NULL"));
       
   854 		free (comp);
       
   855 		return err;
       
   856 		}
       
   857 	free (comp);
       
   858 	return KErrNone;
       
   859 	}
       
   860 
       
   861 TInt CTestZlib::Test_inflate01()
       
   862 	{
       
   863 	INFO_PRINTF1(_L("Zlib Test inflate. Positive test"));
       
   864 	int retVal = KErrGeneral;
       
   865 	TInt flush, compression, expRet;
       
   866 	Byte *comp, *uncomp;
       
   867 	uLong compLen, uncompLen;
       
   868 	compLen = uncompLen = 60;
       
   869 
       
   870 	comp = (Byte*)calloc((uInt)compLen, 1);
       
   871 	//comp    = (Byte*)malloc(compLen);
       
   872 	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
       
   873 	//uncomp  = (Byte*)malloc(uncompLen);
       
   874 
       
   875 	ReadIntParam (flush);
       
   876 	ReadIntParam (compression);
       
   877 	ReadIntParam (expRet);
       
   878 
       
   879 	retVal = sec_deflate01 (comp, compLen, flush, compression);
       
   880 	if ( retVal != KErrNone)
       
   881 		{
       
   882 		ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
       
   883 		retVal= KErrGeneral;
       
   884 		}
       
   885 	retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
       
   886 	if ( retVal != expRet)
       
   887 		{
       
   888 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
   889 		retVal= KErrGeneral;
       
   890 		}
       
   891 	else
       
   892 		{
       
   893 		INFO_PRINTF1(_L("Test passes!"));
       
   894 		retVal= KErrNone;
       
   895 		}
       
   896 	free (comp);
       
   897 	free (uncomp);
       
   898 	return retVal;
       
   899 	}
       
   900 
       
   901 //Negative test - invalid deflate data - return Z_DATA_ERROR
       
   902 TInt CTestZlib::Test_inflate02()
       
   903 	{
       
   904 	INFO_PRINTF1(_L("Zlib Test inflate with invalide deflate data"));
       
   905 	int retVal = KErrGeneral;
       
   906 	TInt flush, compression, expRet;
       
   907 	Byte *comp, *uncomp;
       
   908 	uLong compLen, uncompLen;
       
   909 	compLen = uncompLen = 30;
       
   910 
       
   911 	comp = (Byte*)calloc((uInt)compLen, 1);
       
   912 	//comp    = (Byte*)malloc(compLen);
       
   913 	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
       
   914 	//uncomp  = (Byte*)malloc(uncompLen);
       
   915 
       
   916 	ReadIntParam (flush);
       
   917 	ReadIntParam (compression);
       
   918 	ReadIntParam (expRet);
       
   919 
       
   920 	retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
       
   921 	if ( retVal != expRet)
       
   922 		{
       
   923 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
   924 		retVal= KErrGeneral;
       
   925 		}
       
   926 	else
       
   927 		{
       
   928 		INFO_PRINTF1(_L("Test passes!"));
       
   929 		retVal= KErrNone;
       
   930 		}
       
   931 	free (comp);
       
   932 	free (uncomp);
       
   933 	return retVal;
       
   934 	}
       
   935 
       
   936 // uncompressed data buffer inititalized to NULL
       
   937 TInt CTestZlib::Test_inflate03()
       
   938 	{
       
   939 	INFO_PRINTF1(_L("Zlib Test inflate with NULL uncompressed data buffer"));
       
   940 	int retVal = KErrGeneral;
       
   941 	TInt flush, compression, expRet;
       
   942 	Byte *comp=NULL, *uncomp=NULL;
       
   943 	uLong compLen, uncompLen;
       
   944 	compLen = uncompLen = 30;
       
   945 
       
   946 	comp = (Byte*)calloc((uInt)compLen, 1);
       
   947 	//uncomp  = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data
       
   948 
       
   949 	ReadIntParam (flush);
       
   950 	ReadIntParam (compression);
       
   951 	ReadIntParam (expRet);
       
   952 
       
   953 	retVal = sec_deflate01 (comp, compLen, flush, compression);
       
   954 	if ( retVal != KErrNone)
       
   955 		{
       
   956 		ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
       
   957 		retVal= KErrGeneral;
       
   958 		}
       
   959 	retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
       
   960 	if ( retVal != expRet)
       
   961 		{
       
   962 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
   963 		retVal= KErrGeneral;
       
   964 		}
       
   965 	else
       
   966 		{
       
   967 		INFO_PRINTF1(_L("Test passes!"));
       
   968 		retVal= KErrNone;
       
   969 		}
       
   970 	free (comp); //free(uncomp);
       
   971 	return retVal;
       
   972 	}
       
   973 
       
   974 //Not enough buffer size for uncompresed data
       
   975 TInt CTestZlib::Test_inflate04()
       
   976 	{
       
   977 	INFO_PRINTF1(_L("Zlib Test inflatewith not enough buffer size for uncompressed data"));
       
   978 	int retVal = KErrGeneral;
       
   979 	TInt flush, compression, expRet;
       
   980 	Byte *comp=NULL, *uncomp=NULL;
       
   981 	uLong compLen, uncompLen;
       
   982 	compLen = 30;
       
   983 	uncompLen = 5;
       
   984 
       
   985 	comp = (Byte*)calloc((uInt)compLen, 1);
       
   986 	uncomp = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data
       
   987 
       
   988 	ReadIntParam (flush);
       
   989 	ReadIntParam (compression);
       
   990 	ReadIntParam (expRet);
       
   991 
       
   992 	retVal = sec_deflate01 (comp, compLen, flush, compression);
       
   993 	if ( retVal != KErrNone)
       
   994 		{
       
   995 		ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
       
   996 		retVal= KErrGeneral;
       
   997 		}
       
   998 	retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
       
   999 	if ( retVal != expRet)
       
  1000 		{
       
  1001 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
  1002 		retVal= KErrGeneral;
       
  1003 		}
       
  1004 	else
       
  1005 		{
       
  1006 		INFO_PRINTF1(_L("Test passes!"));
       
  1007 		retVal= KErrNone;
       
  1008 		}
       
  1009 	free (comp);
       
  1010 	free (uncomp);
       
  1011 	return retVal;
       
  1012 	}
       
  1013 
       
  1014 //Use 256K sized chunks for inflating
       
  1015 TInt CTestZlib::Test_inflate05()
       
  1016 	{
       
  1017 	INFO_PRINTF1(_L("Zlib Test inflate with 256K sized chunks"));
       
  1018 	int retVal = KErrGeneral;
       
  1019 	TInt flush, compression, expRet;
       
  1020 	Byte *comp=NULL, *uncomp=NULL;
       
  1021 	uLong compLen, uncompLen;
       
  1022 	compLen = 30;
       
  1023 	uncompLen = 30;
       
  1024 
       
  1025 	comp = (Byte*)calloc((uInt)compLen, 1);
       
  1026 	uncomp = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data
       
  1027 
       
  1028 	ReadIntParam (flush);
       
  1029 	ReadIntParam (compression);
       
  1030 	ReadIntParam (expRet);
       
  1031 
       
  1032 	retVal = sec_deflate01 (comp, compLen, flush, compression);
       
  1033 	if ( retVal != KErrNone)
       
  1034 		{
       
  1035 		ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
       
  1036 		retVal= KErrGeneral;
       
  1037 		}
       
  1038 	retVal = sec_inflate_large_buf (comp, compLen, uncomp, uncompLen, flush);
       
  1039 	if ( retVal != expRet)
       
  1040 		{
       
  1041 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
  1042 		retVal= KErrGeneral;
       
  1043 		}
       
  1044 	else
       
  1045 		{
       
  1046 		INFO_PRINTF1(_L("Test passes!"));
       
  1047 		retVal= KErrNone;
       
  1048 		}
       
  1049 	free (comp);
       
  1050 	free (uncomp);
       
  1051 	return retVal;
       
  1052 	}
       
  1053 
       
  1054 TInt CTestZlib::Test_inflate06()
       
  1055 	{
       
  1056 	INFO_PRINTF1(_L("Zlib Test inflate with invalid data"));
       
  1057 	int retVal = KErrGeneral;
       
  1058 	TInt flush, compression, expRet;
       
  1059 	Byte *comp, *uncomp;
       
  1060 	uLong compLen, uncompLen;
       
  1061 	compLen = uncompLen = 60;
       
  1062 
       
  1063 	comp = (Byte*)calloc((uInt)compLen, 1);
       
  1064 	//comp    = (Byte*)malloc(compLen);
       
  1065 	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
       
  1066 	//uncomp  = (Byte*)malloc(uncompLen);
       
  1067 
       
  1068 	ReadIntParam (flush);
       
  1069 	ReadIntParam (compression);
       
  1070 	ReadIntParam (expRet);
       
  1071 
       
  1072 	retVal = sec_deflate01 (comp, compLen, flush, compression);
       
  1073 	if ( retVal != KErrNone)
       
  1074 		{
       
  1075 		ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
       
  1076 		retVal= KErrGeneral;
       
  1077 		}
       
  1078 	
       
  1079 	// Corrupt the compressed data
       
  1080 	comp[0] = 'a';
       
  1081 	comp[1] = 'a';
       
  1082 	
       
  1083 	retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
       
  1084 	if ( retVal != expRet)
       
  1085 		{
       
  1086 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
  1087 		retVal= KErrGeneral;
       
  1088 		}
       
  1089 	else
       
  1090 		{
       
  1091 		INFO_PRINTF1(_L("Test passes!"));
       
  1092 		retVal= KErrNone;
       
  1093 		}
       
  1094 	free (comp);
       
  1095 	free (uncomp);
       
  1096 	return retVal;
       
  1097 	}
       
  1098 
       
  1099 TInt CTestZlib::Test_inflateEnd()
       
  1100 	{
       
  1101 	INFO_PRINTF1(_L("Zlib Test inflateEnd"));
       
  1102 	Byte *comp, *uncomp;
       
  1103 	uLong compLen, uncompLen;
       
  1104 	compLen = uncompLen = 30;
       
  1105 
       
  1106 	comp = (Byte*)calloc((uInt)compLen, 1);
       
  1107 	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
       
  1108 
       
  1109 	int err;
       
  1110 	z_stream d_stream; // decompression stream 
       
  1111 
       
  1112 	//strcpy((char*)uncompr, "garbage");
       
  1113 
       
  1114 	d_stream.zalloc = (alloc_func)0;
       
  1115 	d_stream.zfree = (free_func)0;
       
  1116 	d_stream.opaque = (voidpf)0;
       
  1117 
       
  1118 	d_stream.next_in = comp;
       
  1119 	d_stream.avail_in = 0;
       
  1120 	d_stream.next_out = uncomp;
       
  1121 
       
  1122 	err = inflateInit (&d_stream);
       
  1123 	if ( err != Z_OK)
       
  1124 		{
       
  1125 		INFO_PRINTF2(_L("inflateInit error: %d"), err);
       
  1126 		free (comp);
       
  1127 		free (uncomp);
       
  1128 		return err;
       
  1129 		}
       
  1130 	//Not inflating
       
  1131 
       
  1132 	err = inflateEnd (&d_stream);
       
  1133 	if ( err != Z_OK)
       
  1134 		{
       
  1135 		INFO_PRINTF2(_L("inflateEnd error: %d"), err);
       
  1136 		free (comp);
       
  1137 		free (uncomp);
       
  1138 		return err;
       
  1139 		}
       
  1140 	if ( d_stream.state != NULL)
       
  1141 		{
       
  1142 		INFO_PRINTF2(_L("inflateEnd error: %d"), err);
       
  1143 		free (comp);
       
  1144 		free (uncomp);
       
  1145 		return err;
       
  1146 		}
       
  1147 
       
  1148 	free (comp);
       
  1149 	free (uncomp);
       
  1150 	return KErrNone;
       
  1151 	}
       
  1152 
       
  1153 // Test deflateSetDictionary - normal flow
       
  1154 TInt CTestZlib::Test_deflateSetDictionary01()
       
  1155 	{
       
  1156 	INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - positive test"));
       
  1157 	int retVal = KErrGeneral;
       
  1158 	TInt flush, compression, expRet;
       
  1159 
       
  1160 	Byte *comp;
       
  1161 	uLong compLen;
       
  1162 	compLen = 30;
       
  1163 	comp = (Byte*)calloc((uInt)compLen, 1);
       
  1164 
       
  1165 	ReadIntParam (flush);
       
  1166 	ReadIntParam (compression);
       
  1167 	ReadIntParam (expRet);
       
  1168 
       
  1169 	retVal = sec_deflateSetDictionary01 (comp, compLen, flush, compression);
       
  1170 	free (comp);
       
  1171 	if ( retVal != expRet)
       
  1172 		{
       
  1173 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
  1174 		retVal= KErrGeneral;
       
  1175 		}
       
  1176 	else
       
  1177 		{
       
  1178 		INFO_PRINTF1(_L("Test passes!"));
       
  1179 		retVal= KErrNone;
       
  1180 		}
       
  1181 	return retVal;
       
  1182 	}
       
  1183 
       
  1184 // Test deflateSetDictionary - dictionary NULL
       
  1185 TInt CTestZlib::Test_deflateSetDictionary02()
       
  1186 	{
       
  1187 	INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary with dictionary NULL"));
       
  1188 	int retVal = KErrGeneral;
       
  1189 
       
  1190 	TInt compression, expRet;
       
  1191 
       
  1192 	ReadIntParam (compression);
       
  1193 	ReadIntParam (expRet);
       
  1194 	retVal = sec_deflateSetDictionary02 (compression);
       
  1195 
       
  1196 	if ( retVal != expRet)
       
  1197 		{
       
  1198 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
  1199 		retVal= KErrGeneral;
       
  1200 		}
       
  1201 	else
       
  1202 		{
       
  1203 		INFO_PRINTF1(_L("Test passes!"));
       
  1204 		retVal= KErrNone;
       
  1205 		}
       
  1206 	return retVal;
       
  1207 	}
       
  1208 
       
  1209 // Test deflateSetDictionary - set dictionary after deflate, deflateEnd
       
  1210 TInt CTestZlib::Test_deflateSetDictionary03()
       
  1211 	{
       
  1212 	INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - set dictionary after deflating"));
       
  1213 	int retVal = KErrGeneral;
       
  1214 	TInt flush, compression, expRet;
       
  1215 
       
  1216 	Byte *comp;
       
  1217 	uLong compLen;
       
  1218 	compLen = 30;
       
  1219 	comp = (Byte*)calloc((uInt)compLen, 1);
       
  1220 
       
  1221 	ReadIntParam (flush);
       
  1222 	ReadIntParam (compression);
       
  1223 	ReadIntParam (expRet);
       
  1224 
       
  1225 	retVal = sec_deflateSetDictionary03 (comp, compLen, flush, compression);
       
  1226 	free (comp);
       
  1227 	if ( retVal != expRet)
       
  1228 		{
       
  1229 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
  1230 		retVal= KErrGeneral;
       
  1231 		}
       
  1232 	else
       
  1233 		{
       
  1234 		INFO_PRINTF1(_L("Test passes!"));
       
  1235 		retVal= KErrNone;
       
  1236 		}
       
  1237 	return retVal;
       
  1238 	}
       
  1239 // Test deflateSetDictionary - set tiny dictionary < MIN_MATCH
       
  1240 TInt CTestZlib::Test_deflateSetDictionary04()
       
  1241 	{
       
  1242 	INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - positive test"));
       
  1243 	int retVal = KErrGeneral;
       
  1244 	TInt flush, compression, expRet;
       
  1245 
       
  1246 	Byte *comp;
       
  1247 	uLong compLen;
       
  1248 	compLen = 30;
       
  1249 	comp = (Byte*)calloc((uInt)compLen, 1);
       
  1250 
       
  1251 	ReadIntParam (flush);
       
  1252 	ReadIntParam (compression);
       
  1253 	ReadIntParam (expRet);
       
  1254 
       
  1255 	retVal = sec_deflateSetDictionary04 (comp, compLen, flush, compression);
       
  1256 	free (comp);
       
  1257 	if ( retVal != expRet)
       
  1258 		{
       
  1259 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
  1260 		retVal= KErrGeneral;
       
  1261 		}
       
  1262 	else
       
  1263 		{
       
  1264 		INFO_PRINTF1(_L("Test passes!"));
       
  1265 		retVal= KErrNone;
       
  1266 		}
       
  1267 	return retVal;
       
  1268 	}
       
  1269 
       
  1270 // Test deflateSetDictionary - set large dictionary > MAX_MATCH
       
  1271 TInt CTestZlib::Test_deflateSetDictionary05()
       
  1272 	{
       
  1273 	INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - set large dictionary > MAX_MATCH"));
       
  1274 	int retVal = KErrGeneral;
       
  1275 	TInt flush, compression, expRet;
       
  1276 
       
  1277 	Byte *comp;
       
  1278 	uLong compLen;
       
  1279 	compLen = 30;
       
  1280 	comp = (Byte*)calloc((uInt)compLen, 1);
       
  1281 
       
  1282 	ReadIntParam (flush);
       
  1283 	ReadIntParam (compression);
       
  1284 	ReadIntParam (expRet);
       
  1285 
       
  1286 	retVal = sec_deflateSetDictionary05 (comp, compLen, flush, compression);
       
  1287 	free (comp);
       
  1288 	if ( retVal != expRet)
       
  1289 		{
       
  1290 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
       
  1291 		retVal= KErrGeneral;
       
  1292 		}
       
  1293 	else
       
  1294 		{
       
  1295 		INFO_PRINTF1(_L("Test passes!"));
       
  1296 		retVal= KErrNone;
       
  1297 		}
       
  1298 	return retVal;
       
  1299 	}
       
  1300 
       
  1301 TInt CTestZlib::Test_gzio()
       
  1302 	{
       
  1303 	INFO_PRINTF1(_L("Zlib Test gzio"));
       
  1304 	int retVal = 0;
       
  1305 
       
  1306 	Byte *comp, *uncomp;
       
  1307 	uLong compLen, uncompLen;
       
  1308 	compLen = uncompLen = 30;
       
  1309 
       
  1310 	comp = (Byte*)calloc((uInt)compLen, 1);
       
  1311 	if ( comp == NULL)
       
  1312 		{
       
  1313 		INFO_PRINTF1(_L("Could not allocate memory for comp."));
       
  1314 		return KErrNoMemory;
       
  1315 		}
       
  1316 
       
  1317 	uncomp = (Byte*)calloc((uInt)uncompLen, 1);
       
  1318 	if ( uncomp == NULL)
       
  1319 		{
       
  1320 		INFO_PRINTF1(_L("Could not allocate memory for uncomp."));
       
  1321 		free (comp);
       
  1322 		return KErrNoMemory;
       
  1323 		}
       
  1324 
       
  1325 	retVal = sec_gzio ("C:\\bye.gz", uncomp, uncompLen);
       
  1326 	free (comp);
       
  1327 	free (uncomp);
       
  1328 	return retVal;
       
  1329 	}
       
  1330 
       
  1331 TInt CTestZlib::Test_gzdirect()
       
  1332 	{
       
  1333 	INFO_PRINTF1(_L("gzdirect test: read gz file"));
       
  1334 	TInt res = KErrNone;
       
  1335 	char mode[3];
       
  1336 	gzFile file;
       
  1337 	const char * fname=  TESTFILE;
       
  1338 	ReadStringParam (mode);
       
  1339 	file = gzopen (fname, mode);
       
  1340 	if ( file == NULL)
       
  1341 		{
       
  1342 		res = KErrGeneral;
       
  1343 		return res;
       
  1344 		}
       
  1345 	res = gzdirect (file); //0=success
       
  1346 	gzclose (file);
       
  1347 	return res;
       
  1348 	}
       
  1349 
       
  1350 TInt CTestZlib::Test_gzdirectnull()
       
  1351 	{
       
  1352 	INFO_PRINTF1(_L("gzdirect test: read NULL stream"));
       
  1353 	TInt res = KErrNone;
       
  1354 	gzFile file=NULL;
       
  1355 	res = gzdirect (file); //0=success
       
  1356 	gzclose (file);
       
  1357 	return res;
       
  1358 	}
       
  1359 
       
  1360 TInt CTestZlib::Test_gzclearerr_null()
       
  1361 	{
       
  1362 	TInt res = KErrNone;
       
  1363 	int err;
       
  1364 	gzFile file;
       
  1365 	const char *fname=  NULL;
       
  1366 	file = gzopen (fname, "wb");
       
  1367 	if ( file == NULL)
       
  1368 		{
       
  1369 		res=KErrGeneral;
       
  1370 		}
       
  1371 	gzputc (file, 'h');
       
  1372 	if ( gzputs (file, "ello")!= 5)
       
  1373 		{
       
  1374 		gzprintf (file, "gzputs err");
       
  1375 		res=KErrGeneral;
       
  1376 		}
       
  1377 	err= gzclose (file);
       
  1378 	if ( err != Z_OK)
       
  1379 		{
       
  1380 		res = KErrGeneral;
       
  1381 		}
       
  1382 	gzclearerr (file);
       
  1383 	z_stream *s = (z_stream*)file;
       
  1384 	if ( s == NULL)
       
  1385 		res = KErrNone;
       
  1386 	else
       
  1387 		{
       
  1388 		ERR_PRINTF1(_L("Expected NULL stream. Returned nonNULL"));
       
  1389 		res = KErrGeneral;
       
  1390 		}
       
  1391 	return res;
       
  1392 	}
       
  1393 
       
  1394 TInt CTestZlib::Test_gzclearerr()
       
  1395 	{
       
  1396 
       
  1397 	Byte *compr, *uncompr;
       
  1398 	uLong comprLen = 20*sizeof(int);
       
  1399 
       
  1400 	uLong uncomprLen = comprLen;
       
  1401 	compr = (Byte*)calloc((uInt)comprLen, 1);
       
  1402 	if ( compr == Z_NULL)
       
  1403 		{
       
  1404 		return KErrNoMemory;
       
  1405 		}
       
  1406 	uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
       
  1407 	if ( uncompr == Z_NULL)
       
  1408 		{
       
  1409 		free (compr);
       
  1410 		return KErrNoMemory;
       
  1411 		}
       
  1412 
       
  1413 	INFO_PRINTF1(_L("gzclearerr test"));
       
  1414 	int err;
       
  1415 	int len = (int)strlen(hello)+1;
       
  1416 	gzFile file;
       
  1417 
       
  1418 	file = gzopen (MYFILE, "wb");
       
  1419 	if ( file == NULL)
       
  1420 		{
       
  1421 		err = KErrGeneral;
       
  1422 		free (compr);
       
  1423 		free (uncompr);
       
  1424 		return err;
       
  1425 		}
       
  1426 	gzputc (file, 'h');
       
  1427 	if ( gzputs (file, "ello")!= 4)
       
  1428 		{
       
  1429 		err=KErrGeneral;
       
  1430 		}
       
  1431 	if ( gzprintf (file, ", %s!", "hello")!= 8)
       
  1432 		{
       
  1433 		err=KErrGeneral;
       
  1434 		}
       
  1435 	gzseek (file, 1L, SEEK_CUR); // add one zero byte 
       
  1436 	gzclose (file);
       
  1437 
       
  1438 	file = gzopen (MYFILE, "rb");
       
  1439 	if ( file == NULL)
       
  1440 		{
       
  1441 		err = KErrGeneral;
       
  1442 		free (compr);
       
  1443 		free (uncompr);
       
  1444 		return err;
       
  1445 		}
       
  1446 	strcpy ((char*)uncompr, "garbage");
       
  1447 
       
  1448 	if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len)
       
  1449 		{
       
  1450 		}
       
  1451 	if ( strcmp ((char*)uncompr, hello))
       
  1452 		{
       
  1453 		err=KErrGeneral;
       
  1454 		}
       
  1455 	else
       
  1456 		{
       
  1457 		err=KErrNone;
       
  1458 		}
       
  1459 
       
  1460 	gzseek (file, -8L, SEEK_CUR);
       
  1461 	gzclearerr (file);
       
  1462 	gzgets (file, (char*)uncompr, (int)uncomprLen);
       
  1463 
       
  1464 	if ( strlen ((char*)uncompr)!= 7)
       
  1465 		{
       
  1466 		//1 " hello!" 
       
  1467 		ERR_PRINTF1(_L("gzegets gets wrong string"));
       
  1468 		err=KErrGeneral;
       
  1469 		}
       
  1470 	gzclose (file);
       
  1471 
       
  1472 	free (compr);
       
  1473 	free (uncompr);
       
  1474 	return err;
       
  1475 	}
       
  1476 
       
  1477 TInt CTestZlib::Test_gzerror_streamend()
       
  1478 	{
       
  1479 #ifdef NO_GZCOMPRESS
       
  1480 	ERR_PRINTF1(_L("NO_GZCOMPRESS -- gz* functions cannot compress"));
       
  1481 #else
       
  1482 	const char *msgptr;
       
  1483 	char fname[] = "C:\\bye.gz";
       
  1484 
       
  1485 	Byte *compr, *uncompr;
       
  1486 	uLong comprLen, uncomprLen;
       
  1487 	comprLen = uncomprLen = 30;
       
  1488 
       
  1489 	compr = (Byte*)calloc((uInt)comprLen, 1);
       
  1490 	if ( compr == NULL)
       
  1491 		{
       
  1492 		INFO_PRINTF1(_L("Could not allocate memory for compr."));
       
  1493 		return KErrNoMemory;
       
  1494 		}
       
  1495 
       
  1496 	uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
       
  1497 	if ( uncompr == NULL)
       
  1498 		{
       
  1499 		INFO_PRINTF1(_L("Could not allocate memory for uncompr."));
       
  1500 		free (compr);
       
  1501 		return KErrNoMemory;
       
  1502 		}
       
  1503 
       
  1504 	int err;
       
  1505 	const char hello[] = "hello, hello!";
       
  1506 	int len = (int)strlen(hello)+1;
       
  1507 	gzFile file;
       
  1508 
       
  1509 	file = gzopen (fname, "wb");
       
  1510 	if ( file == NULL)
       
  1511 		{
       
  1512 		ERR_PRINTF1(_L("gzopen error"));
       
  1513 		free (compr);
       
  1514 		free (uncompr);
       
  1515 		return KErrGeneral;
       
  1516 		}
       
  1517 	gzputc (file, 'h');
       
  1518 	if ( gzputs (file, "ello")!= 4)
       
  1519 		{
       
  1520 		ERR_PRINTF1(_L("gzputs err"));
       
  1521 		free (compr);
       
  1522 		free (uncompr);
       
  1523 		return KErrGeneral;
       
  1524 		}
       
  1525 	if ( gzprintf (file, ", %s!", "hello")!= 8)
       
  1526 		{
       
  1527 		ERR_PRINTF1(_L("gzprintf err="));
       
  1528 		free (compr);
       
  1529 		free (uncompr);
       
  1530 		return KErrGeneral;
       
  1531 		}
       
  1532 
       
  1533 	gzseek (file, 1L, SEEK_CUR); // add one zero byte 
       
  1534 	gzclose (file);
       
  1535 
       
  1536 	file = gzopen (fname, "rb");
       
  1537 	if ( file == NULL)
       
  1538 		{
       
  1539 		ERR_PRINTF1(_L("gzopen error"));
       
  1540 		free (compr);
       
  1541 		free (uncompr);
       
  1542 		return KErrGeneral;
       
  1543 		}
       
  1544 	strcpy ((char*)uncompr, "garbage");
       
  1545 
       
  1546 	if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len)
       
  1547 		{
       
  1548 		ERR_PRINTF1(_L("gzread err"));
       
  1549 		free (compr);
       
  1550 		free (uncompr);
       
  1551 		return KErrGeneral;
       
  1552 		}
       
  1553 
       
  1554 	if ( strcmp ((char*)uncompr, hello))
       
  1555 		{
       
  1556 		ERR_PRINTF1(_L("bad gzread"));
       
  1557 		free (compr);
       
  1558 		free (uncompr);
       
  1559 		return KErrGeneral;
       
  1560 		}
       
  1561 
       
  1562 	INFO_PRINTF2(_L("Reached file position %ld"),gzseek(file, -8L, SEEK_CUR));
       
  1563 
       
  1564 	gzgets (file, (char*)uncompr, (int)uncomprLen);
       
  1565 	msgptr = gzerror (file, &err);
       
  1566 	if ( strcmp (msgptr, "C:\\bye.gz: stream end")!= 0)
       
  1567 		{
       
  1568 		// " hello!" 
       
  1569 		ERR_PRINTF1(_L("gzerror err on streamend"));
       
  1570 		free (compr);
       
  1571 		free (uncompr);
       
  1572 		return KErrGeneral;
       
  1573 		}
       
  1574 
       
  1575 	gzclose (file);
       
  1576 	free (compr);
       
  1577 	free (uncompr);
       
  1578 
       
  1579 	if ( err != Z_STREAM_END)
       
  1580 		{
       
  1581 		return KErrGeneral;
       
  1582 		}
       
  1583 	return KErrNone;
       
  1584 #endif
       
  1585 	}
       
  1586 
       
  1587 TInt CTestZlib::Test_gzungetcnegative()
       
  1588 	{
       
  1589 	gzFile file=NULL;
       
  1590 	int ret = gzungetc (' ', file); //NULL stream
       
  1591 	if ( ret != EOF)
       
  1592 		{
       
  1593 		ERR_PRINTF2(_L("gzungetc NULL stream test: Expected EOF but returned %d"),ret);
       
  1594 		return KErrGeneral;
       
  1595 		}
       
  1596 
       
  1597 	const char hello[] = "hello, hello!";
       
  1598 	int len = (int)strlen(hello)+1;
       
  1599 
       
  1600 	file = gzopen ("C:\\bye.gz", "wb");
       
  1601 	if ( file == NULL)
       
  1602 		{
       
  1603 		ERR_PRINTF1(_L("gzopen error"));
       
  1604 		return KErrGeneral;
       
  1605 		}
       
  1606 	gzputc (file, 'h');
       
  1607 	if ( gzputs (file, "ello")!= 4)
       
  1608 		{
       
  1609 		ERR_PRINTF1(_L("gzputs err"));
       
  1610 		gzclose (file);
       
  1611 		return KErrGeneral;
       
  1612 		}
       
  1613 
       
  1614 	ret = gzungetc (' ', file); //non-read mode
       
  1615 	if ( ret != EOF)
       
  1616 		{
       
  1617 		ERR_PRINTF2(_L("gzungetc non-read mode test: Expected EOF but returned %d"),ret);
       
  1618 		gzclose (file);
       
  1619 		return KErrGeneral;
       
  1620 		}
       
  1621 
       
  1622 	gzseek (file, 1L, SEEK_CUR); // add one zero byte 
       
  1623 	gzclose (file);
       
  1624 
       
  1625 	file = gzopen ("C:\\bye.gz", "rb");
       
  1626 	if ( file == NULL)
       
  1627 		{
       
  1628 		ERR_PRINTF1(_L("gzopen error"));
       
  1629 		return KErrGeneral;
       
  1630 		}
       
  1631 
       
  1632 	if ( gzungetc (EOF, file)!= EOF) //ungetc EOF
       
  1633 		{
       
  1634 		gzclose (file);
       
  1635 		ERR_PRINTF1(_L("gzungetc error"));
       
  1636 		return KErrGeneral;
       
  1637 		}
       
  1638 	gzclose (file);
       
  1639 
       
  1640 	return KErrNone;
       
  1641 	}
       
  1642 
       
  1643 TInt CTestZlib::Test_gzseeknegative()
       
  1644 	{
       
  1645 
       
  1646 	int err=0;
       
  1647 
       
  1648 	int len = (int)strlen(hello)+1;
       
  1649 	gzFile file;
       
  1650 
       
  1651 	file = gzopen (TESTFILE, "wb");
       
  1652 	if ( file == NULL)
       
  1653 		{
       
  1654 		return KErrNoMemory;
       
  1655 		}
       
  1656 	gzputc (file, 'h');
       
  1657 
       
  1658 	err= gzseek (file, 1L, SEEK_END); /* add one zero byte */
       
  1659 	if ( err != -1)
       
  1660 		{
       
  1661 		gzclose (file);
       
  1662 		return KErrGeneral;
       
  1663 		}
       
  1664 
       
  1665 	err= gzclose (file);
       
  1666 	file = gzopen (TESTFILE, "rb");
       
  1667 	if ( gzgetc (file)!= 'h')
       
  1668 		{
       
  1669 		gzclose (file);
       
  1670 		ERR_PRINTF1(_L("gzgetc error"));
       
  1671 		return KErrGeneral;
       
  1672 		}
       
  1673 	if ( gzgetc (file)!= EOF)
       
  1674 		{
       
  1675 		gzclose (file);
       
  1676 		ERR_PRINTF1(_L("gzgetc error"));
       
  1677 		return KErrGeneral;
       
  1678 		}
       
  1679 	err= gzseek (file, 1L, SEEK_CUR);
       
  1680 	if ( gzgetc (file)!= -1L)
       
  1681 		{
       
  1682 		gzclose (file);
       
  1683 		ERR_PRINTF1(_L("gzseek error"));
       
  1684 		return KErrGeneral;
       
  1685 		}
       
  1686 	gzclose (file);
       
  1687 	return KErrNone;
       
  1688 	}
       
  1689 
       
  1690 /*TInt CTestZlib::TestGzopenRw()
       
  1691  {
       
  1692  TInt res = KErrNone ;
       
  1693  gzFile file;
       
  1694  char c;
       
  1695  const char *fname = "c:\\Bytes.gz";
       
  1696  file = gzopen(fname, "wr");
       
  1697  if (file == NULL) 
       
  1698  {
       
  1699  res = KErrGeneral;
       
  1700  return res;
       
  1701  }
       
  1702  else
       
  1703  {
       
  1704  res=gzputc(file, 'r');
       
  1705  if(res<0)
       
  1706  {
       
  1707  res = KErrGeneral;
       
  1708  } 
       
  1709  else  
       
  1710  {    	
       
  1711  res = KErrNone;
       
  1712  //gzclearerr(file);
       
  1713  gzseek(file,0, SEEK_SET);
       
  1714  c = gzgetc(file);
       
  1715  if(c == 'r')
       
  1716  {
       
  1717  res = KErrNone;
       
  1718  }
       
  1719  else
       
  1720  {
       
  1721  ERR_PRINTF1(_L("gzgetc error in rw mode. Expected r"));
       
  1722  res=KErrGeneral;		        	
       
  1723  }
       
  1724  }     	
       
  1725  }
       
  1726  gzclose(file);
       
  1727  return res;
       
  1728  }
       
  1729  */
       
  1730 /**
       
  1731  * Function Name : Test_gzdirecttxt
       
  1732  * TestCase Description: 1. Checks whether a normal txt file gives a compressed stream or not
       
  1733  */
       
  1734 TInt CTestZlib::Test_gzdirecttxt()
       
  1735 	{
       
  1736 	gzFile file;
       
  1737 	int ret=KErrGeneral;
       
  1738 	char fname[] = "C:\\gzdirecttest.txt";
       
  1739 	FILE *fp=NULL;
       
  1740 	fp=fopen (fname, "w");
       
  1741 	fputc ('\n', fp);
       
  1742 	fclose (fp);
       
  1743 	file = gzopen (fname, "rb");
       
  1744 	ret = gzdirect (file);
       
  1745 	if ( ret)
       
  1746 		{
       
  1747 		INFO_PRINTF1(_L("Reading a Non GzFile"));
       
  1748 		ret=KErrNone;
       
  1749 		}
       
  1750 	else
       
  1751 		{
       
  1752 		ERR_PRINTF1(_L("Error in gzdirect. Expeceted 1, returned 0"));
       
  1753 		ret=KErrGeneral;
       
  1754 		}
       
  1755 	gzclose (file);
       
  1756 	return ret;
       
  1757 	}
       
  1758 
       
  1759 /**
       
  1760  * Function Name : TestGzungetcChain
       
  1761  * TestCase Description: 1. Checks whether gzungetc ungets the read chars using getc
       
  1762  */
       
  1763 TInt CTestZlib::TestGzungetcChain()
       
  1764 	{
       
  1765 	gzFile file;
       
  1766 	char tmp;
       
  1767 	char fname[] = "C:\\Hello.gz";
       
  1768 	file = gzopen (fname, "wb");
       
  1769 	gzputc (file, 'h');
       
  1770 	if ( gzputs (file, "ello World")!= 10)
       
  1771 		{
       
  1772 		gzclose (file);
       
  1773 		printf ("Error: gzputs\n");
       
  1774 		}
       
  1775 	gzclose (file);
       
  1776 	file = gzopen (fname, "rb");
       
  1777 	while (' ' != ( tmp = gzgetc(file) ))
       
  1778 		{
       
  1779 		gzungetc (tmp, file);
       
  1780 		gzseek (file, 1L, SEEK_CUR);
       
  1781 		}
       
  1782 	gzclose (file);
       
  1783 	return KErrNone;
       
  1784 	}
       
  1785 
       
  1786 /**
       
  1787  * Function Name : TestGzseekBack
       
  1788  * TestCase Description: 1. Checks whether gzseek returns -1
       
  1789  * for backward seeks in files opened in write mode.
       
  1790  */
       
  1791 TInt CTestZlib::TestGzseekBack()
       
  1792 	{
       
  1793 	int err;
       
  1794 	int len = (int)strlen(hello)+1;
       
  1795 	gzFile file;
       
  1796 
       
  1797 	const char * fname=  TESTFILE;
       
  1798 
       
  1799 	file = gzopen (fname, "wb");
       
  1800 	if ( file == NULL)
       
  1801 		{
       
  1802 		err = KErrGeneral;
       
  1803 		return err;
       
  1804 		}
       
  1805 	gzputc (file, 'h');
       
  1806 	if ( gzputs (file, "ello")!= 4)
       
  1807 		{
       
  1808 		err=1;
       
  1809 		}
       
  1810 	if ( gzprintf (file, ", %s!", "hello")!= 8)
       
  1811 		{
       
  1812 		err=1;
       
  1813 		}
       
  1814 	err = (int) gzseek(file,0, SEEK_SET); /* to beg */
       
  1815 	gzclose (file);
       
  1816 	if ( err == -1)
       
  1817 		{
       
  1818 		return KErrNone;
       
  1819 		}
       
  1820 	else
       
  1821 		{
       
  1822 		ERR_PRINTF2(_L("Expected -1, returned %d"),err);
       
  1823 		return KErrGeneral;
       
  1824 		}
       
  1825 	}
       
  1826 
       
  1827 /**
       
  1828  * Function Name : TestGzseekAppend
       
  1829  * TestCase Description: 
       
  1830  * 1. Writes a text file, closes.
       
  1831  * 2. Open using gzopen in append mode
       
  1832  * 3. Writes another character.
       
  1833  * 4. Seek one down from current position
       
  1834  * 5. Checks whether gzseek returns 2
       
  1835  */
       
  1836 TInt CTestZlib::TestGzseekAppend()
       
  1837 	{
       
  1838 	const char hello[] = "hello, hello!";
       
  1839 	int len = (int)strlen(hello)+1;
       
  1840 	int err;
       
  1841 	gzFile file;
       
  1842 
       
  1843 	FILE *fp = fopen ("c:\\file.txt", "wb");
       
  1844 	fputc ('h', fp);
       
  1845 	fclose (fp);
       
  1846 	file = gzopen ("c:\\file.txt", "a");
       
  1847 	if ( file == NULL)
       
  1848 		{
       
  1849 		ERR_PRINTF1(_L("gzopen error"));
       
  1850 		return KErrGeneral;
       
  1851 		}
       
  1852 	gzputc (file, 'h');
       
  1853 	err = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */
       
  1854 	gzclose (file);
       
  1855 	if ( err == 2)
       
  1856 		return KErrNone;
       
  1857 	else
       
  1858 		{
       
  1859 		ERR_PRINTF2(_L("Expected 2, returned %d"),err);
       
  1860 		return KErrGeneral;
       
  1861 		}
       
  1862 	}
       
  1863 
       
  1864 /**
       
  1865  * Function Name : TestGzseekHugeOffset
       
  1866  * TestCase Description: 
       
  1867  * 1. Writes a text file, closes.
       
  1868  * 2. Open using gzopen in append mode
       
  1869  * 3. Writes another character.
       
  1870  * 4. Seek 4097 up from current position
       
  1871  * 5. Checks whether gzseek returns 16386 or not.
       
  1872  */
       
  1873 TInt CTestZlib::TestGzseekHugeOffset()
       
  1874 	{
       
  1875 	const char hello[] = "hello, hello!";
       
  1876 	int len = (int)strlen(hello)+1;
       
  1877 	int err;
       
  1878 	gzFile file;
       
  1879 
       
  1880 	FILE *fp = fopen ("c:\\file.txt", "wb");
       
  1881 	fputc ('h', fp);
       
  1882 	fclose (fp);
       
  1883 	file = gzopen ("c:\\file.txt", "a");
       
  1884 	if ( file == NULL)
       
  1885 		{
       
  1886 		ERR_PRINTF1(_L("gzopen error"));
       
  1887 		return KErrGeneral;
       
  1888 		}
       
  1889 	gzputc (file, 'h');
       
  1890 	err = (int) gzseek(file,16385L, SEEK_CUR); /* advance pos by 16385*/
       
  1891 	gzclose (file);
       
  1892 	if ( err == 16386)
       
  1893 		return KErrNone;
       
  1894 	else
       
  1895 		{
       
  1896 		ERR_PRINTF2(_L("Expected 2, returned %d"),err);
       
  1897 		return KErrGeneral;
       
  1898 		}
       
  1899 	}
       
  1900 
       
  1901 /**
       
  1902  * Function Name : TestGzseekNoSize
       
  1903  * TestCase Description: 
       
  1904  * 1. Seeks a zero sized file
       
  1905  * 2. Checks whether it returns -1 or not
       
  1906  */
       
  1907 TInt CTestZlib::TestGzseekNoSize()
       
  1908 	{
       
  1909 	TInt res = KErrNone;
       
  1910 	gzFile file;
       
  1911 	uInt size, len;
       
  1912 	const char *s="\0";
       
  1913 	len=strlen (s);
       
  1914 	const char * fname=  TESTFILE;
       
  1915 	file = gzopen (fname, "wb");
       
  1916 	if ( file == Z_NULL)
       
  1917 		{
       
  1918 		ERR_PRINTF1(_L("gzopen error"));
       
  1919 		return KErrGeneral;
       
  1920 		}
       
  1921 	size = gzwrite (file, (char*)s, (unsigned)strlen(s));
       
  1922 	if ( len!=size)
       
  1923 		{
       
  1924 		ERR_PRINTF1(_L("gzwrite error"));
       
  1925 		return KErrGeneral;
       
  1926 		}
       
  1927 
       
  1928 	res = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */
       
  1929 	gzclose (file);
       
  1930 	if ( res == 1)
       
  1931 		{
       
  1932 		return KErrNone;
       
  1933 		}
       
  1934 	else
       
  1935 		{
       
  1936 		ERR_PRINTF2(_L("Expected -1, returned %d"), res);
       
  1937 		return KErrGeneral;
       
  1938 		}
       
  1939 	}
       
  1940 
       
  1941 /**
       
  1942  * Function Name : TestGzopenLongPath
       
  1943  * TestCase Description: 
       
  1944  * 1. Seeks a file with long name
       
  1945  * 2. Checks whether gzopen returns NULL or not
       
  1946  */
       
  1947 TInt CTestZlib::TestGzopenLongPath01()
       
  1948 	{
       
  1949 	gzFile file;
       
  1950 	const char
       
  1951 			* fname = "c:\\fffff\
       
  1952     fffffffffffffffffffffffffffffff\
       
  1953     fffffffffffffffffffffffffffffff\
       
  1954     fffffffffffffffffffffffffffffff\
       
  1955     fffffffffffffffffffffffffffffff\
       
  1956     fffffffffffffffffffffffffffffff\
       
  1957     fffffffffffffffffffffffffffffff\
       
  1958     fffffffffffffffffffffffffffffff\
       
  1959     fffffffffffffffffffffffffffffff\
       
  1960     fffffffffffffffffffffffffffffff\
       
  1961     fffffffffffffffffffffffffffffff\
       
  1962     fffffffffffffffffffffffffffffff.txt";
       
  1963 	file = gzopen (fname, "wb");
       
  1964 	if ( file == Z_NULL)
       
  1965 		{
       
  1966 		INFO_PRINTF1(_L("Returned NULL"));
       
  1967 		return KErrNone;
       
  1968 		}
       
  1969 	else
       
  1970 		{
       
  1971 		ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
       
  1972 		return KErrGeneral;
       
  1973 		}
       
  1974 	}
       
  1975 
       
  1976 /**
       
  1977  * Function Name : TestGzseekLongPath
       
  1978  * TestCase Description: 
       
  1979  * 1. Seeks a acceptable long file name
       
  1980  * 2. Checks whether it returns 1 or not
       
  1981  */
       
  1982 TInt CTestZlib::TestGzseekLongPath01()
       
  1983 	{
       
  1984 	TInt res = KErrNone;
       
  1985 	gzFile file;
       
  1986 	uInt size, len;
       
  1987 	const char *s="\0";
       
  1988 	len=strlen (s);
       
  1989 	const char
       
  1990 			* fname = "c:\\fffff\
       
  1991     fffffffffffffffffffffffffffffff\
       
  1992     fffffffffffffffffffffffffffffff\
       
  1993     fffffffffffffffffffffffffffffff\
       
  1994     fffffffffffffffffffffffffffffff\
       
  1995     fffffffffffffffffffffffffffffff\
       
  1996     fffffffffffffffffffffffffffffff.txt";
       
  1997 	file = gzopen (fname, "wb");
       
  1998 	if ( file == Z_NULL)
       
  1999 		{
       
  2000 		ERR_PRINTF1(_L("gzopen error"));
       
  2001 		return KErrGeneral;
       
  2002 		}
       
  2003 	size = gzwrite (file, (char*)s, (unsigned)strlen(s));
       
  2004 	if ( len!=size)
       
  2005 		{
       
  2006 		ERR_PRINTF1(_L("gzwrite error"));
       
  2007 		return KErrGeneral;
       
  2008 		}
       
  2009 
       
  2010 	res = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */
       
  2011 	gzclose (file);
       
  2012 	if ( res == 1)
       
  2013 		{
       
  2014 		return KErrNone;
       
  2015 		}
       
  2016 	else
       
  2017 		{
       
  2018 		ERR_PRINTF2(_L("Expected -1, returned %d"), res);
       
  2019 		return KErrGeneral;
       
  2020 		}
       
  2021 	}
       
  2022 
       
  2023 /**
       
  2024  * Function Name : TestGzopenLongPath
       
  2025  * TestCase Description: 
       
  2026  * 1. Seeks a long pathed file
       
  2027  * 2. Checks whether it returns NULL or not
       
  2028  */
       
  2029 TInt CTestZlib::TestGzopenLongPath02()
       
  2030 	{
       
  2031 	gzFile file;
       
  2032 	int ret = KErrNone;
       
  2033 	const char
       
  2034 			* fname = "C:\\fffff\
       
  2035     fffffffffffffffffffffffffffffff\
       
  2036     fffffffffffffffffffffffffffffff\
       
  2037     fffffffffffffffffffffffffffffff\
       
  2038     fffffffffffffffffffffffffffffff\
       
  2039     fffffffffffffffffffffffffffffff\
       
  2040     fffffffffffffffffffffffffffffff";
       
  2041 
       
  2042 	file = gzopen (fname, "wb");
       
  2043 	if ( file == Z_NULL)
       
  2044 		{
       
  2045 		ERR_PRINTF1(_L("gzopen error- File NULL"));
       
  2046 		return KErrGeneral;
       
  2047 		}
       
  2048 	else
       
  2049 		{
       
  2050 		INFO_PRINTF1(_L("Expected file pointer, returned Success"));
       
  2051 		}
       
  2052 	gzclose (file);
       
  2053 	return ret;
       
  2054 	}
       
  2055 
       
  2056 /**
       
  2057  * Function Name : TestGzseekMixedFile01
       
  2058  * TestCase Description: 
       
  2059  * 1. Open using gzopen in write mode
       
  2060  * 2. gzputs a string.
       
  2061  * 3. fopen it, writes a text, close.
       
  2062  * 4. Seek one down from current position
       
  2063  * 5. Checks whether gzseek returns 1 for offset 1L, 
       
  2064  *    1000L for offset 1000L, -1 for -1L, -1 for -1000L
       
  2065  */
       
  2066 TInt CTestZlib::TestGzseekMixedFile01()
       
  2067 	{
       
  2068 	const char hello[] = "hello, hello!";
       
  2069 	int len = (int)strlen(hello)+1;
       
  2070 	int err;
       
  2071 	gzFile file;
       
  2072 
       
  2073 	TInt offset, expRes;
       
  2074 
       
  2075 	ReadIntParam (offset);
       
  2076 	ReadIntParam (expRes);
       
  2077 
       
  2078 	file = gzopen ("c:\\file.txt", "wb");
       
  2079 	gzputs (file, hello);
       
  2080 	gzclose (file);
       
  2081 	FILE *fp = fopen ("c:\\file.txt", "w+");
       
  2082 	fputc ('h', fp);
       
  2083 	fclose (fp);
       
  2084 	file = gzopen ("c:\\file.txt", "rb");
       
  2085 	if ( file == NULL)
       
  2086 		{
       
  2087 		ERR_PRINTF1(_L("gzopen error"));
       
  2088 		return KErrGeneral;
       
  2089 		}
       
  2090 	err = (int) gzseek(file,offset, SEEK_CUR); /* to next pos */
       
  2091 	gzclose (file);
       
  2092 	if ( err == expRes)
       
  2093 		return KErrNone;
       
  2094 	else
       
  2095 		{
       
  2096 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err);
       
  2097 		return KErrGeneral;
       
  2098 		}
       
  2099 	}
       
  2100 
       
  2101 /**
       
  2102  * Function Name : TestGzopenNoMode
       
  2103  * TestCase Description: 
       
  2104  * 1. gzopen a file with NULL mode
       
  2105  * 2. Checks whether gzopen returns NULL or not
       
  2106  */
       
  2107 TInt CTestZlib::TestGzopenNoMode()
       
  2108 	{
       
  2109 	gzFile file;
       
  2110 	const char * fname = "c:\\file.txt";
       
  2111 	file = gzopen (fname, NULL);
       
  2112 	if ( file == Z_NULL)
       
  2113 		{
       
  2114 		INFO_PRINTF1(_L("Returned NULL"));
       
  2115 		return KErrNone;
       
  2116 		}
       
  2117 	else
       
  2118 		{
       
  2119 		ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
       
  2120 		return KErrGeneral;
       
  2121 		}
       
  2122 	}
       
  2123 
       
  2124 /**
       
  2125  * Function Name : TestGzopenNoPath
       
  2126  * TestCase Description: 
       
  2127  * 1. gzopen a file with NULL path
       
  2128  * 2. Checks whether gzopen returns NULL or not
       
  2129  */
       
  2130 TInt CTestZlib::TestGzopenNoPath()
       
  2131 	{
       
  2132 	gzFile file;
       
  2133 	file = gzopen (NULL, "wb");
       
  2134 	if ( file == Z_NULL)
       
  2135 		{
       
  2136 		INFO_PRINTF1(_L("Returned NULL"));
       
  2137 		return KErrNone;
       
  2138 		}
       
  2139 	else
       
  2140 		{
       
  2141 		ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
       
  2142 		return KErrGeneral;
       
  2143 		}
       
  2144 	}
       
  2145 
       
  2146 /**
       
  2147  * Function Name : TestGzopenNoPath
       
  2148  * TestCase Description: 
       
  2149  * 1. gzopen a file with path,mode empty string, 
       
  2150  * 2. Checks whether gzopen returns NULL or not
       
  2151  */
       
  2152 TInt CTestZlib::TestGzopenNoPathMode()
       
  2153 	{
       
  2154 	gzFile file;
       
  2155 	file = gzopen ("", "");
       
  2156 	if ( file == Z_NULL)
       
  2157 		{
       
  2158 		INFO_PRINTF1(_L("Returned NULL"));
       
  2159 		return KErrNone;
       
  2160 		}
       
  2161 	else
       
  2162 		{
       
  2163 		ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
       
  2164 		return KErrGeneral;
       
  2165 		}
       
  2166 	}
       
  2167 /**
       
  2168  * Function Name : TestGzseekConcatedFile01
       
  2169  * TestCase Description: 
       
  2170  * 1. Open a manually concatinated gz file using gzopen in read mode
       
  2171  * 2. Seek one down from current position
       
  2172  * 3. Checks whether gzseek returns 1 for offset 1L, 
       
  2173  *    -1 for offset 1000L, -1 for -1L, -1 for -1000L
       
  2174  */
       
  2175 TInt CTestZlib::TestGzseekConcatedFile01()
       
  2176 	{
       
  2177 	int err;
       
  2178 	gzFile file;
       
  2179 
       
  2180 	TInt offset, expRes;
       
  2181 	ReadIntParam (offset);
       
  2182 	ReadIntParam (expRes);
       
  2183 
       
  2184 	file = gzopen (FILETESTGZCONCAT, "rb");
       
  2185 	if ( file == NULL)
       
  2186 		{
       
  2187 		ERR_PRINTF1(_L("gzopen error"));
       
  2188 		return KErrGeneral;
       
  2189 		}
       
  2190 	err = (int) gzseek(file,offset, SEEK_CUR); // to next pos 
       
  2191 	gzclose (file);
       
  2192 	if ( err == expRes)
       
  2193 		{
       
  2194 		return KErrNone;
       
  2195 		}
       
  2196 	else
       
  2197 		{
       
  2198 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err);
       
  2199 		return KErrGeneral;
       
  2200 		}
       
  2201 	}
       
  2202 
       
  2203 /**
       
  2204  * Function Name : TestGzopenNoPath
       
  2205  * TestCase Description: 
       
  2206  * 1. gzopen a file with valid path, mode: 9, f, h, R, 9, fb, hb, Rb, 
       
  2207  *    and wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
       
  2208  * 2. Checks whether gzopen returns NULL all cases, except the last one.
       
  2209  */
       
  2210 TInt CTestZlib::TestGzopenDiffMode()
       
  2211 	{
       
  2212 	TInt res = KErrNone;
       
  2213 	gzFile file=Z_NULL;
       
  2214 	const char * fname=  TESTFILE;
       
  2215 	char mode[100];
       
  2216 	TInt expRes;
       
  2217 	ReadStringParam (mode);
       
  2218 	ReadIntParam (expRes);
       
  2219 	file = gzopen (fname, "wb");
       
  2220 	res = gzputc (file, 'h');
       
  2221 	res = gzclose (file);
       
  2222 	file = gzopen (fname, mode);
       
  2223 	if ( (file == Z_NULL && expRes == 0) || (file != Z_NULL && expRes == 1))
       
  2224 		{
       
  2225 		res = KErrNone;
       
  2226 		}
       
  2227 	else
       
  2228 		{
       
  2229 		res = KErrGeneral;
       
  2230 		ERR_PRINTF1(_L("Expected NULL, returned nonNULL"));
       
  2231 		}
       
  2232 	if ( file)
       
  2233 		{
       
  2234 		gzclose (file);
       
  2235 		}
       
  2236 	return res;
       
  2237 	}
       
  2238 
       
  2239 /**
       
  2240  * Function Name : TestGzseekConcatedFile02
       
  2241  * TestCase Description: 
       
  2242  * 1. Open a programmatically concatinated gz file using gzopen 
       
  2243  *    in read mode
       
  2244  * 2. Seek one down from current position
       
  2245  * 3. Checks whether gzseek returns 1 for offset 1L, 
       
  2246  *    -1 for offset 1000L, -1 for -1L, -1 for -1000L
       
  2247  */
       
  2248 TInt CTestZlib::TestGzseekConcatedFile02()
       
  2249 	{
       
  2250 	int err;
       
  2251 	gzFile file;
       
  2252 
       
  2253 	TInt offset, expRes;
       
  2254 
       
  2255 	ReadIntParam (offset);
       
  2256 	ReadIntParam (expRes);
       
  2257 	char fname1[13]="c:\\first.gz";
       
  2258 	char fname2[14]="c:\\second.gz";
       
  2259 
       
  2260 	//create 2 gz files
       
  2261 	file = gzopen (fname1, "w");
       
  2262 	if ( file == NULL)
       
  2263 		{
       
  2264 		ERR_PRINTF1(_L("gzopen error"));
       
  2265 		return KErrGeneral;
       
  2266 		}
       
  2267 	gzputc (file, 'h');
       
  2268 	gzclose (file);
       
  2269 	file = gzopen (fname2, "w");
       
  2270 	if ( file == NULL)
       
  2271 		{
       
  2272 		unlink (fname1);
       
  2273 		ERR_PRINTF1(_L("gzopen error"));
       
  2274 		return KErrGeneral;
       
  2275 		}
       
  2276 	gzputc (file, 'e');
       
  2277 	gzclose (file);
       
  2278 
       
  2279 	//concatenate the two
       
  2280 	FILE *fpFirst=NULL, *fpSecond=NULL;
       
  2281 	fpFirst = fopen (fname1, "a");
       
  2282 	fpSecond = fopen (fname2, "r");
       
  2283 	char c;
       
  2284 	for (; !feof(fpSecond);)
       
  2285 		{
       
  2286 		c=fgetc (fpSecond);
       
  2287 		fputc (c, fpFirst);
       
  2288 		}
       
  2289 	fclose (fpFirst);
       
  2290 	fclose (fpSecond);
       
  2291 
       
  2292 	//Now seek
       
  2293 	file = gzopen (fname1, "r");
       
  2294 	err = (int) gzseek(file,offset, SEEK_CUR); // to next pos 
       
  2295 	gzclose (file);
       
  2296 	if ( err == expRes)
       
  2297 		{
       
  2298 		unlink (fname1);
       
  2299 		unlink (fname2);
       
  2300 		return KErrNone;
       
  2301 		}
       
  2302 	else
       
  2303 		{
       
  2304 		unlink (fname1);
       
  2305 		unlink (fname2);
       
  2306 		ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err);
       
  2307 		return KErrGeneral;
       
  2308 		}
       
  2309 	}
       
  2310 
       
  2311 /**
       
  2312  * Function Name : TestGzprintf01
       
  2313  * TestCase Description: 
       
  2314  * 1. Prints an empty string
       
  2315  * 2. Checks whether  returns 0 
       
  2316  */
       
  2317 TInt CTestZlib::TestGzprintf01()
       
  2318 	{
       
  2319 	TInt res = KErrGeneral;
       
  2320 	gzFile file;
       
  2321 	const char * fname=  TESTFILE;
       
  2322 	file = gzopen (fname, "wb");
       
  2323 	if ( file == NULL)
       
  2324 		{
       
  2325 		res = KErrNoMemory;
       
  2326 		return res;
       
  2327 		}
       
  2328 	res = gzprintf (file, "");
       
  2329 	if ( res != 0)
       
  2330 		{
       
  2331 		ERR_PRINTF1(_L("gzprintf err"));
       
  2332 		}
       
  2333 	else
       
  2334 		{
       
  2335 		res = KErrNone;
       
  2336 		}
       
  2337 	gzclose (file);
       
  2338 	return res;
       
  2339 	}
       
  2340 /**
       
  2341  * Function Name : TestGzprintf02
       
  2342  * TestCase Description: 
       
  2343  * 1. Prints an large string of length 4097, 4096
       
  2344  * 2. Checks whether  returns 0, 4095 
       
  2345  */
       
  2346 TInt CTestZlib::TestGzprintf02()
       
  2347 	{
       
  2348 	TInt res = KErrGeneral;
       
  2349 	gzFile file;
       
  2350 	const char * fname=  TESTFILE;
       
  2351 
       
  2352 	char largeStr[4098];
       
  2353 	TInt strLength, expRes;
       
  2354 	ReadIntParam (strLength);
       
  2355 	ReadIntParam (expRes);
       
  2356 
       
  2357 	//create alarge string
       
  2358 	for (int i=0; i<strLength;i++)
       
  2359 		{
       
  2360 		largeStr[i]='a';
       
  2361 		}
       
  2362 	largeStr[strLength]='\0';
       
  2363 	file = gzopen (fname, "wb");
       
  2364 	if ( file == NULL)
       
  2365 		{
       
  2366 		res = KErrNoMemory;
       
  2367 		return res;
       
  2368 		}
       
  2369 	res = gzprintf (file, largeStr);
       
  2370 	if ( res != expRes)
       
  2371 		{
       
  2372 		ERR_PRINTF1(_L("gzprintf err"));
       
  2373 		}
       
  2374 	else
       
  2375 		{
       
  2376 		res = KErrNone;
       
  2377 		}
       
  2378 	gzclose (file);
       
  2379 	unlink (TESTFILE);
       
  2380 	return res;
       
  2381 	}
       
  2382 
       
  2383 /**
       
  2384  * Function Name : TestGzflushNull
       
  2385  * TestCase Description: 
       
  2386  * 1. Flushes a NULL stream
       
  2387  * 2. Checks whether  returns Z_STREAM_ERROR(-2)
       
  2388  */
       
  2389 TInt CTestZlib::TestGzflushNull()
       
  2390 	{
       
  2391 	TInt res = KErrNone;
       
  2392 	gzFile file=  NULL;
       
  2393 	int l= gzflush (file, Z_FULL_FLUSH);
       
  2394 	if ( l != Z_STREAM_ERROR)
       
  2395 		{
       
  2396 		res = KErrGeneral;
       
  2397 		}
       
  2398 	return res;
       
  2399 	}
       
  2400 
       
  2401 /**
       
  2402  * Function Name : TestGzflushRepeat
       
  2403  * TestCase Description: 
       
  2404  * 1. Flushes a valid stream twice
       
  2405  * 2. Checks whether  returns 0
       
  2406  */
       
  2407 TInt CTestZlib::TestGzflushRepeat()
       
  2408 	{
       
  2409 	TInt res = KErrNone;
       
  2410 	gzFile file;
       
  2411 
       
  2412 	const char * fname=  TESTFILE;
       
  2413 	file = gzopen (fname, "wb");
       
  2414 	if ( file == Z_NULL)
       
  2415 		{
       
  2416 		res = KErrNoMemory;
       
  2417 		return res;
       
  2418 		}
       
  2419 	int l= gzflush (file, Z_FULL_FLUSH);
       
  2420 	if ( l != Z_OK)
       
  2421 		{
       
  2422 		res = KErrGeneral;
       
  2423 		}
       
  2424 	l= gzflush (file, Z_SYNC_FLUSH);
       
  2425 	if ( l != Z_OK)
       
  2426 		{
       
  2427 		res = KErrGeneral;
       
  2428 		}
       
  2429 	int err= gzclose (file);
       
  2430 	if ( err != Z_OK)
       
  2431 		{
       
  2432 		res = KErrGeneral;
       
  2433 		}
       
  2434 	return res;
       
  2435 	}
       
  2436 
       
  2437 /**
       
  2438  * Function Name : TestGzflushHugeBuf
       
  2439  * TestCase Description: 
       
  2440  * 1. Flushes a valid stream 
       
  2441  * 2. Checks whether  returns 0
       
  2442  */
       
  2443 TInt CTestZlib::TestGzflushHugeBuf()
       
  2444 	{
       
  2445 	TInt res = KErrNone;
       
  2446 	gzFile file;
       
  2447 
       
  2448 	const char * fname=  TESTFILE;
       
  2449 	file = gzopen (fname, "wb");
       
  2450 	if ( file == Z_NULL)
       
  2451 		{
       
  2452 		res = KErrNoMemory;
       
  2453 		return res;
       
  2454 		}
       
  2455 	for (int i=0; i<16385;i++)
       
  2456 		{
       
  2457 		gzputc (file, 'a');
       
  2458 		}
       
  2459 
       
  2460 	int l= gzflush (file, Z_FULL_FLUSH);
       
  2461 	if ( l != Z_OK)
       
  2462 		{
       
  2463 		res = KErrGeneral;
       
  2464 		}
       
  2465 	int err= gzclose (file);
       
  2466 	if ( err != Z_OK)
       
  2467 		{
       
  2468 		res = KErrGeneral;
       
  2469 		}
       
  2470 	return res;
       
  2471 	}
       
  2472 
       
  2473 /**
       
  2474  * Function Name : TestGzrewindNull
       
  2475  * TestCase Description: 
       
  2476  * 1. Rewinds a NULL stream 
       
  2477  * 2. Checks whether  returns -1
       
  2478  */
       
  2479 TInt CTestZlib::TestGzrewindNull()
       
  2480 	{
       
  2481 	TInt res = KErrNone;
       
  2482 	res = gzrewind (NULL);
       
  2483 	if ( res == -1)
       
  2484 		{
       
  2485 		res = KErrNone;
       
  2486 		}
       
  2487 	else
       
  2488 		{
       
  2489 		res = KErrGeneral;
       
  2490 		}
       
  2491 	return res;
       
  2492 	}
       
  2493 
       
  2494 /**
       
  2495  * Function Name : TestGzrewindTransparent
       
  2496  * TestCase Description: 
       
  2497  * 1. Rewinds a non-gz file stream 
       
  2498  * 2. Checks whether  returns 1 or not
       
  2499  */
       
  2500 TInt CTestZlib::TestGzrewindTransparent()
       
  2501 	{
       
  2502 
       
  2503 	gzFile file;
       
  2504 	int ret=KErrGeneral;
       
  2505 	char fname[] = "C:\\gzdirecttest.txt";
       
  2506 	FILE *fp=NULL;
       
  2507 	fp=fopen (fname, "w");
       
  2508 	fputc ('\n', fp);
       
  2509 	fclose (fp);
       
  2510 	file = gzopen (fname, "rb");
       
  2511 	ret = gzdirect (file);
       
  2512 	if ( ret)
       
  2513 		{
       
  2514 		INFO_PRINTF1(_L("Reading a Non GzFile"));
       
  2515 		ret = gzrewind (file);
       
  2516 		if ( ret)
       
  2517 			{
       
  2518 			ret=KErrGeneral;
       
  2519 			}
       
  2520 		else
       
  2521 			{
       
  2522 			ret = KErrNone;
       
  2523 			}
       
  2524 		}
       
  2525 	else
       
  2526 		{
       
  2527 		ERR_PRINTF1(_L("Error in gzdirect. Expeceted 1, returned 0"));
       
  2528 		ret=KErrGeneral;
       
  2529 		}
       
  2530 	gzclose (file);
       
  2531 	return ret;
       
  2532 	}
       
  2533 
       
  2534 /**
       
  2535  * Function Name : TestGzgetsBufNull
       
  2536  * TestCase Description: 
       
  2537  * 1. Gets from file into a NULL buffer
       
  2538  * 2. Checks whether  returns NULL or not
       
  2539  */
       
  2540 TInt CTestZlib::TestGzgetsBufNull()
       
  2541 	{
       
  2542 
       
  2543 	const char hello[] = "hello, hello!";
       
  2544 	int len = (int)strlen(hello)+1;
       
  2545 	gzFile file;
       
  2546 	char *buf=NULL;
       
  2547 	file = gzopen ("c:\\file.gz", "w");
       
  2548 	if ( file == NULL)
       
  2549 		{
       
  2550 		ERR_PRINTF1(_L("gzopen error"));
       
  2551 		return KErrGeneral;
       
  2552 		}
       
  2553 	gzputs (file, hello);
       
  2554 	gzclose (file);
       
  2555 	file = gzopen ("c:\\file.gz", "r");
       
  2556 	buf = gzgets (file, buf, len);
       
  2557 	gzclose (file);
       
  2558 	if ( buf == Z_NULL)
       
  2559 		return KErrNone;
       
  2560 	else
       
  2561 		return KErrGeneral;
       
  2562 	}
       
  2563 
       
  2564 /**
       
  2565  * Function Name : TestGzgetsSmallBuf
       
  2566  * TestCase Description: 
       
  2567  * 1. Gets from file into a small buffer
       
  2568  * 2. Checks whether  returns the string correctly or not
       
  2569  */
       
  2570 TInt CTestZlib::TestGzgetsSmallBuf()
       
  2571 	{
       
  2572 	const char hello[] = "hello, hello!\n";
       
  2573 	int len;
       
  2574 	char expBuf[100];
       
  2575 	ReadIntParam (len);
       
  2576 	ReadStringParam (expBuf);
       
  2577 	gzFile file;
       
  2578 	char *buf=(char *)malloc(strlen(hello));
       
  2579 	file = gzopen ("c:\\file.gz", "w");
       
  2580 	if ( file == NULL)
       
  2581 		{
       
  2582 		ERR_PRINTF1(_L("gzopen error"));
       
  2583 		free (buf);
       
  2584 		return KErrGeneral;
       
  2585 		}
       
  2586 	gzputs (file, hello);
       
  2587 	gzclose (file);
       
  2588 	file = gzopen ("c:\\file.gz", "r");
       
  2589 	buf = gzgets (file, (char *)buf, len);
       
  2590 	gzclose (file);
       
  2591 
       
  2592 	if ( !strcmp(buf,expBuf))
       
  2593 		{
       
  2594 		free (buf);
       
  2595 		return KErrNone;
       
  2596 		}
       
  2597 	else
       
  2598 		{
       
  2599 		free (buf);
       
  2600 		return KErrGeneral;
       
  2601 		}
       
  2602 	}