1BEGIN {
2    if ($ENV{PERL_CORE}) {
3	chdir 't' if -d 't';
4	@INC = ("../lib", "lib/compress");
5    }
6}
7
8use lib qw(t t/compress);
9use strict;
10use warnings;
11
12use Test::More ;
13use CompTestUtils;
14
15BEGIN
16{
17    # use Test::NoWarnings, if available
18    my $extra = 0 ;
19    $extra = 1
20        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
21
22    plan tests => 21 + $extra ;
23
24    use_ok('Compress::Raw::Bzip2', 2) ;
25}
26
27
28
29my $hello = <<EOM ;
30hello world
31this is a test
32EOM
33
34my $len   = length $hello ;
35
36
37{
38
39    title  "bzdeflate/bzinflate - non-PV buffers";
40    # ==============================
41
42    my $hello = *hello;
43    $hello = *hello;
44    my ($err, $x, $X, $status);
45
46    ok( ($x, $err) = new Compress::Raw::Bzip2(0), "Create bzdeflate object" );
47    ok $x, "Compress::Raw::Bzip2 ok" ;
48    cmp_ok $err, '==', BZ_OK, "status is BZ_OK" ;
49
50    is $x->uncompressedBytes(), 0, "uncompressedBytes() == 0" ;
51    is $x->compressedBytes(), 0, "compressedBytes() == 0" ;
52
53    my $Answer = *Answer;
54    $Answer = *Answer;
55    $status = $x->bzdeflate($hello, $Answer) ;
56    cmp_ok $status, '==', BZ_RUN_OK, "bzdeflate returned BZ_RUN_OK" ;
57
58    $X = *X;
59    cmp_ok  $x->bzflush($X), '==', BZ_RUN_OK, "bzflush returned BZ_RUN_OK" ;
60    $Answer .= $X ;
61
62    is $x->uncompressedBytes(), length $hello, "uncompressedBytes ok" ;
63    is $x->compressedBytes(), length $Answer, "compressedBytes ok" ;
64
65    $X = *X;
66    cmp_ok $x->bzclose($X), '==', BZ_STREAM_END, "bzclose returned BZ_STREAM_END";
67    $Answer .= $X ;
68
69    my @Answer = split('', $Answer) ;
70
71    my $k;
72    ok(($k, $err) = new Compress::Raw::Bunzip2(0, 0));
73    ok $k, "Compress::Raw::Bunzip2 ok" ;
74    cmp_ok $err, '==', BZ_OK, "status is BZ_OK" ;
75
76    is $k->compressedBytes(), 0, "compressedBytes() == 0" ;
77    is $k->uncompressedBytes(), 0, "uncompressedBytes() == 0" ;
78    my $GOT = *GOT;
79    $GOT = *GOT;
80    my $Z;
81    $status = $k->bzinflate($Answer, $GOT) ;
82
83
84    cmp_ok $status, '==', BZ_STREAM_END, "Got BZ_STREAM_END" ;
85    is $GOT, $hello, "uncompressed data matches ok" ;
86    is $k->compressedBytes(), length $Answer, "compressedBytes ok" ;
87    is $k->uncompressedBytes(), length $hello , "uncompressedBytes ok";
88
89}
90
91
92