Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Name : tzlibcases.cpp
20 #define CHECK_ERR(err, msg) { \
22 INFO_PRINTF2(_L("Error: %d"), err); \
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)
34 _LIT( Kparam, "Param%d" );
39 pNameBuf.Format (Kparam, ++iParamCnt);
40 TBool ret = GetStringFromConfig (ConfigSection (), pNameBuf, descriptor);
41 if ( descriptor == _L("\"\""))
47 // If the string is quoted, take only the insides
48 if ( (descriptor[0] == '\"') && (descriptor[descriptor.Length()-1] == '\"'))
50 for (i=0; i<descriptor.Length ()-2; i++)
52 aString[i]=descriptor[i+1];
55 // Otherwise,take the whole string
58 for (i=0; i<descriptor.Length (); i++)
60 aString[i]=descriptor[i];
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)
75 _LIT( Kparam, "Param%d" );
78 pNameBuf.Format (Kparam, ++iParamCnt);
79 TBool res = GetIntFromConfig (ConfigSection (), pNameBuf, aInt);
82 //---------------/*COMPRESS AND UNCOMPRESS*/----------------------------------
84 TInt CTestZlib::sec_compress(Byte * compr, uLong comprLen, Byte * uncompr,
89 const char hello[] = "hello, hello!";
90 uLong len = (uLong)strlen(hello)+1;
92 err = compress (compr, &comprLen, (const Bytef*)hello, len);
93 CHECK_ERR(err, "compress");
95 strcpy ((char*)uncompr, "garbage");
97 err = uncompress (uncompr, &uncomprLen, compr, comprLen);
98 CHECK_ERR(err, "uncompress");
100 if ( strcmp ((char*)uncompr, hello))
102 printf ("Bad uncompress");
107 printf ("uncompress(): %s", (char *)uncompr);
112 //------------------------------//deflateSetDictionary//-----------------------------------
114 TInt CTestZlib::sec_deflateSetDictionary01(Byte * compr, uLong comprLen,
115 TInt flush, TInt compression)
117 z_stream c_stream; // compression stream
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;
126 err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
130 INFO_PRINTF2(_L("deflateInit error: %d"), err);
133 err = deflateSetDictionary (&c_stream, dictionary, 3);
136 ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
137 deflateEnd (&c_stream);
140 c_stream.next_in = (Bytef*)hello;
141 c_stream.next_out = compr;
143 while (c_stream.total_in != len && c_stream.total_out < comprLen)
145 c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers
146 err = deflate (&c_stream, flush);
149 INFO_PRINTF2(_L("deflate return code: %d"), err);
150 deflateEnd (&c_stream);
154 // Finish the stream, still forcing small buffers:
157 c_stream.avail_out = 1;
158 err = deflate (&c_stream, Z_FINISH);
159 if ( err == Z_STREAM_END)
163 INFO_PRINTF2(_L("deflate error: %d"), err);
164 deflateEnd (&c_stream);
169 deflateEnd (&c_stream);
173 TInt CTestZlib::sec_deflateSetDictionary02(TInt compression)
175 z_stream c_stream; // compression stream
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;
184 err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
188 INFO_PRINTF2(_L("deflateInit error: %d"), err);
191 err = deflateSetDictionary (&c_stream, dictionary, 30);
194 ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
195 deflateEnd (&c_stream);
198 deflateEnd (&c_stream);
202 //------------------------------//deflateSetDictionary//-----------------------------------
204 TInt CTestZlib::sec_deflateSetDictionary03(Byte * compr, uLong comprLen,
205 TInt flush, TInt compression)
207 z_stream c_stream; // compression stream
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;
216 err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
220 INFO_PRINTF2(_L("deflateInit error: %d"), err);
223 c_stream.next_in = (Bytef*)hello;
224 c_stream.next_out = compr;
226 while (c_stream.total_in != len && c_stream.total_out < comprLen)
228 c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers
229 err = deflate (&c_stream, flush);
232 INFO_PRINTF2(_L("deflate return code: %d"), err);
233 deflateEnd (&c_stream);
237 // Finish the stream, still forcing small buffers:
240 c_stream.avail_out = 1;
241 err = deflate (&c_stream, Z_FINISH);
242 if ( err == Z_STREAM_END)
246 INFO_PRINTF2(_L("deflate error: %d"), err);
247 deflateEnd (&c_stream);
252 deflateEnd (&c_stream);
253 err = deflateSetDictionary (&c_stream, dictionary, 30);
256 ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
263 TInt CTestZlib::sec_deflateSetDictionary04(Byte * compr, uLong comprLen,
264 TInt flush, TInt compression)
266 z_stream c_stream; // compression stream
268 const char hello[] = "hello, hello!";
269 uLong len = (uLong)strlen(hello)+1;
270 const char dict[] = "z";
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;
277 err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
281 INFO_PRINTF2(_L("deflateInit error: %d"), err);
284 err = deflateSetDictionary (&c_stream, dictionary, (uLong)strlen(dict)+1);
287 ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
288 deflateEnd (&c_stream);
291 c_stream.next_in = (Bytef*)hello;
292 c_stream.next_out = compr;
294 while (c_stream.total_in != len && c_stream.total_out < comprLen)
296 c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers
297 err = deflate (&c_stream, flush);
300 INFO_PRINTF2(_L("deflate return code: %d"), err);
301 deflateEnd (&c_stream);
305 // Finish the stream, still forcing small buffers:
308 c_stream.avail_out = 1;
309 err = deflate (&c_stream, Z_FINISH);
310 if ( err == Z_STREAM_END)
314 INFO_PRINTF2(_L("deflate error: %d"), err);
315 deflateEnd (&c_stream);
320 deflateEnd (&c_stream);
324 TInt CTestZlib::sec_deflateSetDictionary05(Byte * compr, uLong comprLen,
325 TInt flush, TInt compression)
327 z_stream c_stream; // compression stream
329 const char hello[] = "hello, hello!";
330 uLong len = (uLong)strlen(hello)+1;
332 dict[] = "abcdefghijklmnopqrstuvwxyz \
333 abcdefghijklmnopqrstuvwxyz \
334 abcdefghijklmnopqrstuvwxyz \
335 abcdefghijklmnopqrstuvwxyz \
336 abcdefghijklmnopqrstuvwxyz \
337 abcdefghijklmnopqrstuvwxyz \
338 abcdefghijklmnopqrstuvwxyz \
339 abcdefghijklmnopqrstuvwxyz \
340 abcdefghijklmnopqrstuvwxyz \
341 abcdefghijklmnopqrstuvwxyz";
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;
348 err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
352 INFO_PRINTF2(_L("deflateInit error: %d"), err);
355 err = deflateSetDictionary (&c_stream, dictionary, (uLong)strlen(dict)+1);
358 ERR_PRINTF2(_L("deflateSetDictionary error: %d"), err);
359 deflateEnd (&c_stream);
362 c_stream.next_in = (Bytef*)hello;
363 c_stream.next_out = compr;
365 while (c_stream.total_in != len && c_stream.total_out < comprLen)
367 c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers
368 err = deflate (&c_stream, flush);
371 INFO_PRINTF2(_L("deflate return code: %d"), err);
372 deflateEnd (&c_stream);
376 // Finish the stream, still forcing small buffers:
379 c_stream.avail_out = 1;
380 err = deflate (&c_stream, Z_FINISH);
381 if ( err == Z_STREAM_END)
385 INFO_PRINTF2(_L("deflate error: %d"), err);
386 deflateEnd (&c_stream);
391 deflateEnd (&c_stream);
394 //------------------------------//DEFLATE//-----------------------------------
396 TInt CTestZlib::sec_deflate01( Byte * compr, uLong comprLen, TInt flush,
399 z_stream c_stream; // compression stream
401 const char hello[] = "hello, hello!";
402 uLong len = (uLong)strlen(hello)+1;
404 c_stream.zalloc = (alloc_func)0;
405 c_stream.zfree = (free_func)0;
406 c_stream.opaque = (voidpf)0;
408 err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
412 INFO_PRINTF2(_L("deflateInit error: %d"), err);
416 c_stream.next_in = (Bytef*)hello;
417 c_stream.next_out = compr;
419 while (c_stream.total_in != len && c_stream.total_out < comprLen)
421 c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers
422 err = deflate (&c_stream, flush);
425 INFO_PRINTF2(_L("deflate return code: %d"), err);
426 deflateEnd (&c_stream);
430 // Finish the stream, still forcing small buffers:
433 c_stream.avail_out = 1;
434 err = deflate (&c_stream, Z_FINISH);
435 if ( err == Z_STREAM_END)
439 INFO_PRINTF2(_L("deflate error: %d"), err);
440 deflateEnd (&c_stream);
445 deflateEnd (&c_stream);
449 TInt CTestZlib::sec_deflate02( Byte * compr, uLong comprLen, TInt flush,
452 z_stream c_stream; // compression stream
454 const char hello[] = "hello, hello!";
455 uLong len = (uLong)strlen(hello)+1;
457 c_stream.zalloc = (alloc_func)0;
458 c_stream.zfree = (free_func)0;
459 c_stream.opaque = (voidpf)0;
461 err = deflateInit (&c_stream, compression);// Z_DEFAULT_COMPRESSION);
465 INFO_PRINTF2(_L("deflateInit error: %d"), err);
469 c_stream.next_in = (Bytef*)hello;
470 c_stream.next_out = compr;
472 while (c_stream.total_in != len && c_stream.total_out < comprLen)
474 c_stream.avail_in = c_stream.avail_out = 1; //* force small buffers
475 err = deflate (&c_stream, Z_NO_FLUSH);
478 INFO_PRINTF2(_L("deflate return code: %d"), err);
479 deflateEnd (&c_stream);
483 // Finish the stream, still forcing small buffers:
486 c_stream.avail_out = 1;
487 err = deflate (&c_stream, Z_FINISH);
488 if ( err == Z_STREAM_END)
492 INFO_PRINTF2(_L("deflate error: %d"), err);
493 deflateEnd (&c_stream);
498 //deflate call after a finish
499 err = deflate (&c_stream, flush);
500 deflateEnd (&c_stream);
503 //-------------------------------/INFLATE/----------------------------------
505 TInt CTestZlib::sec_inflate( Byte * compr, uLong comprLen, Byte * uncompr,
506 uLong uncomprLen, TInt flush)
509 const char hello[] = "hello, hello!";
510 z_stream d_stream; // decompression stream
512 //strcpy((char*)uncompr, "garbage");
514 d_stream.zalloc = (alloc_func)0;
515 d_stream.zfree = (free_func)0;
516 d_stream.opaque = (voidpf)0;
518 d_stream.next_in = compr;
519 d_stream.avail_in = 0;
520 d_stream.next_out = uncompr;
522 err = inflateInit (&d_stream);
523 CHECK_ERR(err, "inflateInit");
525 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
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)
533 inflateEnd (&d_stream);
538 err = inflateEnd (&d_stream);
539 CHECK_ERR(err, "inflateEnd");
541 if ( strcmp ((char*)uncompr, hello))
543 ERR_PRINTF1(_L("Bad inflate"));
548 INFO_PRINTF1(_L("inflate success"));
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)
558 const char hello[] = "hello, hello!";
559 z_stream d_stream; // decompression stream
561 //strcpy((char*)uncompr, "garbage");
563 d_stream.zalloc = (alloc_func)0;
564 d_stream.zfree = (free_func)0;
565 d_stream.opaque = (voidpf)0;
567 d_stream.next_in = compr;
568 d_stream.avail_in = 0;
569 d_stream.next_out = uncompr;
571 err = inflateInit (&d_stream);
572 CHECK_ERR(err, "inflateInit");
574 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
576 d_stream.avail_in = d_stream.avail_out = 262144; // 256K
577 err = inflate (&d_stream, flush);
578 if ( err == Z_STREAM_END)
582 inflateEnd (&d_stream);
587 err = inflateEnd (&d_stream);
588 CHECK_ERR(err, "inflateEnd");
590 if ( strcmp ((char*)uncompr, hello))
592 ERR_PRINTF1(_L("Bad inflate"));
597 INFO_PRINTF1(_L("inflate success"));
602 //----------------------------//GZ OPERATION//--------------------------------
604 TInt CTestZlib::sec_gzio( const char *fname, Byte * uncompr, uLong uncomprLen)
607 ERR_PRINTF1(_L("NO_GZCOMPRESS -- gz* functions cannot compress"));
609 const char hello[] = "hello, hello!";
610 int len = (int)strlen(hello)+1;
614 file = gzopen (fname, "wb");
617 ERR_PRINTF1(_L("gzopen error"));
621 if ( gzputs (file, "ello")!= 4)
624 ERR_PRINTF1(_L("gzputs err"));
627 if ( gzprintf (file, ", %s!", "hello")!= 8)
630 ERR_PRINTF1(_L("gzprintf err:"));
634 gzseek (file, 1L, SEEK_CUR); // add one zero byte
637 file = gzopen (fname, "rb");
640 ERR_PRINTF1(_L("gzopen error"));
643 strcpy ((char*)uncompr, "garbage");
645 if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len)
648 ERR_PRINTF1(_L("gzread err"));
652 if ( strcmp ((char*)uncompr, hello))
655 ERR_PRINTF1(_L("bad gzread"));
659 pos = gzseek (file, -8L, SEEK_CUR);
660 if ( pos != 6 || gztell (file)!= pos)
663 ERR_PRINTF3(_L("gzseek error, pos=%ld, gztell=%ld"),(long)pos, (long)gztell(file));
667 if ( gzgetc (file)!= ' ')
670 ERR_PRINTF1(_L("gzgetc error"));
674 if ( gzungetc (' ', file)!= ' ')
677 ERR_PRINTF1(_L("gzungetc error"));
681 gzgets (file, (char*)uncompr, (int)uncomprLen);
683 if ( strlen ((char*)uncompr)!= 7)
687 ERR_PRINTF1(_L("gzgets err after gzseek"));
691 if ( strcmp ((char*)uncompr, hello + 6))
694 ERR_PRINTF1(_L("bad gzgets after gzseek"));
703 TInt CTestZlib::Test_zlibVersion()
705 INFO_PRINTF1(_L("Zlib Test zlibVersion"));
708 const char *version = zlibVersion ();
709 if ( strcmp (ZLIB_VERSION, version)== 0)
711 INFO_PRINTF1(_L("Returned version matches!"));
717 ERR_PRINTF1(_L("Return version mismatch!"));
723 TInt CTestZlib::Test_compress01()
725 INFO_PRINTF1(_L("Zlib Test compress"));
729 uLong compLen, uncompLen;
730 compLen = uncompLen = 30;
732 comp = (Byte*)calloc((uInt)compLen, 1);
735 INFO_PRINTF1(_L("Could not allocate memory for comp."));
738 uncomp = (Byte*)calloc((uInt)uncompLen, 1);
741 INFO_PRINTF1(_L("Could not allocate memory for uncomp."));
746 retVal = sec_compress (comp, compLen, uncomp, uncompLen);
752 // Test deflate - normal flow
753 TInt CTestZlib::Test_deflate01()
755 INFO_PRINTF1(_L("Zlib Test deflate"));
756 int retVal = KErrGeneral;
757 TInt flush, compression, expRet;
762 comp = (Byte*)calloc((uInt)compLen, 1);
764 ReadIntParam (flush);
765 ReadIntParam (compression);
766 ReadIntParam (expRet);
768 retVal = sec_deflate01 (comp, compLen, flush, compression);
770 if ( retVal != expRet)
772 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
777 INFO_PRINTF1(_L("Test passes!"));
784 TInt CTestZlib::Test_deflate02()
786 INFO_PRINTF1(_L("Zlib Test deflate"));
787 int retVal = KErrGeneral;
788 TInt flush, compression, expRet;
793 comp = (Byte*)calloc((uInt)compLen, 1);
795 ReadIntParam (flush);
796 ReadIntParam (compression);
797 ReadIntParam (expRet);
799 retVal = sec_deflate02 (comp, compLen, flush, compression);
801 if ( retVal != expRet)
803 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
808 INFO_PRINTF1(_L("Test passes!"));
814 // Test deflate small output buffer
815 TInt CTestZlib::Test_deflateEnd()
817 INFO_PRINTF1(_L("Zlib Test deflateEnd"));
823 comp = (Byte*)calloc((uInt)compLen, 1);
825 z_stream c_stream; // compression stream
827 const char hello[] = "hello, hello!";
828 uLong len = (uLong)strlen(hello)+1;
830 c_stream.zalloc = (alloc_func)0;
831 c_stream.zfree = (free_func)0;
832 c_stream.opaque = (voidpf)0;
834 err = deflateInit (&c_stream, Z_DEFAULT_COMPRESSION);
837 INFO_PRINTF2(_L("deflateInit failed: %d"), err);
842 c_stream.next_in = (Bytef*)hello;
843 c_stream.next_out = comp;
844 err = deflateEnd (&c_stream);
847 ERR_PRINTF2(_L("deflateEnd failed: %d"), err);
851 if ( c_stream.state != NULL)
853 ERR_PRINTF1(_L("Stream state expected NULL"));
861 TInt CTestZlib::Test_inflate01()
863 INFO_PRINTF1(_L("Zlib Test inflate. Positive test"));
864 int retVal = KErrGeneral;
865 TInt flush, compression, expRet;
867 uLong compLen, uncompLen;
868 compLen = uncompLen = 60;
870 comp = (Byte*)calloc((uInt)compLen, 1);
871 //comp = (Byte*)malloc(compLen);
872 uncomp = (Byte*)calloc((uInt)uncompLen, 1);
873 //uncomp = (Byte*)malloc(uncompLen);
875 ReadIntParam (flush);
876 ReadIntParam (compression);
877 ReadIntParam (expRet);
879 retVal = sec_deflate01 (comp, compLen, flush, compression);
880 if ( retVal != KErrNone)
882 ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
885 retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
886 if ( retVal != expRet)
888 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
893 INFO_PRINTF1(_L("Test passes!"));
901 //Negative test - invalid deflate data - return Z_DATA_ERROR
902 TInt CTestZlib::Test_inflate02()
904 INFO_PRINTF1(_L("Zlib Test inflate with invalide deflate data"));
905 int retVal = KErrGeneral;
906 TInt flush, compression, expRet;
908 uLong compLen, uncompLen;
909 compLen = uncompLen = 30;
911 comp = (Byte*)calloc((uInt)compLen, 1);
912 //comp = (Byte*)malloc(compLen);
913 uncomp = (Byte*)calloc((uInt)uncompLen, 1);
914 //uncomp = (Byte*)malloc(uncompLen);
916 ReadIntParam (flush);
917 ReadIntParam (compression);
918 ReadIntParam (expRet);
920 retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
921 if ( retVal != expRet)
923 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
928 INFO_PRINTF1(_L("Test passes!"));
936 // uncompressed data buffer inititalized to NULL
937 TInt CTestZlib::Test_inflate03()
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;
946 comp = (Byte*)calloc((uInt)compLen, 1);
947 //uncomp = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data
949 ReadIntParam (flush);
950 ReadIntParam (compression);
951 ReadIntParam (expRet);
953 retVal = sec_deflate01 (comp, compLen, flush, compression);
954 if ( retVal != KErrNone)
956 ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
959 retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
960 if ( retVal != expRet)
962 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
967 INFO_PRINTF1(_L("Test passes!"));
970 free (comp); //free(uncomp);
974 //Not enough buffer size for uncompresed data
975 TInt CTestZlib::Test_inflate04()
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;
985 comp = (Byte*)calloc((uInt)compLen, 1);
986 uncomp = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data
988 ReadIntParam (flush);
989 ReadIntParam (compression);
990 ReadIntParam (expRet);
992 retVal = sec_deflate01 (comp, compLen, flush, compression);
993 if ( retVal != KErrNone)
995 ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
998 retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
999 if ( retVal != expRet)
1001 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
1002 retVal= KErrGeneral;
1006 INFO_PRINTF1(_L("Test passes!"));
1014 //Use 256K sized chunks for inflating
1015 TInt CTestZlib::Test_inflate05()
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;
1025 comp = (Byte*)calloc((uInt)compLen, 1);
1026 uncomp = (Byte*)calloc((uInt)uncompLen, 1); //Do not alloc for uncompressed data
1028 ReadIntParam (flush);
1029 ReadIntParam (compression);
1030 ReadIntParam (expRet);
1032 retVal = sec_deflate01 (comp, compLen, flush, compression);
1033 if ( retVal != KErrNone)
1035 ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
1036 retVal= KErrGeneral;
1038 retVal = sec_inflate_large_buf (comp, compLen, uncomp, uncompLen, flush);
1039 if ( retVal != expRet)
1041 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
1042 retVal= KErrGeneral;
1046 INFO_PRINTF1(_L("Test passes!"));
1054 TInt CTestZlib::Test_inflate06()
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;
1063 comp = (Byte*)calloc((uInt)compLen, 1);
1064 //comp = (Byte*)malloc(compLen);
1065 uncomp = (Byte*)calloc((uInt)uncompLen, 1);
1066 //uncomp = (Byte*)malloc(uncompLen);
1068 ReadIntParam (flush);
1069 ReadIntParam (compression);
1070 ReadIntParam (expRet);
1072 retVal = sec_deflate01 (comp, compLen, flush, compression);
1073 if ( retVal != KErrNone)
1075 ERR_PRINTF3(_L("Expected %d, returned %d"),KErrNone,retVal);
1076 retVal= KErrGeneral;
1079 // Corrupt the compressed data
1083 retVal = sec_inflate (comp, compLen, uncomp, uncompLen, flush);
1084 if ( retVal != expRet)
1086 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
1087 retVal= KErrGeneral;
1091 INFO_PRINTF1(_L("Test passes!"));
1099 TInt CTestZlib::Test_inflateEnd()
1101 INFO_PRINTF1(_L("Zlib Test inflateEnd"));
1102 Byte *comp, *uncomp;
1103 uLong compLen, uncompLen;
1104 compLen = uncompLen = 30;
1106 comp = (Byte*)calloc((uInt)compLen, 1);
1107 uncomp = (Byte*)calloc((uInt)uncompLen, 1);
1110 z_stream d_stream; // decompression stream
1112 //strcpy((char*)uncompr, "garbage");
1114 d_stream.zalloc = (alloc_func)0;
1115 d_stream.zfree = (free_func)0;
1116 d_stream.opaque = (voidpf)0;
1118 d_stream.next_in = comp;
1119 d_stream.avail_in = 0;
1120 d_stream.next_out = uncomp;
1122 err = inflateInit (&d_stream);
1125 INFO_PRINTF2(_L("inflateInit error: %d"), err);
1132 err = inflateEnd (&d_stream);
1135 INFO_PRINTF2(_L("inflateEnd error: %d"), err);
1140 if ( d_stream.state != NULL)
1142 INFO_PRINTF2(_L("inflateEnd error: %d"), err);
1153 // Test deflateSetDictionary - normal flow
1154 TInt CTestZlib::Test_deflateSetDictionary01()
1156 INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - positive test"));
1157 int retVal = KErrGeneral;
1158 TInt flush, compression, expRet;
1163 comp = (Byte*)calloc((uInt)compLen, 1);
1165 ReadIntParam (flush);
1166 ReadIntParam (compression);
1167 ReadIntParam (expRet);
1169 retVal = sec_deflateSetDictionary01 (comp, compLen, flush, compression);
1171 if ( retVal != expRet)
1173 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
1174 retVal= KErrGeneral;
1178 INFO_PRINTF1(_L("Test passes!"));
1184 // Test deflateSetDictionary - dictionary NULL
1185 TInt CTestZlib::Test_deflateSetDictionary02()
1187 INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary with dictionary NULL"));
1188 int retVal = KErrGeneral;
1190 TInt compression, expRet;
1192 ReadIntParam (compression);
1193 ReadIntParam (expRet);
1194 retVal = sec_deflateSetDictionary02 (compression);
1196 if ( retVal != expRet)
1198 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
1199 retVal= KErrGeneral;
1203 INFO_PRINTF1(_L("Test passes!"));
1209 // Test deflateSetDictionary - set dictionary after deflate, deflateEnd
1210 TInt CTestZlib::Test_deflateSetDictionary03()
1212 INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - set dictionary after deflating"));
1213 int retVal = KErrGeneral;
1214 TInt flush, compression, expRet;
1219 comp = (Byte*)calloc((uInt)compLen, 1);
1221 ReadIntParam (flush);
1222 ReadIntParam (compression);
1223 ReadIntParam (expRet);
1225 retVal = sec_deflateSetDictionary03 (comp, compLen, flush, compression);
1227 if ( retVal != expRet)
1229 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
1230 retVal= KErrGeneral;
1234 INFO_PRINTF1(_L("Test passes!"));
1239 // Test deflateSetDictionary - set tiny dictionary < MIN_MATCH
1240 TInt CTestZlib::Test_deflateSetDictionary04()
1242 INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - positive test"));
1243 int retVal = KErrGeneral;
1244 TInt flush, compression, expRet;
1249 comp = (Byte*)calloc((uInt)compLen, 1);
1251 ReadIntParam (flush);
1252 ReadIntParam (compression);
1253 ReadIntParam (expRet);
1255 retVal = sec_deflateSetDictionary04 (comp, compLen, flush, compression);
1257 if ( retVal != expRet)
1259 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
1260 retVal= KErrGeneral;
1264 INFO_PRINTF1(_L("Test passes!"));
1270 // Test deflateSetDictionary - set large dictionary > MAX_MATCH
1271 TInt CTestZlib::Test_deflateSetDictionary05()
1273 INFO_PRINTF1(_L("Zlib Test test_deflateSetDictionary - set large dictionary > MAX_MATCH"));
1274 int retVal = KErrGeneral;
1275 TInt flush, compression, expRet;
1280 comp = (Byte*)calloc((uInt)compLen, 1);
1282 ReadIntParam (flush);
1283 ReadIntParam (compression);
1284 ReadIntParam (expRet);
1286 retVal = sec_deflateSetDictionary05 (comp, compLen, flush, compression);
1288 if ( retVal != expRet)
1290 ERR_PRINTF3(_L("Expected %d, returned %d"),expRet,retVal);
1291 retVal= KErrGeneral;
1295 INFO_PRINTF1(_L("Test passes!"));
1301 TInt CTestZlib::Test_gzio()
1303 INFO_PRINTF1(_L("Zlib Test gzio"));
1306 Byte *comp, *uncomp;
1307 uLong compLen, uncompLen;
1308 compLen = uncompLen = 30;
1310 comp = (Byte*)calloc((uInt)compLen, 1);
1313 INFO_PRINTF1(_L("Could not allocate memory for comp."));
1314 return KErrNoMemory;
1317 uncomp = (Byte*)calloc((uInt)uncompLen, 1);
1318 if ( uncomp == NULL)
1320 INFO_PRINTF1(_L("Could not allocate memory for uncomp."));
1322 return KErrNoMemory;
1325 retVal = sec_gzio ("C:\\bye.gz", uncomp, uncompLen);
1331 TInt CTestZlib::Test_gzdirect()
1333 INFO_PRINTF1(_L("gzdirect test: read gz file"));
1334 TInt res = KErrNone;
1337 const char * fname= TESTFILE;
1338 ReadStringParam (mode);
1339 file = gzopen (fname, mode);
1345 res = gzdirect (file); //0=success
1350 TInt CTestZlib::Test_gzdirectnull()
1352 INFO_PRINTF1(_L("gzdirect test: read NULL stream"));
1353 TInt res = KErrNone;
1355 res = gzdirect (file); //0=success
1360 TInt CTestZlib::Test_gzclearerr_null()
1362 TInt res = KErrNone;
1365 const char *fname= NULL;
1366 file = gzopen (fname, "wb");
1372 if ( gzputs (file, "ello")!= 5)
1374 gzprintf (file, "gzputs err");
1377 err= gzclose (file);
1383 z_stream *s = (z_stream*)file;
1388 ERR_PRINTF1(_L("Expected NULL stream. Returned nonNULL"));
1394 TInt CTestZlib::Test_gzclearerr()
1397 Byte *compr, *uncompr;
1398 uLong comprLen = 20*sizeof(int);
1400 uLong uncomprLen = comprLen;
1401 compr = (Byte*)calloc((uInt)comprLen, 1);
1402 if ( compr == Z_NULL)
1404 return KErrNoMemory;
1406 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1407 if ( uncompr == Z_NULL)
1410 return KErrNoMemory;
1413 INFO_PRINTF1(_L("gzclearerr test"));
1415 int len = (int)strlen(hello)+1;
1418 file = gzopen (MYFILE, "wb");
1427 if ( gzputs (file, "ello")!= 4)
1431 if ( gzprintf (file, ", %s!", "hello")!= 8)
1435 gzseek (file, 1L, SEEK_CUR); // add one zero byte
1438 file = gzopen (MYFILE, "rb");
1446 strcpy ((char*)uncompr, "garbage");
1448 if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len)
1451 if ( strcmp ((char*)uncompr, hello))
1460 gzseek (file, -8L, SEEK_CUR);
1462 gzgets (file, (char*)uncompr, (int)uncomprLen);
1464 if ( strlen ((char*)uncompr)!= 7)
1467 ERR_PRINTF1(_L("gzegets gets wrong string"));
1477 TInt CTestZlib::Test_gzerror_streamend()
1479 #ifdef NO_GZCOMPRESS
1480 ERR_PRINTF1(_L("NO_GZCOMPRESS -- gz* functions cannot compress"));
1483 char fname[] = "C:\\bye.gz";
1485 Byte *compr, *uncompr;
1486 uLong comprLen, uncomprLen;
1487 comprLen = uncomprLen = 30;
1489 compr = (Byte*)calloc((uInt)comprLen, 1);
1492 INFO_PRINTF1(_L("Could not allocate memory for compr."));
1493 return KErrNoMemory;
1496 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
1497 if ( uncompr == NULL)
1499 INFO_PRINTF1(_L("Could not allocate memory for uncompr."));
1501 return KErrNoMemory;
1505 const char hello[] = "hello, hello!";
1506 int len = (int)strlen(hello)+1;
1509 file = gzopen (fname, "wb");
1512 ERR_PRINTF1(_L("gzopen error"));
1518 if ( gzputs (file, "ello")!= 4)
1520 ERR_PRINTF1(_L("gzputs err"));
1525 if ( gzprintf (file, ", %s!", "hello")!= 8)
1527 ERR_PRINTF1(_L("gzprintf err="));
1533 gzseek (file, 1L, SEEK_CUR); // add one zero byte
1536 file = gzopen (fname, "rb");
1539 ERR_PRINTF1(_L("gzopen error"));
1544 strcpy ((char*)uncompr, "garbage");
1546 if ( gzread (file, uncompr, (unsigned)uncomprLen)!= len)
1548 ERR_PRINTF1(_L("gzread err"));
1554 if ( strcmp ((char*)uncompr, hello))
1556 ERR_PRINTF1(_L("bad gzread"));
1562 INFO_PRINTF2(_L("Reached file position %ld"),gzseek(file, -8L, SEEK_CUR));
1564 gzgets (file, (char*)uncompr, (int)uncomprLen);
1565 msgptr = gzerror (file, &err);
1566 if ( strcmp (msgptr, "C:\\bye.gz: stream end")!= 0)
1569 ERR_PRINTF1(_L("gzerror err on streamend"));
1579 if ( err != Z_STREAM_END)
1587 TInt CTestZlib::Test_gzungetcnegative()
1590 int ret = gzungetc (' ', file); //NULL stream
1593 ERR_PRINTF2(_L("gzungetc NULL stream test: Expected EOF but returned %d"),ret);
1597 const char hello[] = "hello, hello!";
1598 int len = (int)strlen(hello)+1;
1600 file = gzopen ("C:\\bye.gz", "wb");
1603 ERR_PRINTF1(_L("gzopen error"));
1607 if ( gzputs (file, "ello")!= 4)
1609 ERR_PRINTF1(_L("gzputs err"));
1614 ret = gzungetc (' ', file); //non-read mode
1617 ERR_PRINTF2(_L("gzungetc non-read mode test: Expected EOF but returned %d"),ret);
1622 gzseek (file, 1L, SEEK_CUR); // add one zero byte
1625 file = gzopen ("C:\\bye.gz", "rb");
1628 ERR_PRINTF1(_L("gzopen error"));
1632 if ( gzungetc (EOF, file)!= EOF) //ungetc EOF
1635 ERR_PRINTF1(_L("gzungetc error"));
1643 TInt CTestZlib::Test_gzseeknegative()
1648 int len = (int)strlen(hello)+1;
1651 file = gzopen (TESTFILE, "wb");
1654 return KErrNoMemory;
1658 err= gzseek (file, 1L, SEEK_END); /* add one zero byte */
1665 err= gzclose (file);
1666 file = gzopen (TESTFILE, "rb");
1667 if ( gzgetc (file)!= 'h')
1670 ERR_PRINTF1(_L("gzgetc error"));
1673 if ( gzgetc (file)!= EOF)
1676 ERR_PRINTF1(_L("gzgetc error"));
1679 err= gzseek (file, 1L, SEEK_CUR);
1680 if ( gzgetc (file)!= -1L)
1683 ERR_PRINTF1(_L("gzseek error"));
1690 /*TInt CTestZlib::TestGzopenRw()
1692 TInt res = KErrNone ;
1695 const char *fname = "c:\\Bytes.gz";
1696 file = gzopen(fname, "wr");
1704 res=gzputc(file, 'r');
1713 gzseek(file,0, SEEK_SET);
1721 ERR_PRINTF1(_L("gzgetc error in rw mode. Expected r"));
1731 * Function Name : Test_gzdirecttxt
1732 * TestCase Description: 1. Checks whether a normal txt file gives a compressed stream or not
1734 TInt CTestZlib::Test_gzdirecttxt()
1737 int ret=KErrGeneral;
1738 char fname[] = "C:\\gzdirecttest.txt";
1740 fp=fopen (fname, "w");
1743 file = gzopen (fname, "rb");
1744 ret = gzdirect (file);
1747 INFO_PRINTF1(_L("Reading a Non GzFile"));
1752 ERR_PRINTF1(_L("Error in gzdirect. Expeceted 1, returned 0"));
1760 * Function Name : TestGzungetcChain
1761 * TestCase Description: 1. Checks whether gzungetc ungets the read chars using getc
1763 TInt CTestZlib::TestGzungetcChain()
1767 char fname[] = "C:\\Hello.gz";
1768 file = gzopen (fname, "wb");
1770 if ( gzputs (file, "ello World")!= 10)
1773 printf ("Error: gzputs\n");
1776 file = gzopen (fname, "rb");
1777 while (' ' != ( tmp = gzgetc(file) ))
1779 gzungetc (tmp, file);
1780 gzseek (file, 1L, SEEK_CUR);
1787 * Function Name : TestGzseekBack
1788 * TestCase Description: 1. Checks whether gzseek returns -1
1789 * for backward seeks in files opened in write mode.
1791 TInt CTestZlib::TestGzseekBack()
1794 int len = (int)strlen(hello)+1;
1797 const char * fname= TESTFILE;
1799 file = gzopen (fname, "wb");
1806 if ( gzputs (file, "ello")!= 4)
1810 if ( gzprintf (file, ", %s!", "hello")!= 8)
1814 err = (int) gzseek(file,0, SEEK_SET); /* to beg */
1822 ERR_PRINTF2(_L("Expected -1, returned %d"),err);
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
1836 TInt CTestZlib::TestGzseekAppend()
1838 const char hello[] = "hello, hello!";
1839 int len = (int)strlen(hello)+1;
1843 FILE *fp = fopen ("c:\\file.txt", "wb");
1846 file = gzopen ("c:\\file.txt", "a");
1849 ERR_PRINTF1(_L("gzopen error"));
1853 err = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */
1859 ERR_PRINTF2(_L("Expected 2, returned %d"),err);
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.
1873 TInt CTestZlib::TestGzseekHugeOffset()
1875 const char hello[] = "hello, hello!";
1876 int len = (int)strlen(hello)+1;
1880 FILE *fp = fopen ("c:\\file.txt", "wb");
1883 file = gzopen ("c:\\file.txt", "a");
1886 ERR_PRINTF1(_L("gzopen error"));
1890 err = (int) gzseek(file,16385L, SEEK_CUR); /* advance pos by 16385*/
1896 ERR_PRINTF2(_L("Expected 2, returned %d"),err);
1902 * Function Name : TestGzseekNoSize
1903 * TestCase Description:
1904 * 1. Seeks a zero sized file
1905 * 2. Checks whether it returns -1 or not
1907 TInt CTestZlib::TestGzseekNoSize()
1909 TInt res = KErrNone;
1914 const char * fname= TESTFILE;
1915 file = gzopen (fname, "wb");
1916 if ( file == Z_NULL)
1918 ERR_PRINTF1(_L("gzopen error"));
1921 size = gzwrite (file, (char*)s, (unsigned)strlen(s));
1924 ERR_PRINTF1(_L("gzwrite error"));
1928 res = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */
1936 ERR_PRINTF2(_L("Expected -1, returned %d"), res);
1942 * Function Name : TestGzopenLongPath
1943 * TestCase Description:
1944 * 1. Seeks a file with long name
1945 * 2. Checks whether gzopen returns NULL or not
1947 TInt CTestZlib::TestGzopenLongPath01()
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)
1966 INFO_PRINTF1(_L("Returned NULL"));
1971 ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
1977 * Function Name : TestGzseekLongPath
1978 * TestCase Description:
1979 * 1. Seeks a acceptable long file name
1980 * 2. Checks whether it returns 1 or not
1982 TInt CTestZlib::TestGzseekLongPath01()
1984 TInt res = KErrNone;
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)
2000 ERR_PRINTF1(_L("gzopen error"));
2003 size = gzwrite (file, (char*)s, (unsigned)strlen(s));
2006 ERR_PRINTF1(_L("gzwrite error"));
2010 res = (int) gzseek(file,1L, SEEK_CUR); /* to next pos */
2018 ERR_PRINTF2(_L("Expected -1, returned %d"), res);
2024 * Function Name : TestGzopenLongPath
2025 * TestCase Description:
2026 * 1. Seeks a long pathed file
2027 * 2. Checks whether it returns NULL or not
2029 TInt CTestZlib::TestGzopenLongPath02()
2034 * fname = "C:\\fffff\
2035 fffffffffffffffffffffffffffffff\
2036 fffffffffffffffffffffffffffffff\
2037 fffffffffffffffffffffffffffffff\
2038 fffffffffffffffffffffffffffffff\
2039 fffffffffffffffffffffffffffffff\
2040 fffffffffffffffffffffffffffffff";
2042 file = gzopen (fname, "wb");
2043 if ( file == Z_NULL)
2045 ERR_PRINTF1(_L("gzopen error- File NULL"));
2050 INFO_PRINTF1(_L("Expected file pointer, returned Success"));
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
2066 TInt CTestZlib::TestGzseekMixedFile01()
2068 const char hello[] = "hello, hello!";
2069 int len = (int)strlen(hello)+1;
2073 TInt offset, expRes;
2075 ReadIntParam (offset);
2076 ReadIntParam (expRes);
2078 file = gzopen ("c:\\file.txt", "wb");
2079 gzputs (file, hello);
2081 FILE *fp = fopen ("c:\\file.txt", "w+");
2084 file = gzopen ("c:\\file.txt", "rb");
2087 ERR_PRINTF1(_L("gzopen error"));
2090 err = (int) gzseek(file,offset, SEEK_CUR); /* to next pos */
2096 ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err);
2102 * Function Name : TestGzopenNoMode
2103 * TestCase Description:
2104 * 1. gzopen a file with NULL mode
2105 * 2. Checks whether gzopen returns NULL or not
2107 TInt CTestZlib::TestGzopenNoMode()
2110 const char * fname = "c:\\file.txt";
2111 file = gzopen (fname, NULL);
2112 if ( file == Z_NULL)
2114 INFO_PRINTF1(_L("Returned NULL"));
2119 ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
2125 * Function Name : TestGzopenNoPath
2126 * TestCase Description:
2127 * 1. gzopen a file with NULL path
2128 * 2. Checks whether gzopen returns NULL or not
2130 TInt CTestZlib::TestGzopenNoPath()
2133 file = gzopen (NULL, "wb");
2134 if ( file == Z_NULL)
2136 INFO_PRINTF1(_L("Returned NULL"));
2141 ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
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
2152 TInt CTestZlib::TestGzopenNoPathMode()
2155 file = gzopen ("", "");
2156 if ( file == Z_NULL)
2158 INFO_PRINTF1(_L("Returned NULL"));
2163 ERR_PRINTF2(_L("Expected NULL, returned %d"), file);
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
2175 TInt CTestZlib::TestGzseekConcatedFile01()
2180 TInt offset, expRes;
2181 ReadIntParam (offset);
2182 ReadIntParam (expRes);
2184 file = gzopen (FILETESTGZCONCAT, "rb");
2187 ERR_PRINTF1(_L("gzopen error"));
2190 err = (int) gzseek(file,offset, SEEK_CUR); // to next pos
2198 ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err);
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.
2210 TInt CTestZlib::TestGzopenDiffMode()
2212 TInt res = KErrNone;
2214 const char * fname= TESTFILE;
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))
2230 ERR_PRINTF1(_L("Expected NULL, returned nonNULL"));
2240 * Function Name : TestGzseekConcatedFile02
2241 * TestCase Description:
2242 * 1. Open a programmatically concatinated gz file using gzopen
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
2248 TInt CTestZlib::TestGzseekConcatedFile02()
2253 TInt offset, expRes;
2255 ReadIntParam (offset);
2256 ReadIntParam (expRes);
2257 char fname1[13]="c:\\first.gz";
2258 char fname2[14]="c:\\second.gz";
2261 file = gzopen (fname1, "w");
2264 ERR_PRINTF1(_L("gzopen error"));
2269 file = gzopen (fname2, "w");
2273 ERR_PRINTF1(_L("gzopen error"));
2279 //concatenate the two
2280 FILE *fpFirst=NULL, *fpSecond=NULL;
2281 fpFirst = fopen (fname1, "a");
2282 fpSecond = fopen (fname2, "r");
2284 for (; !feof(fpSecond);)
2293 file = gzopen (fname1, "r");
2294 err = (int) gzseek(file,offset, SEEK_CUR); // to next pos
2306 ERR_PRINTF3(_L("Expected %d, returned %d"),expRes, err);
2312 * Function Name : TestGzprintf01
2313 * TestCase Description:
2314 * 1. Prints an empty string
2315 * 2. Checks whether returns 0
2317 TInt CTestZlib::TestGzprintf01()
2319 TInt res = KErrGeneral;
2321 const char * fname= TESTFILE;
2322 file = gzopen (fname, "wb");
2328 res = gzprintf (file, "");
2331 ERR_PRINTF1(_L("gzprintf err"));
2341 * Function Name : TestGzprintf02
2342 * TestCase Description:
2343 * 1. Prints an large string of length 4097, 4096
2344 * 2. Checks whether returns 0, 4095
2346 TInt CTestZlib::TestGzprintf02()
2348 TInt res = KErrGeneral;
2350 const char * fname= TESTFILE;
2352 char largeStr[4098];
2353 TInt strLength, expRes;
2354 ReadIntParam (strLength);
2355 ReadIntParam (expRes);
2357 //create alarge string
2358 for (int i=0; i<strLength;i++)
2362 largeStr[strLength]='\0';
2363 file = gzopen (fname, "wb");
2369 res = gzprintf (file, largeStr);
2372 ERR_PRINTF1(_L("gzprintf err"));
2384 * Function Name : TestGzflushNull
2385 * TestCase Description:
2386 * 1. Flushes a NULL stream
2387 * 2. Checks whether returns Z_STREAM_ERROR(-2)
2389 TInt CTestZlib::TestGzflushNull()
2391 TInt res = KErrNone;
2393 int l= gzflush (file, Z_FULL_FLUSH);
2394 if ( l != Z_STREAM_ERROR)
2402 * Function Name : TestGzflushRepeat
2403 * TestCase Description:
2404 * 1. Flushes a valid stream twice
2405 * 2. Checks whether returns 0
2407 TInt CTestZlib::TestGzflushRepeat()
2409 TInt res = KErrNone;
2412 const char * fname= TESTFILE;
2413 file = gzopen (fname, "wb");
2414 if ( file == Z_NULL)
2419 int l= gzflush (file, Z_FULL_FLUSH);
2424 l= gzflush (file, Z_SYNC_FLUSH);
2429 int err= gzclose (file);
2438 * Function Name : TestGzflushHugeBuf
2439 * TestCase Description:
2440 * 1. Flushes a valid stream
2441 * 2. Checks whether returns 0
2443 TInt CTestZlib::TestGzflushHugeBuf()
2445 TInt res = KErrNone;
2448 const char * fname= TESTFILE;
2449 file = gzopen (fname, "wb");
2450 if ( file == Z_NULL)
2455 for (int i=0; i<16385;i++)
2460 int l= gzflush (file, Z_FULL_FLUSH);
2465 int err= gzclose (file);
2474 * Function Name : TestGzrewindNull
2475 * TestCase Description:
2476 * 1. Rewinds a NULL stream
2477 * 2. Checks whether returns -1
2479 TInt CTestZlib::TestGzrewindNull()
2481 TInt res = KErrNone;
2482 res = gzrewind (NULL);
2495 * Function Name : TestGzrewindTransparent
2496 * TestCase Description:
2497 * 1. Rewinds a non-gz file stream
2498 * 2. Checks whether returns 1 or not
2500 TInt CTestZlib::TestGzrewindTransparent()
2504 int ret=KErrGeneral;
2505 char fname[] = "C:\\gzdirecttest.txt";
2507 fp=fopen (fname, "w");
2510 file = gzopen (fname, "rb");
2511 ret = gzdirect (file);
2514 INFO_PRINTF1(_L("Reading a Non GzFile"));
2515 ret = gzrewind (file);
2527 ERR_PRINTF1(_L("Error in gzdirect. Expeceted 1, returned 0"));
2535 * Function Name : TestGzgetsBufNull
2536 * TestCase Description:
2537 * 1. Gets from file into a NULL buffer
2538 * 2. Checks whether returns NULL or not
2540 TInt CTestZlib::TestGzgetsBufNull()
2543 const char hello[] = "hello, hello!";
2544 int len = (int)strlen(hello)+1;
2547 file = gzopen ("c:\\file.gz", "w");
2550 ERR_PRINTF1(_L("gzopen error"));
2553 gzputs (file, hello);
2555 file = gzopen ("c:\\file.gz", "r");
2556 buf = gzgets (file, buf, len);
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
2570 TInt CTestZlib::TestGzgetsSmallBuf()
2572 const char hello[] = "hello, hello!\n";
2576 ReadStringParam (expBuf);
2578 char *buf=(char *)malloc(strlen(hello));
2579 file = gzopen ("c:\\file.gz", "w");
2582 ERR_PRINTF1(_L("gzopen error"));
2586 gzputs (file, hello);
2588 file = gzopen ("c:\\file.gz", "r");
2589 buf = gzgets (file, (char *)buf, len);
2592 if ( !strcmp(buf,expBuf))