summaryrefslogtreecommitdiff
path: root/t/011-prototype.t
blob: 06e309f17e688f3f5c238efccc6894e448bdadde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- mode: perl -*-

use Test::More tests => 9;

## compress sample1 from the bzip2 1.0.2 distribution

BEGIN {
  use_ok('Compress::Bzip2');
};

do 't/lib.pl';

my $INFILE = catfile( qw(bzlib-src sample1.ref) );
( my $MODELFILE = $INFILE ) =~ s/\.ref$/.bz2/;
my $PREFIX = catfile( qw(t 011-tmp) );

my $in;
open( $in, $INFILE );

my $d;
ok( eval '$d = bzopen( "$PREFIX-sample.bz2", "w" ); 1;', "bzopen prototype ok" );
ok( $d, "bzopen $PREFIX-sample.bz2 successful" );
ok( eval '$d->bzsetparams( -blockSize100k => 1 ); 1;', "bzsetparams prototype ok" );

my $counter = 0;
my $bytes = 0;
my $buf;
my ( $evalres1, $evalres2 );
while ( my $ln = read( $in, $buf, 512 ) ) {
  my $out1 = -1;
  my $out2 = -1;
  $evalres1 = eval '$out1 = $d->bzwrite( $buf, $ln ); 1;';
  last if !$evalres1;

  $evalres2 = eval '$out2 = $d->bzwrite( $buf ); 1;';
  last if !$evalres2;

  if ( $out1 < 0 || $out2 < 0 || $out1 != $out2 ) {
    print STDERR "error: $out1 $out2 $Compress::Bzip2::bzerrno\n";
    last;
  }
  $bytes += $ln;
  $counter++;
}
ok( defined($evalres1), 'bzwrite prototype $$$ ok'.($@ ? " - $@" : '') );
ok( defined($evalres2), 'bzwrite prototype $$ ok'.($@ ? " - $@" : '') );
ok( $counter, "$counter blocks were read, $bytes bytes" );

my $res;
ok( eval '$res = $d->bzclose; 1;', 'bzclose prototype ok' );
ok( !$res, "file was closed $res $Compress::Bzip2::bzerrno" );

close($in);