Blame t/070-gzcomp.t

Packit 989e37
# -*- mode: perl -*-
Packit 989e37
Packit 989e37
use Test::More tests => 5;
Packit 989e37
#use Test::More qw(no_plan);
Packit 989e37
Packit 989e37
## test the Compress::Zlib compatibility
Packit 989e37
## compress a simple text file - the lyrics to end of the world REM
Packit 989e37
## compare against bzip2 command with od -x and diff
Packit 989e37
Packit 989e37
BEGIN {
Packit 989e37
  use_ok('Compress::Bzip2', qw(:gzip));
Packit 989e37
};
Packit 989e37
Packit 989e37
do './t/lib.pl';
Packit 989e37
Packit 989e37
my $INFILE = catfile( qw(bzlib-src sample0.ref) );
Packit 989e37
( my $MODELFILE = $INFILE ) =~ s/\.ref$/.bz2/;
Packit 989e37
my $PREFIX = catfile( qw(t 020-tmp) );
Packit 989e37
Packit 989e37
my $in;
Packit 989e37
open( $in, $INFILE );
Packit 989e37
Packit 989e37
my $d = gzopen( "$PREFIX-sample.bz2", "w" );
Packit 989e37
Packit 989e37
ok( $d, "gzopen was successful" );
Packit 989e37
Packit 989e37
my $counter = 0;
Packit 989e37
my $bytes = 0;
Packit 989e37
while ( my $ln = read( $in, $buf, 512 ) ) {
Packit 989e37
  my $out = $d->gzwrite( $buf, $ln );
Packit 989e37
  if ( $out < 0 ) {
Packit 989e37
    print STDERR "error: $out $gzerrno\n";
Packit 989e37
    last;
Packit 989e37
  }
Packit 989e37
  $bytes += $ln;
Packit 989e37
  $counter++;
Packit 989e37
}
Packit 989e37
ok( $counter, "$counter blocks were read, $bytes bytes" );
Packit 989e37
Packit 989e37
my $res = $d->gzclose;
Packit 989e37
ok( !$res, "file was closed $res $gzerrno" );
Packit 989e37
Packit 989e37
close($in);
Packit 989e37
Packit 989e37
ok ( compare_binary_files( "$PREFIX-sample.bz2", $MODELFILE ), 'no differences with reference' );
Packit 989e37
#system( "bzip2 < $INFILE | od -x > $PREFIX-reference-bz2.odx" );
Packit 989e37
#system( "od -x < $PREFIX-sample.bz2 | diff - $PREFIX-reference-bz2.odx > $PREFIX-diff.txt" );
Packit 989e37
Packit 989e37
#ok( ! -s "$PREFIX-diff.txt", "no differences with bzip2" );