4 @INC = ("../lib", "lib/compress");
8 use lib qw(t t/compress);
19 # use Test::NoWarnings, if available
22 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
33 plan tests => $count + $extra ;
35 use_ok('Compress::Zlib', 2) ;
36 use_ok('IO::Compress::Gzip::Constants') ;
38 use_ok('IO::Compress::Gzip', qw($GzipError)) ;
47 my $len = length $hello ;
49 # Check zlib_version and ZLIB_VERSION are the same.
50 is Compress::Zlib::zlib_version, ZLIB_VERSION,
51 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
53 # generate a long random string
56 { $contents .= chr int rand 256 }
61 # compress/uncompress tests
62 # =========================
64 eval { compress([1]); };
65 ok $@ =~ m#not a scalar reference#
68 eval { uncompress([1]); };
69 ok $@ =~ m#not a scalar reference#
72 $hello = "hello mum" ;
73 my $keep_hello = $hello ;
75 my $compr = compress($hello) ;
78 my $keep_compr = $compr ;
80 my $uncompr = uncompress ($compr) ;
82 ok $hello eq $uncompr ;
84 ok $hello eq $keep_hello ;
85 ok $compr eq $keep_compr ;
89 $keep_hello = $hello ;
91 $compr = compress($hello) ;
94 $keep_compr = $compr ;
96 $uncompr = uncompress ($compr) ;
98 ok $hello eq $uncompr ;
100 ok $hello eq $keep_hello ;
101 ok $compr eq $keep_compr ;
105 $compr = compress ($contents) ;
108 $uncompr = uncompress ($compr) ;
110 ok $contents eq $uncompr ;
114 $compr = compress(\$hello) ;
118 $uncompr = uncompress (\$compr) ;
119 ok $hello eq $uncompr ;
122 $compr = compress($hello, 1000) ;
126 $compr = compress($hello, Z_BEST_COMPRESSION) ;
128 $uncompr = uncompress (\$compr) ;
129 ok $hello eq $uncompr ;
132 $compr = compress(\$hello) ;
135 substr($compr,0, 1) = "\xFF";
136 ok !defined uncompress (\$compr) ;
138 # deflate/inflate - small buffer
139 # ==============================
141 $hello = "I am a HAL 9000 computer" ;
142 my @hello = split('', $hello) ;
143 my ($err, $X, $status);
145 ok (($x, $err) = deflateInit( {-Bufsize => 1} ) ) ;
152 ($X, $status) = $x->deflate($_) ;
153 last unless $status == Z_OK ;
160 ok ((($X, $status) = $x->flush())[1] == Z_OK ) ;
164 my @Answer = split('', $Answer) ;
167 ok (($k, $err) = inflateInit( {-Bufsize => 1}) ) ;
175 ($Z, $status) = $k->inflate($_) ;
177 last if $status == Z_STREAM_END or $status != Z_OK ;
181 ok $status == Z_STREAM_END ;
185 title 'deflate/inflate - small buffer with a number';
186 # ==============================
190 ok (($x, $err) = deflateInit( {-Bufsize => 1} ) ) ;
194 ok !defined $x->msg() ;
195 ok $x->total_in() == 0 ;
196 ok $x->total_out() == 0 ;
199 ($X, $status) = $x->deflate($hello) ;
206 ok ((($X, $status) = $x->flush())[1] == Z_OK ) ;
209 ok !defined $x->msg() ;
210 ok $x->total_in() == length $hello ;
211 ok $x->total_out() == length $Answer ;
214 @Answer = split('', $Answer) ;
216 ok (($k, $err) = inflateInit( {-Bufsize => 1}) ) ;
220 ok !defined $k->msg() ;
221 ok $k->total_in() == 0 ;
222 ok $k->total_out() == 0 ;
227 ($Z, $status) = $k->inflate($_) ;
229 last if $status == Z_STREAM_END or $status != Z_OK ;
233 ok $status == Z_STREAM_END ;
236 ok !defined $k->msg() ;
237 is $k->total_in(), length $Answer ;
238 ok $k->total_out() == length $hello ;
242 title 'deflate/inflate - larger buffer';
243 # ==============================
246 ok $x = deflateInit() ;
248 ok ((($X, $status) = $x->deflate($contents))[1] == Z_OK) ;
253 ok ((($X, $status) = $x->flush() )[1] == Z_OK ) ;
258 ok $k = inflateInit() ;
260 ($Z, $status) = $k->inflate($Y) ;
262 ok $status == Z_STREAM_END ;
265 title 'deflate/inflate - preset dictionary';
266 # ===================================
268 my $dictionary = "hello" ;
269 ok $x = deflateInit({-Level => Z_BEST_COMPRESSION,
270 -Dictionary => $dictionary}) ;
272 my $dictID = $x->dict_adler() ;
274 ($X, $status) = $x->deflate($hello) ;
276 ($Y, $status) = $x->flush() ;
281 ok $k = inflateInit(-Dictionary => $dictionary) ;
283 ($Z, $status) = $k->inflate($X);
284 ok $status == Z_STREAM_END ;
285 ok $k->dict_adler() == $dictID;
290 # ($Z, $status) = $k->inflate($X) ;
291 # last if $status == Z_STREAM_END or $status != Z_OK ;
292 #print "status=[$status] hello=[$hello] Z=[$Z]\n";
294 #ok $status == Z_STREAM_END ;
296 # or print "status=[$status] hello=[$hello] Z=[$Z]\n";
303 title 'inflate - check remaining buffer after Z_STREAM_END';
304 # ===================================================
307 ok $x = deflateInit(-Level => Z_BEST_COMPRESSION ) ;
309 ($X, $status) = $x->deflate($hello) ;
311 ($Y, $status) = $x->flush() ;
316 ok $k = inflateInit() ;
318 my $first = substr($X, 0, 2) ;
319 my $last = substr($X, 2) ;
320 ($Z, $status) = $k->inflate($first);
324 $last .= "appendage" ;
326 ($T, $status) = $k->inflate($last);
327 ok $status == Z_STREAM_END ;
328 ok $hello eq $Z . $T ;
329 ok $last eq "appendage" ;
333 title 'memGzip & memGunzip';
335 my $name = "test.gz" ;
342 my $len = length $buffer ;
346 # create an in-memory gzip file
347 my $dest = Compress::Zlib::memGzip($buffer) ;
351 ok open(FH, ">$name") ;
356 # uncompress with gzopen
357 ok my $fil = gzopen($name, "rb") ;
359 is $fil->gzread($uncomp, 0), 0 ;
360 ok (($x = $fil->gzread($uncomp)) == $len) ;
364 ok $uncomp eq $buffer ;
366 1 while unlink $name ;
368 # now check that memGunzip can deal with it.
369 my $ungzip = Compress::Zlib::memGunzip($dest) ;
371 ok $buffer eq $ungzip ;
373 # now do the same but use a reference
375 $dest = Compress::Zlib::memGzip(\$buffer) ;
379 ok open(FH, ">$name") ;
384 # uncompress with gzopen
385 ok $fil = gzopen($name, "rb") ;
387 ok (($x = $fil->gzread($uncomp)) == $len) ;
391 ok $uncomp eq $buffer ;
393 # now check that memGunzip can deal with it.
395 $ungzip = Compress::Zlib::memGunzip(\$dest) ;
397 ok $buffer eq $ungzip ;
399 # check memGunzip can cope with missing gzip trailer
400 my $minimal = substr($keep, 0, -1) ;
401 $ungzip = Compress::Zlib::memGunzip(\$minimal) ;
403 ok $buffer eq $ungzip ;
405 $minimal = substr($keep, 0, -2) ;
406 $ungzip = Compress::Zlib::memGunzip(\$minimal) ;
408 ok $buffer eq $ungzip ;
410 $minimal = substr($keep, 0, -3) ;
411 $ungzip = Compress::Zlib::memGunzip(\$minimal) ;
413 ok $buffer eq $ungzip ;
415 $minimal = substr($keep, 0, -4) ;
416 $ungzip = Compress::Zlib::memGunzip(\$minimal) ;
418 ok $buffer eq $ungzip ;
420 $minimal = substr($keep, 0, -5) ;
421 $ungzip = Compress::Zlib::memGunzip(\$minimal) ;
423 ok $buffer eq $ungzip ;
425 $minimal = substr($keep, 0, -6) ;
426 $ungzip = Compress::Zlib::memGunzip(\$minimal) ;
428 ok $buffer eq $ungzip ;
430 $minimal = substr($keep, 0, -7) ;
431 $ungzip = Compress::Zlib::memGunzip(\$minimal) ;
433 ok $buffer eq $ungzip ;
435 $minimal = substr($keep, 0, -8) ;
436 $ungzip = Compress::Zlib::memGunzip(\$minimal) ;
438 ok $buffer eq $ungzip ;
440 $minimal = substr($keep, 0, -9) ;
441 $ungzip = Compress::Zlib::memGunzip(\$minimal) ;
442 ok ! defined $ungzip ;
445 1 while unlink $name ;
447 # check corrupt header -- too short
449 my $result = Compress::Zlib::memGunzip($dest) ;
450 ok !defined $result ;
452 # check corrupt header -- full of junk
454 $result = Compress::Zlib::memGunzip($dest) ;
455 ok !defined $result ;
457 # corrupt header - 1st byte wrong
459 substr($bad, 0, 1) = "\xFF" ;
460 $ungzip = Compress::Zlib::memGunzip(\$bad) ;
461 ok ! defined $ungzip ;
463 # corrupt header - 2st byte wrong
465 substr($bad, 1, 1) = "\xFF" ;
466 $ungzip = Compress::Zlib::memGunzip(\$bad) ;
467 ok ! defined $ungzip ;
469 # corrupt header - method not deflated
471 substr($bad, 2, 1) = "\xFF" ;
472 $ungzip = Compress::Zlib::memGunzip(\$bad) ;
473 ok ! defined $ungzip ;
475 # corrupt header - reserverd bits used
477 substr($bad, 3, 1) = "\xFF" ;
478 $ungzip = Compress::Zlib::memGunzip(\$bad) ;
479 ok ! defined $ungzip ;
481 # corrupt trailer - length wrong
483 substr($bad, -8, 4) = "\xFF" x 4 ;
484 $ungzip = Compress::Zlib::memGunzip(\$bad) ;
485 ok ! defined $ungzip ;
487 # corrupt trailer - CRC wrong
489 substr($bad, -4, 4) = "\xFF" x 4 ;
490 $ungzip = Compress::Zlib::memGunzip(\$bad) ;
491 ok ! defined $ungzip ;
495 title "Check all bytes can be handled";
497 my $lex = new LexFile my $name ;
498 my $data = join '', map { chr } 0x00 .. 0xFF;
499 $data .= "\r\nabd\r\n";
502 ok $fil = gzopen($name, "wb") ;
503 is $fil->gzwrite($data), length $data ;
504 ok ! $fil->gzclose();
507 ok $fil = gzopen($name, "rb") ;
508 is $fil->gzread($input), length $data ;
509 ok ! $fil->gzclose();
512 title "Check all bytes can be handled - transparent mode";
513 writeFile($name, $data);
514 ok $fil = gzopen($name, "rb") ;
515 is $fil->gzread($input), length $data ;
516 ok ! $fil->gzclose();
521 title 'memGunzip with a gzopen created file';
523 my $name = "test.gz" ;
530 ok $fil = gzopen($name, "wb") ;
532 ok $fil->gzwrite($buffer) == length $buffer ;
536 my $compr = readFile($name);
538 my $unc = Compress::Zlib::memGunzip($compr) ;
541 1 while unlink $name ;
549 $hello = "Test test test test test";
550 @hello = split('', $hello) ;
552 ok (($x, $err) = deflateInit( -Bufsize => 1, -WindowBits => -MAX_WBITS() ) ) ;
559 ($X, $status) = $x->deflate($_) ;
560 last unless $status == Z_OK ;
567 ok ((($X, $status) = $x->flush())[1] == Z_OK ) ;
571 @Answer = split('', $Answer) ;
572 # Undocumented corner -- extra byte needed to get inflate to return
573 # Z_STREAM_END when done.
576 ok (($k, $err) = inflateInit(-Bufsize => 1, -WindowBits => -MAX_WBITS()) ) ;
583 ($Z, $status) = $k->inflate($_) ;
585 last if $status == Z_STREAM_END or $status != Z_OK ;
589 ok $status == Z_STREAM_END ;
597 # create a deflate stream with flush points
599 my $hello = "I am a HAL 9000 computer" x 2001 ;
600 my $goodbye = "Will I dream?" x 2010;
601 my ($err, $answer, $X, $status, $Answer);
603 ok (($x, $err) = deflateInit() ) ;
607 ($Answer, $status) = $x->deflate($hello) ;
610 # create a flush point
611 ok ((($X, $status) = $x->flush(Z_FULL_FLUSH))[1] == Z_OK ) ;
614 ($X, $status) = $x->deflate($goodbye) ;
618 ok ((($X, $status) = $x->flush())[1] == Z_OK ) ;
621 my ($first, @Answer) = split('', $Answer) ;
624 ok (($k, $err) = inflateInit()) ;
628 ($Z, $status) = $k->inflate($first) ;
631 # skip to the first flush point.
634 my $byte = shift @Answer;
635 $status = $k->inflateSync($byte) ;
636 last unless $status == Z_DATA_ERROR;
647 ($Z, $status) = $k->inflate($_) ;
648 $GOT .= $Z if defined $Z ;
649 # print "x $status\n";
650 last if $status == Z_STREAM_END or $status != Z_OK ;
654 # zlib 1.0.9 returns Z_STREAM_END here, all others return Z_DATA_ERROR
655 ok $status == Z_DATA_ERROR || $status == Z_STREAM_END ;
656 ok $GOT eq $goodbye ;
659 # Check inflateSync leaves good data in buffer
660 $Answer =~ /^(.)(.*)$/ ;
661 my ($initial, $rest) = ($1, $2);
664 ok (($k, $err) = inflateInit()) ;
668 ($Z, $status) = $k->inflate($initial) ;
671 $status = $k->inflateSync($rest) ;
674 ($GOT, $status) = $k->inflate($rest) ;
676 ok $status == Z_DATA_ERROR ;
677 ok $Z . $GOT eq $goodbye ;
683 my $hello = "I am a HAL 9000 computer" x 2001 ;
684 my $goodbye = "Will I dream?" x 2010;
685 my ($input, $err, $answer, $X, $status, $Answer);
687 ok (($x, $err) = deflateInit(-Level => Z_BEST_COMPRESSION,
688 -Strategy => Z_DEFAULT_STRATEGY) ) ;
692 ok $x->get_Level() == Z_BEST_COMPRESSION;
693 ok $x->get_Strategy() == Z_DEFAULT_STRATEGY;
695 ($Answer, $status) = $x->deflate($hello) ;
700 eval { $x->deflateParams() };
701 #like $@, mkErr("^Compress::Raw::Zlib::deflateParams needs Level and/or Strategy");
702 like $@, "/^Compress::Raw::Zlib::deflateParams needs Level and/or Strategy/";
704 eval { $x->deflateParams(-Joe => 3) };
705 like $@, "/^Compress::Raw::Zlib::deflateStream::deflateParams: unknown key value/";
706 #like $@, mkErr("^Compress::Raw::Zlib::deflateStream::deflateParams: unknown key value(s) Joe");
707 #ok $@ =~ /^Compress::Zlib::deflateStream::deflateParams: unknown key value\(s\) Joe at/
708 # or print "# $@\n" ;
710 ok $x->get_Level() == Z_BEST_COMPRESSION;
711 ok $x->get_Strategy() == Z_DEFAULT_STRATEGY;
713 # change both Level & Strategy
714 $status = $x->deflateParams(-Level => Z_BEST_SPEED, -Strategy => Z_HUFFMAN_ONLY) ;
717 ok $x->get_Level() == Z_BEST_SPEED;
718 ok $x->get_Strategy() == Z_HUFFMAN_ONLY;
720 ($X, $status) = $x->deflate($goodbye) ;
726 $status = $x->deflateParams(-Level => Z_NO_COMPRESSION) ;
729 ok $x->get_Level() == Z_NO_COMPRESSION;
730 ok $x->get_Strategy() == Z_HUFFMAN_ONLY;
732 ($X, $status) = $x->deflate($goodbye) ;
737 # change only Strategy
738 $status = $x->deflateParams(-Strategy => Z_FILTERED) ;
741 ok $x->get_Level() == Z_NO_COMPRESSION;
742 ok $x->get_Strategy() == Z_FILTERED;
744 ($X, $status) = $x->deflate($goodbye) ;
749 ok ((($X, $status) = $x->flush())[1] == Z_OK ) ;
752 my ($first, @Answer) = split('', $Answer) ;
755 ok (($k, $err) = inflateInit()) ;
759 ($Z, $status) = $k->inflate($Answer) ;
761 ok $status == Z_STREAM_END
762 or print "# status $status\n";
769 eval { deflateInit(-Level) };
770 like $@, '/^Compress::Zlib::deflateInit: Expected even number of parameters, got 1/';
772 eval { inflateInit(-Level) };
773 like $@, '/^Compress::Zlib::inflateInit: Expected even number of parameters, got 1/';
775 eval { deflateInit(-Joe => 1) };
776 ok $@ =~ /^Compress::Zlib::deflateInit: unknown key value\(s\) Joe at/;
778 eval { inflateInit(-Joe => 1) };
779 ok $@ =~ /^Compress::Zlib::inflateInit: unknown key value\(s\) Joe at/;
781 eval { deflateInit(-Bufsize => 0) };
782 ok $@ =~ /^.*?: Bufsize must be >= 1, you specified 0 at/;
784 eval { inflateInit(-Bufsize => 0) };
785 ok $@ =~ /^.*?: Bufsize must be >= 1, you specified 0 at/;
787 eval { deflateInit(-Bufsize => -1) };
788 #ok $@ =~ /^.*?: Bufsize must be >= 1, you specified -1 at/;
789 ok $@ =~ /^Compress::Zlib::deflateInit: Parameter 'Bufsize' must be an unsigned int, got '-1'/;
791 eval { inflateInit(-Bufsize => -1) };
792 ok $@ =~ /^Compress::Zlib::inflateInit: Parameter 'Bufsize' must be an unsigned int, got '-1'/;
794 eval { deflateInit(-Bufsize => "xxx") };
795 ok $@ =~ /^Compress::Zlib::deflateInit: Parameter 'Bufsize' must be an unsigned int, got 'xxx'/;
797 eval { inflateInit(-Bufsize => "xxx") };
798 ok $@ =~ /^Compress::Zlib::inflateInit: Parameter 'Bufsize' must be an unsigned int, got 'xxx'/;
800 eval { gzopen([], 0) ; } ;
801 ok $@ =~ /^gzopen: file parameter is not a filehandle or filename at/
804 # my $x = Symbol::gensym() ;
805 # eval { gzopen($x, 0) ; } ;
806 # ok $@ =~ /^gzopen: file parameter is not a filehandle or filename at/
807 # or print "# $@\n" ;
813 # test inflate with a substr
815 ok my $x = deflateInit() ;
817 ok ((my ($X, $status) = $x->deflate($contents))[1] == Z_OK) ;
823 ok ((($X, $status) = $x->flush() )[1] == Z_OK ) ;
826 my $append = "Appended" ;
829 ok $k = inflateInit() ;
831 #($Z, $status) = $k->inflate(substr($Y, 0, -1)) ;
832 ($Z, $status) = $k->inflate(substr($Y, 0)) ;
834 ok $status == Z_STREAM_END ;
842 # deflate/inflate in scalar context
844 ok my $x = deflateInit() ;
846 my $X = $x->deflate($contents);
855 my $append = "Appended" ;
858 ok $k = inflateInit() ;
860 #$Z = $k->inflate(substr($Y, 0, -1)) ;
861 $Z = $k->inflate(substr($Y, 0)) ;
871 my $data = 'ZgRNtjgSUW'; # CRC32 of this data should have the high bit set
872 my $expected_crc = 0xCF707A2B ; # 3480255019
873 my $crc = crc32($data) ;
874 is $crc, $expected_crc;
880 my $data = 'lpscOVsAJiUfNComkOfWYBcPhHZ[bT'; # adler of this data should have the high bit set
881 my $expected_crc = 0xAAD60AC7 ; # 2866154183
882 my $crc = adler32($data) ;
883 is $crc, $expected_crc;
887 # memGunzip - input > 4K
891 { $contents .= chr int rand 256 }
893 ok my $compressed = Compress::Zlib::memGzip(\$contents) ;
895 ok length $compressed > 4096 ;
896 ok my $out = Compress::Zlib::memGunzip(\$compressed) ;
898 ok $contents eq $out ;
899 is length $out, length $contents ;
906 # memGunzip Header Corruption Tests
913 ok my $x = new IO::Compress::Gzip \$good, Append => 1, -HeaderCRC => 1 ;
914 ok $x->write($string) ;
918 title "Header Corruption - Fingerprint wrong 1st byte" ;
920 substr($buffer, 0, 1) = 'x' ;
922 ok ! Compress::Zlib::memGunzip(\$buffer) ;
926 title "Header Corruption - Fingerprint wrong 2nd byte" ;
928 substr($buffer, 1, 1) = "\xFF" ;
930 ok ! Compress::Zlib::memGunzip(\$buffer) ;
934 title "Header Corruption - CM not 8";
936 substr($buffer, 2, 1) = 'x' ;
938 ok ! Compress::Zlib::memGunzip(\$buffer) ;
942 title "Header Corruption - Use of Reserved Flags";
944 substr($buffer, 3, 1) = "\xff";
946 ok ! Compress::Zlib::memGunzip(\$buffer) ;
951 for my $index ( GZIP_MIN_HEADER_SIZE + 1 .. GZIP_MIN_HEADER_SIZE + GZIP_FEXTRA_HEADER_SIZE + 1)
953 title "Header Corruption - Truncated in Extra";
959 ok my $x = new IO::Compress::Gzip \$truncated, Append => 1, -HeaderCRC => 1, Strict => 0,
960 -ExtraField => "hello" x 10 ;
961 ok $x->write($string) ;
964 substr($truncated, $index) = '' ;
966 ok ! Compress::Zlib::memGunzip(\$truncated) ;
972 for my $index ( GZIP_MIN_HEADER_SIZE .. GZIP_MIN_HEADER_SIZE + length($Name) -1)
974 title "Header Corruption - Truncated in Name";
980 ok my $x = new IO::Compress::Gzip \$truncated, Append => 1, -Name => $Name;
981 ok $x->write($string) ;
984 substr($truncated, $index) = '' ;
986 ok ! Compress::Zlib::memGunzip(\$truncated) ;
989 my $Comment = "comment" ;
990 for my $index ( GZIP_MIN_HEADER_SIZE .. GZIP_MIN_HEADER_SIZE + length($Comment) -1)
992 title "Header Corruption - Truncated in Comment";
998 ok my $x = new IO::Compress::Gzip \$truncated, -Comment => $Comment;
999 ok $x->write($string) ;
1002 substr($truncated, $index) = '' ;
1003 ok ! Compress::Zlib::memGunzip(\$truncated) ;
1006 for my $index ( GZIP_MIN_HEADER_SIZE .. GZIP_MIN_HEADER_SIZE + GZIP_FHCRC_SIZE -1)
1008 title "Header Corruption - Truncated in CRC";
1014 ok my $x = new IO::Compress::Gzip \$truncated, -HeaderCRC => 1;
1015 ok $x->write($string) ;
1018 substr($truncated, $index) = '' ;
1020 ok ! Compress::Zlib::memGunzip(\$truncated) ;
1024 title "memGunzip can cope with a gzip header with all possible fields";
1030 ok my $x = new IO::Compress::Gzip \$buffer,
1035 -ExtraField => "Extra",
1036 -Comment => 'Comment';
1037 ok $x->write($string) ;
1040 ok defined $buffer ;
1042 ok my $got = Compress::Zlib::memGunzip($buffer)
1043 or diag "gzerrno is $gzerrno" ;
1049 # Trailer Corruption tests
1056 ok my $x = new IO::Compress::Gzip \$good, Append => 1 ;
1057 ok $x->write($string) ;
1060 foreach my $trim (-8 .. -1)
1062 my $got = $trim + 8 ;
1063 title "Trailer Corruption - Trailer truncated to $got bytes" ;
1064 my $buffer = $good ;
1066 substr($buffer, $trim) = '';
1068 ok my $u = Compress::Zlib::memGunzip(\$buffer) ;
1074 title "Trailer Corruption - Length Wrong, CRC Correct" ;
1075 my $buffer = $good ;
1076 substr($buffer, -4, 4) = pack('V', 1234);
1078 ok ! Compress::Zlib::memGunzip(\$buffer) ;
1082 title "Trailer Corruption - Length Wrong, CRC Wrong" ;
1083 my $buffer = $good ;
1084 substr($buffer, -4, 4) = pack('V', 1234);
1085 substr($buffer, -8, 4) = pack('V', 1234);
1087 ok ! Compress::Zlib::memGunzip(\$buffer) ;
1098 my $fil = gzopen($name, "rb") ;
1099 ok $fil , "opened $name";
1100 cmp_ok $fil->gzread($input, 50000), ">", 0, "read more than zero bytes";
1101 ok ! $fil->gzclose(), "closed ok";
1112 $fil = gzopen($name, "rb") ;
1113 ok $fil, "opened ok";
1114 while ($fil->gzread($input, 50000) > 0)
1119 ok ! $fil->gzclose(), "closed ok";
1128 title "Append & MultiStream Tests";
1131 my $lex = new LexFile my $name ;
1132 my $data1 = "the is the first";
1133 my $data2 = "and this is the second";
1134 my $trailing = "some trailing data";
1139 $fil = gzopen($name, "wb") ;
1140 ok $fil, "opened first file";
1141 is $fil->gzwrite($data1), length $data1, "write data1" ;
1142 ok ! $fil->gzclose(), "Closed";
1144 is slurp($name), $data1, "got expected data from slurp";
1145 is trickle($name), $data1, "got expected data from trickle";
1148 $fil = gzopen($name, "ab") ;
1149 ok $fil, "opened second file";
1150 is $fil->gzwrite($data2), length $data2, "write data2" ;
1151 ok ! $fil->gzclose(), "Closed";
1153 is slurp($name), $data1 . $data2, "got expected data from slurp";
1154 is trickle($name), $data1 . $data2, "got expected data from trickle";
1156 title "Trailing Data";
1161 is slurp($name), $data1 . $data2 . $trailing, "got expected data from slurp" ;
1162 is trickle($name), $data1 . $data2 . $trailing, "got expected data from trickle" ;