sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Name : tzlibcases.cpp sl@0: // sl@0: // sl@0: #include sl@0: #include "tzlib.h" sl@0: sl@0: #define CHECK_ERR(err, msg) { \ sl@0: if (err != Z_OK) { \ sl@0: INFO_PRINTF2(_L("Error: %d"), err); \ sl@0: return err; \ sl@0: } \ sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: //Function Name :ReadStringParam sl@0: //Description:Reads string from ini file sl@0: //Param : aString is populated with the read string sl@0: // ----------------------------------------------------------------------------- sl@0: void CTestZlib::ReadStringParam(char* aString) sl@0: { sl@0: _LIT( Kparam, "Param%d" ); sl@0: TBuf<100> pNameBuf; sl@0: TPtrC descriptor; sl@0: TInt i; sl@0: sl@0: pNameBuf.Format (Kparam, ++iParamCnt); sl@0: TBool ret = GetStringFromConfig (ConfigSection (), pNameBuf, descriptor); sl@0: if ( descriptor == _L("\"\"")) sl@0: { sl@0: i = 0; sl@0: } sl@0: else sl@0: { sl@0: // If the string is quoted, take only the insides sl@0: if ( (descriptor[0] == '\"') && (descriptor[descriptor.Length()-1] == '\"')) sl@0: { sl@0: for (i=0; i pNameBuf; sl@0: TPtrC string; sl@0: pNameBuf.Format (Kparam, ++iParamCnt); sl@0: TBool res = GetIntFromConfig (ConfigSection (), pNameBuf, aInt); sl@0: } sl@0: sl@0: //---------------/*COMPRESS AND UNCOMPRESS*/---------------------------------- sl@0: sl@0: TInt CTestZlib::sec_compress(Byte * compr, uLong comprLen, Byte * uncompr, sl@0: uLong uncomprLen) sl@0: { sl@0: sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: uLong len = (uLong)strlen(hello)+1; sl@0: sl@0: err = compress (compr, &comprLen, (const Bytef*)hello, len); sl@0: CHECK_ERR(err, "compress"); sl@0: sl@0: strcpy ((char*)uncompr, "garbage"); sl@0: sl@0: err = uncompress (uncompr, &uncomprLen, compr, comprLen); sl@0: CHECK_ERR(err, "uncompress"); sl@0: sl@0: if ( strcmp ((char*)uncompr, hello)) sl@0: { sl@0: printf ("Bad uncompress"); sl@0: return KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: printf ("uncompress(): %s", (char *)uncompr); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: //------------------------------//deflateSetDictionary//----------------------------------- sl@0: sl@0: TInt CTestZlib::sec_deflateSetDictionary01(Byte * compr, uLong comprLen, sl@0: TInt flush, TInt compression) sl@0: { sl@0: z_stream c_stream; // compression stream sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: uLong len = (uLong)strlen(hello)+1; sl@0: const Bytef* dictionary=(const Bytef *) hello; sl@0: c_stream.zalloc = (alloc_func)0; sl@0: c_stream.zfree = (free_func)0; sl@0: c_stream.opaque = (voidpf)0; sl@0: sl@0: err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION); sl@0: sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflateInit error: %d"), err); sl@0: return err; sl@0: } sl@0: err = deflateSetDictionary (&c_stream, dictionary, 3); sl@0: if ( err != Z_OK) sl@0: { sl@0: ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: c_stream.next_in = (Bytef*)hello; sl@0: c_stream.next_out = compr; sl@0: sl@0: while (c_stream.total_in != len && c_stream.total_out < comprLen) sl@0: { sl@0: c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers sl@0: err = deflate (&c_stream, flush); sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate return code: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: // Finish the stream, still forcing small buffers: sl@0: for (;;) sl@0: { sl@0: c_stream.avail_out = 1; sl@0: err = deflate (&c_stream, Z_FINISH); sl@0: if ( err == Z_STREAM_END) sl@0: break; sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate error: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: sl@0: deflateEnd (&c_stream); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestZlib::sec_deflateSetDictionary02(TInt compression) sl@0: { sl@0: z_stream c_stream; // compression stream sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: uLong len = (uLong)strlen(hello)+1; sl@0: const Bytef* dictionary=NULL; sl@0: c_stream.zalloc = (alloc_func)0; sl@0: c_stream.zfree = (free_func)0; sl@0: c_stream.opaque = (voidpf)0; sl@0: sl@0: err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION); sl@0: sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflateInit error: %d"), err); sl@0: return err; sl@0: } sl@0: err = deflateSetDictionary (&c_stream, dictionary, 30); sl@0: if ( err != Z_OK) sl@0: { sl@0: ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: deflateEnd (&c_stream); sl@0: return KErrNone; sl@0: } sl@0: sl@0: //------------------------------//deflateSetDictionary//----------------------------------- sl@0: sl@0: TInt CTestZlib::sec_deflateSetDictionary03(Byte * compr, uLong comprLen, sl@0: TInt flush, TInt compression) sl@0: { sl@0: z_stream c_stream; // compression stream sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: uLong len = (uLong)strlen(hello)+1; sl@0: const Bytef* dictionary=(const Bytef *) hello; sl@0: c_stream.zalloc = (alloc_func)0; sl@0: c_stream.zfree = (free_func)0; sl@0: c_stream.opaque = (voidpf)0; sl@0: sl@0: err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION); sl@0: sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflateInit error: %d"), err); sl@0: return err; sl@0: } sl@0: c_stream.next_in = (Bytef*)hello; sl@0: c_stream.next_out = compr; sl@0: sl@0: while (c_stream.total_in != len && c_stream.total_out < comprLen) sl@0: { sl@0: c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers sl@0: err = deflate (&c_stream, flush); sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate return code: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: // Finish the stream, still forcing small buffers: sl@0: for (;;) sl@0: { sl@0: c_stream.avail_out = 1; sl@0: err = deflate (&c_stream, Z_FINISH); sl@0: if ( err == Z_STREAM_END) sl@0: break; sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate error: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: sl@0: deflateEnd (&c_stream); sl@0: err = deflateSetDictionary (&c_stream, dictionary, 30); sl@0: if ( err != Z_OK) sl@0: { sl@0: ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err); sl@0: return err; sl@0: } sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestZlib::sec_deflateSetDictionary04(Byte * compr, uLong comprLen, sl@0: TInt flush, TInt compression) sl@0: { sl@0: z_stream c_stream; // compression stream sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: uLong len = (uLong)strlen(hello)+1; sl@0: const char dict[] = "z"; sl@0: sl@0: const Bytef* dictionary=(const Bytef *) dict; sl@0: c_stream.zalloc = (alloc_func)0; sl@0: c_stream.zfree = (free_func)0; sl@0: c_stream.opaque = (voidpf)0; sl@0: sl@0: err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION); sl@0: sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflateInit error: %d"), err); sl@0: return err; sl@0: } sl@0: err = deflateSetDictionary (&c_stream, dictionary, (uLong)strlen(dict)+1); sl@0: if ( err != Z_OK) sl@0: { sl@0: ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: c_stream.next_in = (Bytef*)hello; sl@0: c_stream.next_out = compr; sl@0: sl@0: while (c_stream.total_in != len && c_stream.total_out < comprLen) sl@0: { sl@0: c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers sl@0: err = deflate (&c_stream, flush); sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate return code: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: // Finish the stream, still forcing small buffers: sl@0: for (;;) sl@0: { sl@0: c_stream.avail_out = 1; sl@0: err = deflate (&c_stream, Z_FINISH); sl@0: if ( err == Z_STREAM_END) sl@0: break; sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate error: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: sl@0: deflateEnd (&c_stream); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestZlib::sec_deflateSetDictionary05(Byte * compr, uLong comprLen, sl@0: TInt flush, TInt compression) sl@0: { sl@0: z_stream c_stream; // compression stream sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: uLong len = (uLong)strlen(hello)+1; sl@0: const char sl@0: dict[] = "abcdefghijklmnopqrstuvwxyz \ sl@0: abcdefghijklmnopqrstuvwxyz \ sl@0: abcdefghijklmnopqrstuvwxyz \ sl@0: abcdefghijklmnopqrstuvwxyz \ sl@0: abcdefghijklmnopqrstuvwxyz \ sl@0: abcdefghijklmnopqrstuvwxyz \ sl@0: abcdefghijklmnopqrstuvwxyz \ sl@0: abcdefghijklmnopqrstuvwxyz \ sl@0: abcdefghijklmnopqrstuvwxyz \ sl@0: abcdefghijklmnopqrstuvwxyz"; sl@0: sl@0: const Bytef* dictionary=(const Bytef *) dict; sl@0: c_stream.zalloc = (alloc_func)0; sl@0: c_stream.zfree = (free_func)0; sl@0: c_stream.opaque = (voidpf)0; sl@0: sl@0: err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION); sl@0: sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflateInit error: %d"), err); sl@0: return err; sl@0: } sl@0: err = deflateSetDictionary (&c_stream, dictionary, (uLong)strlen(dict)+1); sl@0: if ( err != Z_OK) sl@0: { sl@0: ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: c_stream.next_in = (Bytef*)hello; sl@0: c_stream.next_out = compr; sl@0: sl@0: while (c_stream.total_in != len && c_stream.total_out < comprLen) sl@0: { sl@0: c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers sl@0: err = deflate (&c_stream, flush); sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate return code: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: // Finish the stream, still forcing small buffers: sl@0: for (;;) sl@0: { sl@0: c_stream.avail_out = 1; sl@0: err = deflate (&c_stream, Z_FINISH); sl@0: if ( err == Z_STREAM_END) sl@0: break; sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate error: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: sl@0: deflateEnd (&c_stream); sl@0: return KErrNone; sl@0: } sl@0: //------------------------------//DEFLATE//----------------------------------- sl@0: sl@0: TInt CTestZlib::sec_deflate01( Byte * compr, uLong comprLen, TInt flush, sl@0: TInt compression) sl@0: { sl@0: z_stream c_stream; // compression stream sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: uLong len = (uLong)strlen(hello)+1; sl@0: sl@0: c_stream.zalloc = (alloc_func)0; sl@0: c_stream.zfree = (free_func)0; sl@0: c_stream.opaque = (voidpf)0; sl@0: sl@0: err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION); sl@0: sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflateInit error: %d"), err); sl@0: return err; sl@0: } sl@0: sl@0: c_stream.next_in = (Bytef*)hello; sl@0: c_stream.next_out = compr; sl@0: sl@0: while (c_stream.total_in != len && c_stream.total_out < comprLen) sl@0: { sl@0: c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers sl@0: err = deflate (&c_stream, flush); sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate return code: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: // Finish the stream, still forcing small buffers: sl@0: for (;;) sl@0: { sl@0: c_stream.avail_out = 1; sl@0: err = deflate (&c_stream, Z_FINISH); sl@0: if ( err == Z_STREAM_END) sl@0: break; sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate error: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: sl@0: deflateEnd (&c_stream); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestZlib::sec_deflate02( Byte * compr, uLong comprLen, TInt flush, sl@0: TInt compression) sl@0: { sl@0: z_stream c_stream; // compression stream sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: uLong len = (uLong)strlen(hello)+1; sl@0: sl@0: c_stream.zalloc = (alloc_func)0; sl@0: c_stream.zfree = (free_func)0; sl@0: c_stream.opaque = (voidpf)0; sl@0: sl@0: err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION); sl@0: sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflateInit error: %d"), err); sl@0: return err; sl@0: } sl@0: sl@0: c_stream.next_in = (Bytef*)hello; sl@0: c_stream.next_out = compr; sl@0: sl@0: while (c_stream.total_in != len && c_stream.total_out < comprLen) sl@0: { sl@0: c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers sl@0: err = deflate (&c_stream, Z_NO_FLUSH); sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate return code: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: // Finish the stream, still forcing small buffers: sl@0: for (;;) sl@0: { sl@0: c_stream.avail_out = 1; sl@0: err = deflate (&c_stream, Z_FINISH); sl@0: if ( err == Z_STREAM_END) sl@0: break; sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflate error: %d"), err); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: } sl@0: sl@0: //deflate call after a finish sl@0: err = deflate (&c_stream, flush); sl@0: deflateEnd (&c_stream); sl@0: return err; sl@0: } sl@0: //-------------------------------/INFLATE/---------------------------------- sl@0: sl@0: TInt CTestZlib::sec_inflate( Byte * compr, uLong comprLen, Byte * uncompr, sl@0: uLong uncomprLen, TInt flush) sl@0: { sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: z_stream d_stream; // decompression stream sl@0: sl@0: //strcpy((char*)uncompr, "garbage"); sl@0: sl@0: d_stream.zalloc = (alloc_func)0; sl@0: d_stream.zfree = (free_func)0; sl@0: d_stream.opaque = (voidpf)0; sl@0: sl@0: d_stream.next_in = compr; sl@0: d_stream.avail_in = 0; sl@0: d_stream.next_out = uncompr; sl@0: sl@0: err = inflateInit (&d_stream); sl@0: CHECK_ERR(err, "inflateInit"); sl@0: sl@0: while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) sl@0: { sl@0: d_stream.avail_in = d_stream.avail_out = 1; // force small buffers sl@0: err = inflate (&d_stream, flush); sl@0: if ( err == Z_STREAM_END) sl@0: break; sl@0: if ( err != Z_OK) sl@0: { sl@0: inflateEnd (&d_stream); sl@0: return err; sl@0: } sl@0: } sl@0: sl@0: err = inflateEnd (&d_stream); sl@0: CHECK_ERR(err, "inflateEnd"); sl@0: sl@0: if ( strcmp ((char*)uncompr, hello)) sl@0: { sl@0: ERR_PRINTF1(_L("Bad inflate")); sl@0: return KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("inflate success")); sl@0: } sl@0: return 0; sl@0: } sl@0: sl@0: //256K buffer size to hold streams sl@0: TInt CTestZlib::sec_inflate_large_buf( Byte * compr, uLong comprLen, sl@0: Byte * uncompr, uLong uncomprLen, TInt flush) sl@0: { sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: z_stream d_stream; // decompression stream sl@0: sl@0: //strcpy((char*)uncompr, "garbage"); sl@0: sl@0: d_stream.zalloc = (alloc_func)0; sl@0: d_stream.zfree = (free_func)0; sl@0: d_stream.opaque = (voidpf)0; sl@0: sl@0: d_stream.next_in = compr; sl@0: d_stream.avail_in = 0; sl@0: d_stream.next_out = uncompr; sl@0: sl@0: err = inflateInit (&d_stream); sl@0: CHECK_ERR(err, "inflateInit"); sl@0: sl@0: while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) sl@0: { sl@0: d_stream.avail_in = d_stream.avail_out = 262144; // 256K sl@0: err = inflate (&d_stream, flush); sl@0: if ( err == Z_STREAM_END) sl@0: break; sl@0: if ( err != Z_OK) sl@0: { sl@0: inflateEnd (&d_stream); sl@0: return err; sl@0: } sl@0: } sl@0: sl@0: err = inflateEnd (&d_stream); sl@0: CHECK_ERR(err, "inflateEnd"); sl@0: sl@0: if ( strcmp ((char*)uncompr, hello)) sl@0: { sl@0: ERR_PRINTF1(_L("Bad inflate")); sl@0: return KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("inflate success")); sl@0: } sl@0: return 0; sl@0: } sl@0: sl@0: //----------------------------//GZ OPERATION//-------------------------------- sl@0: sl@0: TInt CTestZlib::sec_gzio( const char *fname, Byte * uncompr, uLong uncomprLen) sl@0: { sl@0: #ifdef NO_GZCOMPRESS sl@0: ERR_PRINTF1(_L("NO_GZCOMPRESS -- gz* functions cannot compress")); sl@0: #else sl@0: const char hello[] = "hello, hello!"; sl@0: int len = (int)strlen(hello)+1; sl@0: gzFile file; sl@0: z_off_t pos; sl@0: sl@0: file = gzopen (fname, "wb"); sl@0: if ( file == NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: gzputc (file, 'h'); sl@0: if ( gzputs (file, "ello")!= 4) sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF1(_L("gzputs err")); sl@0: return KErrGeneral; sl@0: } sl@0: if ( gzprintf (file, ", %s!", "hello")!= 8) sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF1(_L("gzprintf err:")); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: gzseek (file, 1L, SEEK_CUR); // add one zero byte sl@0: gzclose (file); sl@0: sl@0: file = gzopen (fname, "rb"); sl@0: if ( file == NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: strcpy ((char*)uncompr, "garbage"); sl@0: sl@0: if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len) sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF1(_L("gzread err")); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: if ( strcmp ((char*)uncompr, hello)) sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF1(_L("bad gzread")); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: pos = gzseek (file, -8L, SEEK_CUR); sl@0: if ( pos != 6 || gztell (file)!= pos) sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF3(_L("gzseek error, pos=%ld, gztell=%ld"),(long)pos, (long)gztell(file)); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: if ( gzgetc (file)!= ' ') sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF1(_L("gzgetc error")); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: if ( gzungetc (' ', file)!= ' ') sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF1(_L("gzungetc error")); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: gzgets (file, (char*)uncompr, (int)uncomprLen); sl@0: sl@0: if ( strlen ((char*)uncompr)!= 7) sl@0: { sl@0: gzclose (file); sl@0: // " hello!" sl@0: ERR_PRINTF1(_L("gzgets err after gzseek")); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: if ( strcmp ((char*)uncompr, hello + 6)) sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF1(_L("bad gzgets after gzseek")); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: gzclose (file); sl@0: #endif sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_zlibVersion() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test zlibVersion")); sl@0: int retVal = 0; sl@0: sl@0: const char *version = zlibVersion (); sl@0: if ( strcmp (ZLIB_VERSION, version)== 0) sl@0: { sl@0: INFO_PRINTF1(_L("Returned version matches!")); sl@0: retVal=KErrNone; sl@0: } sl@0: sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Return version mismatch!")); sl@0: retVal=KErrGeneral; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_compress01() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test compress")); sl@0: int retVal = 0; sl@0: sl@0: Byte *comp, *uncomp; sl@0: uLong compLen, uncompLen; sl@0: compLen = uncompLen = 30; sl@0: sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: if ( comp == NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Could not allocate memory for comp.")); sl@0: return KErrNoMemory; sl@0: } sl@0: uncomp = (Byte*)calloc((uInt)uncompLen, 1); sl@0: if ( uncomp == NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Could not allocate memory for uncomp.")); sl@0: free (comp); sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: retVal = sec_compress (comp, compLen, uncomp, uncompLen); sl@0: free (comp); sl@0: free (uncomp); sl@0: return retVal; sl@0: } sl@0: sl@0: // Test deflate - normal flow sl@0: TInt CTestZlib::Test_deflate01() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test deflate")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: sl@0: Byte *comp; sl@0: uLong compLen; sl@0: compLen = 30; sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_deflate01 (comp, compLen, flush, compression); sl@0: free (comp); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: //Negative test - sl@0: TInt CTestZlib::Test_deflate02() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test deflate")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: sl@0: Byte *comp; sl@0: uLong compLen; sl@0: compLen = 30; sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_deflate02 (comp, compLen, flush, compression); sl@0: free (comp); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: // Test deflate small output buffer sl@0: TInt CTestZlib::Test_deflateEnd() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test deflateEnd")); sl@0: sl@0: Byte *comp; sl@0: uLong compLen; sl@0: compLen = 30; sl@0: sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: sl@0: z_stream c_stream; // compression stream sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: uLong len = (uLong)strlen(hello)+1; sl@0: sl@0: c_stream.zalloc = (alloc_func)0; sl@0: c_stream.zfree = (free_func)0; sl@0: c_stream.opaque = (voidpf)0; sl@0: sl@0: err = deflateInit (&c_stream, Z_DEFAULT_COMPRESSION); sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("deflateInit failed: %d"), err); sl@0: free (comp); sl@0: return err; sl@0: } sl@0: sl@0: c_stream.next_in = (Bytef*)hello; sl@0: c_stream.next_out = comp; sl@0: err = deflateEnd (&c_stream); sl@0: if ( err != Z_OK) sl@0: { sl@0: ERR_PRINTF2(_L("deflateEnd failed: %d"), err); sl@0: free (comp); sl@0: return err; sl@0: } sl@0: if ( c_stream.state != NULL) sl@0: { sl@0: ERR_PRINTF1(_L("Stream state expected NULL")); sl@0: free (comp); sl@0: return err; sl@0: } sl@0: free (comp); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_inflate01() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test inflate. Positive test")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: Byte *comp, *uncomp; sl@0: uLong compLen, uncompLen; sl@0: compLen = uncompLen = 60; sl@0: sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: //comp = (Byte*)malloc(compLen); sl@0: uncomp = (Byte*)calloc((uInt)uncompLen, 1); sl@0: //uncomp = (Byte*)malloc(uncompLen); sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_deflate01 (comp, compLen, flush, compression); sl@0: if ( retVal != KErrNone) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: free (comp); sl@0: free (uncomp); sl@0: return retVal; sl@0: } sl@0: sl@0: //Negative test - invalid deflate data - return Z_DATA_ERROR sl@0: TInt CTestZlib::Test_inflate02() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test inflate with invalide deflate data")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: Byte *comp, *uncomp; sl@0: uLong compLen, uncompLen; sl@0: compLen = uncompLen = 30; sl@0: sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: //comp = (Byte*)malloc(compLen); sl@0: uncomp = (Byte*)calloc((uInt)uncompLen, 1); sl@0: //uncomp = (Byte*)malloc(uncompLen); sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: free (comp); sl@0: free (uncomp); sl@0: return retVal; sl@0: } sl@0: sl@0: // uncompressed data buffer inititalized to NULL sl@0: TInt CTestZlib::Test_inflate03() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test inflate with NULL uncompressed data buffer")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: Byte *comp=NULL, *uncomp=NULL; sl@0: uLong compLen, uncompLen; sl@0: compLen = uncompLen = 30; sl@0: sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: //uncomp = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_deflate01 (comp, compLen, flush, compression); sl@0: if ( retVal != KErrNone) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: free (comp); //free(uncomp); sl@0: return retVal; sl@0: } sl@0: sl@0: //Not enough buffer size for uncompresed data sl@0: TInt CTestZlib::Test_inflate04() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test inflatewith not enough buffer size for uncompressed data")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: Byte *comp=NULL, *uncomp=NULL; sl@0: uLong compLen, uncompLen; sl@0: compLen = 30; sl@0: uncompLen = 5; sl@0: sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: uncomp = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_deflate01 (comp, compLen, flush, compression); sl@0: if ( retVal != KErrNone) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: free (comp); sl@0: free (uncomp); sl@0: return retVal; sl@0: } sl@0: sl@0: //Use 256K sized chunks for inflating sl@0: TInt CTestZlib::Test_inflate05() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test inflate with 256K sized chunks")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: Byte *comp=NULL, *uncomp=NULL; sl@0: uLong compLen, uncompLen; sl@0: compLen = 30; sl@0: uncompLen = 30; sl@0: sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: uncomp = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_deflate01 (comp, compLen, flush, compression); sl@0: if ( retVal != KErrNone) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: retVal = sec_inflate_large_buf (comp, compLen, uncomp, uncompLen, flush); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: free (comp); sl@0: free (uncomp); sl@0: return retVal; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_inflate06() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test inflate with invalid data")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: Byte *comp, *uncomp; sl@0: uLong compLen, uncompLen; sl@0: compLen = uncompLen = 60; sl@0: sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: //comp = (Byte*)malloc(compLen); sl@0: uncomp = (Byte*)calloc((uInt)uncompLen, 1); sl@0: //uncomp = (Byte*)malloc(uncompLen); sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_deflate01 (comp, compLen, flush, compression); sl@0: if ( retVal != KErrNone) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: sl@0: // Corrupt the compressed data sl@0: comp[0] = 'a'; sl@0: comp[1] = 'a'; sl@0: sl@0: retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: free (comp); sl@0: free (uncomp); sl@0: return retVal; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_inflateEnd() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test inflateEnd")); sl@0: Byte *comp, *uncomp; sl@0: uLong compLen, uncompLen; sl@0: compLen = uncompLen = 30; sl@0: sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: uncomp = (Byte*)calloc((uInt)uncompLen, 1); sl@0: sl@0: int err; sl@0: z_stream d_stream; // decompression stream sl@0: sl@0: //strcpy((char*)uncompr, "garbage"); sl@0: sl@0: d_stream.zalloc = (alloc_func)0; sl@0: d_stream.zfree = (free_func)0; sl@0: d_stream.opaque = (voidpf)0; sl@0: sl@0: d_stream.next_in = comp; sl@0: d_stream.avail_in = 0; sl@0: d_stream.next_out = uncomp; sl@0: sl@0: err = inflateInit (&d_stream); sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("inflateInit error: %d"), err); sl@0: free (comp); sl@0: free (uncomp); sl@0: return err; sl@0: } sl@0: //Not inflating sl@0: sl@0: err = inflateEnd (&d_stream); sl@0: if ( err != Z_OK) sl@0: { sl@0: INFO_PRINTF2(_L("inflateEnd error: %d"), err); sl@0: free (comp); sl@0: free (uncomp); sl@0: return err; sl@0: } sl@0: if ( d_stream.state != NULL) sl@0: { sl@0: INFO_PRINTF2(_L("inflateEnd error: %d"), err); sl@0: free (comp); sl@0: free (uncomp); sl@0: return err; sl@0: } sl@0: sl@0: free (comp); sl@0: free (uncomp); sl@0: return KErrNone; sl@0: } sl@0: sl@0: // Test deflateSetDictionary - normal flow sl@0: TInt CTestZlib::Test_deflateSetDictionary01() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - positive test")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: sl@0: Byte *comp; sl@0: uLong compLen; sl@0: compLen = 30; sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_deflateSetDictionary01 (comp, compLen, flush, compression); sl@0: free (comp); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: // Test deflateSetDictionary - dictionary NULL sl@0: TInt CTestZlib::Test_deflateSetDictionary02() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary with dictionary NULL")); sl@0: int retVal = KErrGeneral; sl@0: sl@0: TInt compression, expRet; sl@0: sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: retVal = sec_deflateSetDictionary02 (compression); sl@0: sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: // Test deflateSetDictionary - set dictionary after deflate, deflateEnd sl@0: TInt CTestZlib::Test_deflateSetDictionary03() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - set dictionary after deflating")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: sl@0: Byte *comp; sl@0: uLong compLen; sl@0: compLen = 30; sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_deflateSetDictionary03 (comp, compLen, flush, compression); sl@0: free (comp); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: return retVal; sl@0: } sl@0: // Test deflateSetDictionary - set tiny dictionary < MIN_MATCH sl@0: TInt CTestZlib::Test_deflateSetDictionary04() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - positive test")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: sl@0: Byte *comp; sl@0: uLong compLen; sl@0: compLen = 30; sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_deflateSetDictionary04 (comp, compLen, flush, compression); sl@0: free (comp); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: // Test deflateSetDictionary - set large dictionary > MAX_MATCH sl@0: TInt CTestZlib::Test_deflateSetDictionary05() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - set large dictionary > MAX_MATCH")); sl@0: int retVal = KErrGeneral; sl@0: TInt flush, compression, expRet; sl@0: sl@0: Byte *comp; sl@0: uLong compLen; sl@0: compLen = 30; sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: sl@0: ReadIntParam (flush); sl@0: ReadIntParam (compression); sl@0: ReadIntParam (expRet); sl@0: sl@0: retVal = sec_deflateSetDictionary05 (comp, compLen, flush, compression); sl@0: free (comp); sl@0: if ( retVal != expRet) sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal); sl@0: retVal= KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Test passes!")); sl@0: retVal= KErrNone; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_gzio() sl@0: { sl@0: INFO_PRINTF1(_L("Zlib Test gzio")); sl@0: int retVal = 0; sl@0: sl@0: Byte *comp, *uncomp; sl@0: uLong compLen, uncompLen; sl@0: compLen = uncompLen = 30; sl@0: sl@0: comp = (Byte*)calloc((uInt)compLen, 1); sl@0: if ( comp == NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Could not allocate memory for comp.")); sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: uncomp = (Byte*)calloc((uInt)uncompLen, 1); sl@0: if ( uncomp == NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Could not allocate memory for uncomp.")); sl@0: free (comp); sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: retVal = sec_gzio ("C:\\bye.gz", uncomp, uncompLen); sl@0: free (comp); sl@0: free (uncomp); sl@0: return retVal; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_gzdirect() sl@0: { sl@0: INFO_PRINTF1(_L("gzdirect test: read gz file")); sl@0: TInt res = KErrNone; sl@0: char mode[3]; sl@0: gzFile file; sl@0: const char * fname= TESTFILE; sl@0: ReadStringParam (mode); sl@0: file = gzopen (fname, mode); sl@0: if ( file == NULL) sl@0: { sl@0: res = KErrGeneral; sl@0: return res; sl@0: } sl@0: res = gzdirect (file); //0=success sl@0: gzclose (file); sl@0: return res; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_gzdirectnull() sl@0: { sl@0: INFO_PRINTF1(_L("gzdirect test: read NULL stream")); sl@0: TInt res = KErrNone; sl@0: gzFile file=NULL; sl@0: res = gzdirect (file); //0=success sl@0: gzclose (file); sl@0: return res; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_gzclearerr_null() sl@0: { sl@0: TInt res = KErrNone; sl@0: int err; sl@0: gzFile file; sl@0: const char *fname= NULL; sl@0: file = gzopen (fname, "wb"); sl@0: if ( file == NULL) sl@0: { sl@0: res=KErrGeneral; sl@0: } sl@0: gzputc (file, 'h'); sl@0: if ( gzputs (file, "ello")!= 5) sl@0: { sl@0: gzprintf (file, "gzputs err"); sl@0: res=KErrGeneral; sl@0: } sl@0: err= gzclose (file); sl@0: if ( err != Z_OK) sl@0: { sl@0: res = KErrGeneral; sl@0: } sl@0: gzclearerr (file); sl@0: z_stream *s = (z_stream*)file; sl@0: if ( s == NULL) sl@0: res = KErrNone; sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Expected NULL stream. Returned nonNULL")); sl@0: res = KErrGeneral; sl@0: } sl@0: return res; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_gzclearerr() sl@0: { sl@0: sl@0: Byte *compr, *uncompr; sl@0: uLong comprLen = 20*sizeof(int); sl@0: sl@0: uLong uncomprLen = comprLen; sl@0: compr = (Byte*)calloc((uInt)comprLen, 1); sl@0: if ( compr == Z_NULL) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: uncompr = (Byte*)calloc((uInt)uncomprLen, 1); sl@0: if ( uncompr == Z_NULL) sl@0: { sl@0: free (compr); sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("gzclearerr test")); sl@0: int err; sl@0: int len = (int)strlen(hello)+1; sl@0: gzFile file; sl@0: sl@0: file = gzopen (MYFILE, "wb"); sl@0: if ( file == NULL) sl@0: { sl@0: err = KErrGeneral; sl@0: free (compr); sl@0: free (uncompr); sl@0: return err; sl@0: } sl@0: gzputc (file, 'h'); sl@0: if ( gzputs (file, "ello")!= 4) sl@0: { sl@0: err=KErrGeneral; sl@0: } sl@0: if ( gzprintf (file, ", %s!", "hello")!= 8) sl@0: { sl@0: err=KErrGeneral; sl@0: } sl@0: gzseek (file, 1L, SEEK_CUR); // add one zero byte sl@0: gzclose (file); sl@0: sl@0: file = gzopen (MYFILE, "rb"); sl@0: if ( file == NULL) sl@0: { sl@0: err = KErrGeneral; sl@0: free (compr); sl@0: free (uncompr); sl@0: return err; sl@0: } sl@0: strcpy ((char*)uncompr, "garbage"); sl@0: sl@0: if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len) sl@0: { sl@0: } sl@0: if ( strcmp ((char*)uncompr, hello)) sl@0: { sl@0: err=KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: err=KErrNone; sl@0: } sl@0: sl@0: gzseek (file, -8L, SEEK_CUR); sl@0: gzclearerr (file); sl@0: gzgets (file, (char*)uncompr, (int)uncomprLen); sl@0: sl@0: if ( strlen ((char*)uncompr)!= 7) sl@0: { sl@0: //1 " hello!" sl@0: ERR_PRINTF1(_L("gzegets gets wrong string")); sl@0: err=KErrGeneral; sl@0: } sl@0: gzclose (file); sl@0: sl@0: free (compr); sl@0: free (uncompr); sl@0: return err; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_gzerror_streamend() sl@0: { sl@0: #ifdef NO_GZCOMPRESS sl@0: ERR_PRINTF1(_L("NO_GZCOMPRESS -- gz* functions cannot compress")); sl@0: #else sl@0: const char *msgptr; sl@0: char fname[] = "C:\\bye.gz"; sl@0: sl@0: Byte *compr, *uncompr; sl@0: uLong comprLen, uncomprLen; sl@0: comprLen = uncomprLen = 30; sl@0: sl@0: compr = (Byte*)calloc((uInt)comprLen, 1); sl@0: if ( compr == NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Could not allocate memory for compr.")); sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: uncompr = (Byte*)calloc((uInt)uncomprLen, 1); sl@0: if ( uncompr == NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Could not allocate memory for uncompr.")); sl@0: free (compr); sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: int err; sl@0: const char hello[] = "hello, hello!"; sl@0: int len = (int)strlen(hello)+1; sl@0: gzFile file; sl@0: sl@0: file = gzopen (fname, "wb"); sl@0: if ( file == NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: free (compr); sl@0: free (uncompr); sl@0: return KErrGeneral; sl@0: } sl@0: gzputc (file, 'h'); sl@0: if ( gzputs (file, "ello")!= 4) sl@0: { sl@0: ERR_PRINTF1(_L("gzputs err")); sl@0: free (compr); sl@0: free (uncompr); sl@0: return KErrGeneral; sl@0: } sl@0: if ( gzprintf (file, ", %s!", "hello")!= 8) sl@0: { sl@0: ERR_PRINTF1(_L("gzprintf err=")); sl@0: free (compr); sl@0: free (uncompr); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: gzseek (file, 1L, SEEK_CUR); // add one zero byte sl@0: gzclose (file); sl@0: sl@0: file = gzopen (fname, "rb"); sl@0: if ( file == NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: free (compr); sl@0: free (uncompr); sl@0: return KErrGeneral; sl@0: } sl@0: strcpy ((char*)uncompr, "garbage"); sl@0: sl@0: if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len) sl@0: { sl@0: ERR_PRINTF1(_L("gzread err")); sl@0: free (compr); sl@0: free (uncompr); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: if ( strcmp ((char*)uncompr, hello)) sl@0: { sl@0: ERR_PRINTF1(_L("bad gzread")); sl@0: free (compr); sl@0: free (uncompr); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: INFO_PRINTF2(_L("Reached file position %ld"),gzseek(file, -8L, SEEK_CUR)); sl@0: sl@0: gzgets (file, (char*)uncompr, (int)uncomprLen); sl@0: msgptr = gzerror (file, &err); sl@0: if ( strcmp (msgptr, "C:\\bye.gz: stream end")!= 0) sl@0: { sl@0: // " hello!" sl@0: ERR_PRINTF1(_L("gzerror err on streamend")); sl@0: free (compr); sl@0: free (uncompr); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: gzclose (file); sl@0: free (compr); sl@0: free (uncompr); sl@0: sl@0: if ( err != Z_STREAM_END) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: return KErrNone; sl@0: #endif sl@0: } sl@0: sl@0: TInt CTestZlib::Test_gzungetcnegative() sl@0: { sl@0: gzFile file=NULL; sl@0: int ret = gzungetc (' ', file); //NULL stream sl@0: if ( ret != EOF) sl@0: { sl@0: ERR_PRINTF2(_L("gzungetc NULL stream test: Expected EOF but returned %d"),ret); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: const char hello[] = "hello, hello!"; sl@0: int len = (int)strlen(hello)+1; sl@0: sl@0: file = gzopen ("C:\\bye.gz", "wb"); sl@0: if ( file == NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: gzputc (file, 'h'); sl@0: if ( gzputs (file, "ello")!= 4) sl@0: { sl@0: ERR_PRINTF1(_L("gzputs err")); sl@0: gzclose (file); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: ret = gzungetc (' ', file); //non-read mode sl@0: if ( ret != EOF) sl@0: { sl@0: ERR_PRINTF2(_L("gzungetc non-read mode test: Expected EOF but returned %d"),ret); sl@0: gzclose (file); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: gzseek (file, 1L, SEEK_CUR); // add one zero byte sl@0: gzclose (file); sl@0: sl@0: file = gzopen ("C:\\bye.gz", "rb"); sl@0: if ( file == NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: if ( gzungetc (EOF, file)!= EOF) //ungetc EOF sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF1(_L("gzungetc error")); sl@0: return KErrGeneral; sl@0: } sl@0: gzclose (file); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestZlib::Test_gzseeknegative() sl@0: { sl@0: sl@0: int err=0; sl@0: sl@0: int len = (int)strlen(hello)+1; sl@0: gzFile file; sl@0: sl@0: file = gzopen (TESTFILE, "wb"); sl@0: if ( file == NULL) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: gzputc (file, 'h'); sl@0: sl@0: err= gzseek (file, 1L, SEEK_END); /* add one zero byte */ sl@0: if ( err != -1) sl@0: { sl@0: gzclose (file); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: err= gzclose (file); sl@0: file = gzopen (TESTFILE, "rb"); sl@0: if ( gzgetc (file)!= 'h') sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF1(_L("gzgetc error")); sl@0: return KErrGeneral; sl@0: } sl@0: if ( gzgetc (file)!= EOF) sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF1(_L("gzgetc error")); sl@0: return KErrGeneral; sl@0: } sl@0: err= gzseek (file, 1L, SEEK_CUR); sl@0: if ( gzgetc (file)!= -1L) sl@0: { sl@0: gzclose (file); sl@0: ERR_PRINTF1(_L("gzseek error")); sl@0: return KErrGeneral; sl@0: } sl@0: gzclose (file); sl@0: return KErrNone; sl@0: } sl@0: sl@0: /*TInt CTestZlib::TestGzopenRw() sl@0: { sl@0: TInt res = KErrNone ; sl@0: gzFile file; sl@0: char c; sl@0: const char *fname = "c:\\Bytes.gz"; sl@0: file = gzopen(fname, "wr"); sl@0: if (file == NULL) sl@0: { sl@0: res = KErrGeneral; sl@0: return res; sl@0: } sl@0: else sl@0: { sl@0: res=gzputc(file, 'r'); sl@0: if(res<0) sl@0: { sl@0: res = KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: res = KErrNone; sl@0: //gzclearerr(file); sl@0: gzseek(file,0, SEEK_SET); sl@0: c = gzgetc(file); sl@0: if(c == 'r') sl@0: { sl@0: res = KErrNone; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("gzgetc error in rw mode. Expected r")); sl@0: res=KErrGeneral; sl@0: } sl@0: } sl@0: } sl@0: gzclose(file); sl@0: return res; sl@0: } sl@0: */ sl@0: /** sl@0: * Function Name : Test_gzdirecttxt sl@0: * TestCase Description: 1. Checks whether a normal txt file gives a compressed stream or not sl@0: */ sl@0: TInt CTestZlib::Test_gzdirecttxt() sl@0: { sl@0: gzFile file; sl@0: int ret=KErrGeneral; sl@0: char fname[] = "C:\\gzdirecttest.txt"; sl@0: FILE *fp=NULL; sl@0: fp=fopen (fname, "w"); sl@0: fputc ('\n', fp); sl@0: fclose (fp); sl@0: file = gzopen (fname, "rb"); sl@0: ret = gzdirect (file); sl@0: if ( ret) sl@0: { sl@0: INFO_PRINTF1(_L("Reading a Non GzFile")); sl@0: ret=KErrNone; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Error in gzdirect. Expeceted 1, returned 0")); sl@0: ret=KErrGeneral; sl@0: } sl@0: gzclose (file); sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzungetcChain sl@0: * TestCase Description: 1. Checks whether gzungetc ungets the read chars using getc sl@0: */ sl@0: TInt CTestZlib::TestGzungetcChain() sl@0: { sl@0: gzFile file; sl@0: char tmp; sl@0: char fname[] = "C:\\Hello.gz"; sl@0: file = gzopen (fname, "wb"); sl@0: gzputc (file, 'h'); sl@0: if ( gzputs (file, "ello World")!= 10) sl@0: { sl@0: gzclose (file); sl@0: printf ("Error: gzputs\n"); sl@0: } sl@0: gzclose (file); sl@0: file = gzopen (fname, "rb"); sl@0: while (' ' != ( tmp = gzgetc(file) )) sl@0: { sl@0: gzungetc (tmp, file); sl@0: gzseek (file, 1L, SEEK_CUR); sl@0: } sl@0: gzclose (file); sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzseekBack sl@0: * TestCase Description: 1. Checks whether gzseek returns -1 sl@0: * for backward seeks in files opened in write mode. sl@0: */ sl@0: TInt CTestZlib::TestGzseekBack() sl@0: { sl@0: int err; sl@0: int len = (int)strlen(hello)+1; sl@0: gzFile file; sl@0: sl@0: const char * fname= TESTFILE; sl@0: sl@0: file = gzopen (fname, "wb"); sl@0: if ( file == NULL) sl@0: { sl@0: err = KErrGeneral; sl@0: return err; sl@0: } sl@0: gzputc (file, 'h'); sl@0: if ( gzputs (file, "ello")!= 4) sl@0: { sl@0: err=1; sl@0: } sl@0: if ( gzprintf (file, ", %s!", "hello")!= 8) sl@0: { sl@0: err=1; sl@0: } sl@0: err = (int) gzseek(file,0, SEEK_SET); /* to beg */ sl@0: gzclose (file); sl@0: if ( err == -1) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Expected -1, returned %d"),err); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzseekAppend sl@0: * TestCase Description: sl@0: * 1. Writes a text file, closes. sl@0: * 2. Open using gzopen in append mode sl@0: * 3. Writes another character. sl@0: * 4. Seek one down from current position sl@0: * 5. Checks whether gzseek returns 2 sl@0: */ sl@0: TInt CTestZlib::TestGzseekAppend() sl@0: { sl@0: const char hello[] = "hello, hello!"; sl@0: int len = (int)strlen(hello)+1; sl@0: int err; sl@0: gzFile file; sl@0: sl@0: FILE *fp = fopen ("c:\\file.txt", "wb"); sl@0: fputc ('h', fp); sl@0: fclose (fp); sl@0: file = gzopen ("c:\\file.txt", "a"); sl@0: if ( file == NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: gzputc (file, 'h'); sl@0: err = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */ sl@0: gzclose (file); sl@0: if ( err == 2) sl@0: return KErrNone; sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Expected 2, returned %d"),err); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzseekHugeOffset sl@0: * TestCase Description: sl@0: * 1. Writes a text file, closes. sl@0: * 2. Open using gzopen in append mode sl@0: * 3. Writes another character. sl@0: * 4. Seek 4097 up from current position sl@0: * 5. Checks whether gzseek returns 16386 or not. sl@0: */ sl@0: TInt CTestZlib::TestGzseekHugeOffset() sl@0: { sl@0: const char hello[] = "hello, hello!"; sl@0: int len = (int)strlen(hello)+1; sl@0: int err; sl@0: gzFile file; sl@0: sl@0: FILE *fp = fopen ("c:\\file.txt", "wb"); sl@0: fputc ('h', fp); sl@0: fclose (fp); sl@0: file = gzopen ("c:\\file.txt", "a"); sl@0: if ( file == NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: gzputc (file, 'h'); sl@0: err = (int) gzseek(file,16385L, SEEK_CUR); /* advance pos by 16385*/ sl@0: gzclose (file); sl@0: if ( err == 16386) sl@0: return KErrNone; sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Expected 2, returned %d"),err); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzseekNoSize sl@0: * TestCase Description: sl@0: * 1. Seeks a zero sized file sl@0: * 2. Checks whether it returns -1 or not sl@0: */ sl@0: TInt CTestZlib::TestGzseekNoSize() sl@0: { sl@0: TInt res = KErrNone; sl@0: gzFile file; sl@0: uInt size, len; sl@0: const char *s="\0"; sl@0: len=strlen (s); sl@0: const char * fname= TESTFILE; sl@0: file = gzopen (fname, "wb"); sl@0: if ( file == Z_NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: size = gzwrite (file, (char*)s, (unsigned)strlen(s)); sl@0: if ( len!=size) sl@0: { sl@0: ERR_PRINTF1(_L("gzwrite error")); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: res = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */ sl@0: gzclose (file); sl@0: if ( res == 1) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Expected -1, returned %d"), res); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzopenLongPath sl@0: * TestCase Description: sl@0: * 1. Seeks a file with long name sl@0: * 2. Checks whether gzopen returns NULL or not sl@0: */ sl@0: TInt CTestZlib::TestGzopenLongPath01() sl@0: { sl@0: gzFile file; sl@0: const char sl@0: * fname = "c:\\fffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff.txt"; sl@0: file = gzopen (fname, "wb"); sl@0: if ( file == Z_NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Returned NULL")); sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Expected NULL, returned %d"), file); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzseekLongPath sl@0: * TestCase Description: sl@0: * 1. Seeks a acceptable long file name sl@0: * 2. Checks whether it returns 1 or not sl@0: */ sl@0: TInt CTestZlib::TestGzseekLongPath01() sl@0: { sl@0: TInt res = KErrNone; sl@0: gzFile file; sl@0: uInt size, len; sl@0: const char *s="\0"; sl@0: len=strlen (s); sl@0: const char sl@0: * fname = "c:\\fffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff.txt"; sl@0: file = gzopen (fname, "wb"); sl@0: if ( file == Z_NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: size = gzwrite (file, (char*)s, (unsigned)strlen(s)); sl@0: if ( len!=size) sl@0: { sl@0: ERR_PRINTF1(_L("gzwrite error")); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: res = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */ sl@0: gzclose (file); sl@0: if ( res == 1) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Expected -1, returned %d"), res); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzopenLongPath sl@0: * TestCase Description: sl@0: * 1. Seeks a long pathed file sl@0: * 2. Checks whether it returns NULL or not sl@0: */ sl@0: TInt CTestZlib::TestGzopenLongPath02() sl@0: { sl@0: gzFile file; sl@0: int ret = KErrNone; sl@0: const char sl@0: * fname = "C:\\fffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff\ sl@0: fffffffffffffffffffffffffffffff"; sl@0: sl@0: file = gzopen (fname, "wb"); sl@0: if ( file == Z_NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error- File NULL")); sl@0: return KErrGeneral; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Expected file pointer, returned Success")); sl@0: } sl@0: gzclose (file); sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzseekMixedFile01 sl@0: * TestCase Description: sl@0: * 1. Open using gzopen in write mode sl@0: * 2. gzputs a string. sl@0: * 3. fopen it, writes a text, close. sl@0: * 4. Seek one down from current position sl@0: * 5. Checks whether gzseek returns 1 for offset 1L, sl@0: * 1000L for offset 1000L, -1 for -1L, -1 for -1000L sl@0: */ sl@0: TInt CTestZlib::TestGzseekMixedFile01() sl@0: { sl@0: const char hello[] = "hello, hello!"; sl@0: int len = (int)strlen(hello)+1; sl@0: int err; sl@0: gzFile file; sl@0: sl@0: TInt offset, expRes; sl@0: sl@0: ReadIntParam (offset); sl@0: ReadIntParam (expRes); sl@0: sl@0: file = gzopen ("c:\\file.txt", "wb"); sl@0: gzputs (file, hello); sl@0: gzclose (file); sl@0: FILE *fp = fopen ("c:\\file.txt", "w+"); sl@0: fputc ('h', fp); sl@0: fclose (fp); sl@0: file = gzopen ("c:\\file.txt", "rb"); sl@0: if ( file == NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: err = (int) gzseek(file,offset, SEEK_CUR); /* to next pos */ sl@0: gzclose (file); sl@0: if ( err == expRes) sl@0: return KErrNone; sl@0: else sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzopenNoMode sl@0: * TestCase Description: sl@0: * 1. gzopen a file with NULL mode sl@0: * 2. Checks whether gzopen returns NULL or not sl@0: */ sl@0: TInt CTestZlib::TestGzopenNoMode() sl@0: { sl@0: gzFile file; sl@0: const char * fname = "c:\\file.txt"; sl@0: file = gzopen (fname, NULL); sl@0: if ( file == Z_NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Returned NULL")); sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Expected NULL, returned %d"), file); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzopenNoPath sl@0: * TestCase Description: sl@0: * 1. gzopen a file with NULL path sl@0: * 2. Checks whether gzopen returns NULL or not sl@0: */ sl@0: TInt CTestZlib::TestGzopenNoPath() sl@0: { sl@0: gzFile file; sl@0: file = gzopen (NULL, "wb"); sl@0: if ( file == Z_NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Returned NULL")); sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Expected NULL, returned %d"), file); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzopenNoPath sl@0: * TestCase Description: sl@0: * 1. gzopen a file with path,mode empty string, sl@0: * 2. Checks whether gzopen returns NULL or not sl@0: */ sl@0: TInt CTestZlib::TestGzopenNoPathMode() sl@0: { sl@0: gzFile file; sl@0: file = gzopen ("", ""); sl@0: if ( file == Z_NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Returned NULL")); sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Expected NULL, returned %d"), file); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: /** sl@0: * Function Name : TestGzseekConcatedFile01 sl@0: * TestCase Description: sl@0: * 1. Open a manually concatinated gz file using gzopen in read mode sl@0: * 2. Seek one down from current position sl@0: * 3. Checks whether gzseek returns 1 for offset 1L, sl@0: * -1 for offset 1000L, -1 for -1L, -1 for -1000L sl@0: */ sl@0: TInt CTestZlib::TestGzseekConcatedFile01() sl@0: { sl@0: int err; sl@0: gzFile file; sl@0: sl@0: TInt offset, expRes; sl@0: ReadIntParam (offset); sl@0: ReadIntParam (expRes); sl@0: sl@0: file = gzopen (FILETESTGZCONCAT, "rb"); sl@0: if ( file == NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: err = (int) gzseek(file,offset, SEEK_CUR); // to next pos sl@0: gzclose (file); sl@0: if ( err == expRes) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzopenNoPath sl@0: * TestCase Description: sl@0: * 1. gzopen a file with valid path, mode: 9, f, h, R, 9, fb, hb, Rb, sl@0: * and wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww sl@0: * 2. Checks whether gzopen returns NULL all cases, except the last one. sl@0: */ sl@0: TInt CTestZlib::TestGzopenDiffMode() sl@0: { sl@0: TInt res = KErrNone; sl@0: gzFile file=Z_NULL; sl@0: const char * fname= TESTFILE; sl@0: char mode[100]; sl@0: TInt expRes; sl@0: ReadStringParam (mode); sl@0: ReadIntParam (expRes); sl@0: file = gzopen (fname, "wb"); sl@0: res = gzputc (file, 'h'); sl@0: res = gzclose (file); sl@0: file = gzopen (fname, mode); sl@0: if ( (file == Z_NULL && expRes == 0) || (file != Z_NULL && expRes == 1)) sl@0: { sl@0: res = KErrNone; sl@0: } sl@0: else sl@0: { sl@0: res = KErrGeneral; sl@0: ERR_PRINTF1(_L("Expected NULL, returned nonNULL")); sl@0: } sl@0: if ( file) sl@0: { sl@0: gzclose (file); sl@0: } sl@0: return res; sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzseekConcatedFile02 sl@0: * TestCase Description: sl@0: * 1. Open a programmatically concatinated gz file using gzopen sl@0: * in read mode sl@0: * 2. Seek one down from current position sl@0: * 3. Checks whether gzseek returns 1 for offset 1L, sl@0: * -1 for offset 1000L, -1 for -1L, -1 for -1000L sl@0: */ sl@0: TInt CTestZlib::TestGzseekConcatedFile02() sl@0: { sl@0: int err; sl@0: gzFile file; sl@0: sl@0: TInt offset, expRes; sl@0: sl@0: ReadIntParam (offset); sl@0: ReadIntParam (expRes); sl@0: char fname1[13]="c:\\first.gz"; sl@0: char fname2[14]="c:\\second.gz"; sl@0: sl@0: //create 2 gz files sl@0: file = gzopen (fname1, "w"); sl@0: if ( file == NULL) sl@0: { sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: gzputc (file, 'h'); sl@0: gzclose (file); sl@0: file = gzopen (fname2, "w"); sl@0: if ( file == NULL) sl@0: { sl@0: unlink (fname1); sl@0: ERR_PRINTF1(_L("gzopen error")); sl@0: return KErrGeneral; sl@0: } sl@0: gzputc (file, 'e'); sl@0: gzclose (file); sl@0: sl@0: //concatenate the two sl@0: FILE *fpFirst=NULL, *fpSecond=NULL; sl@0: fpFirst = fopen (fname1, "a"); sl@0: fpSecond = fopen (fname2, "r"); sl@0: char c; sl@0: for (; !feof(fpSecond);) sl@0: { sl@0: c=fgetc (fpSecond); sl@0: fputc (c, fpFirst); sl@0: } sl@0: fclose (fpFirst); sl@0: fclose (fpSecond); sl@0: sl@0: //Now seek sl@0: file = gzopen (fname1, "r"); sl@0: err = (int) gzseek(file,offset, SEEK_CUR); // to next pos sl@0: gzclose (file); sl@0: if ( err == expRes) sl@0: { sl@0: unlink (fname1); sl@0: unlink (fname2); sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: unlink (fname1); sl@0: unlink (fname2); sl@0: ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err); sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Function Name : TestGzprintf01 sl@0: * TestCase Description: sl@0: * 1. Prints an empty string sl@0: * 2. Checks whether returns 0 sl@0: */ sl@0: TInt CTestZlib::TestGzprintf01() sl@0: { sl@0: TInt res = KErrGeneral; sl@0: gzFile file; sl@0: const char * fname= TESTFILE; sl@0: file = gzopen (fname, "wb"); sl@0: if ( file == NULL) sl@0: { sl@0: res = KErrNoMemory; sl@0: return res; sl@0: } sl@0: res = gzprintf (file, ""); sl@0: if ( res != 0) sl@0: { sl@0: ERR_PRINTF1(_L("gzprintf err")); sl@0: } sl@0: else sl@0: { sl@0: res = KErrNone; sl@0: } sl@0: gzclose (file); sl@0: return res; sl@0: } sl@0: /** sl@0: * Function Name : TestGzprintf02 sl@0: * TestCase Description: sl@0: * 1. Prints an large string of length 4097, 4096 sl@0: * 2. Checks whether returns 0, 4095 sl@0: */ sl@0: TInt CTestZlib::TestGzprintf02() sl@0: { sl@0: TInt res = KErrGeneral; sl@0: gzFile file; sl@0: const char * fname= TESTFILE; sl@0: sl@0: char largeStr[4098]; sl@0: TInt strLength, expRes; sl@0: ReadIntParam (strLength); sl@0: ReadIntParam (expRes); sl@0: sl@0: //create alarge string sl@0: for (int i=0; i