File: 19nonpv.t

package info (click to toggle)
libcompress-raw-bzip2-perl 2.213-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,048 kB
  • sloc: ansic: 3,852; perl: 2,255; makefile: 5
file content (94 lines) | stat: -rw-r--r-- 2,351 bytes parent folder | download | duplicates (3)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
BEGIN {
    if ($ENV{PERL_CORE}) {
	chdir 't' if -d 't';
	@INC = ("../lib", "lib/compress");
    }
}

use lib qw(t t/compress);
use strict;
use warnings;

use Test::More ;
use CompTestUtils;

BEGIN
{
    # use Test::NoWarnings, if available
    my $extra = 0 ;
    $extra = 1
        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };

    plan tests => 21 + $extra ;

    use_ok('Compress::Raw::Bzip2', 2) ;
}



my $hello = <<EOM ;
hello world
this is a test
EOM

my $len   = length $hello ;

SKIP:
{

    title  "bzdeflate/bzinflate - non-PV buffers";
    # ==============================

    # temp workaround for
    # https://github.com/pmqs/Compress-Raw-Bzip2/issues/13
    skip "skipping tests for Perl 5.6.*", 19
        if $] < 5.008 ;

    my $hello = *hello;
    $hello = *hello;
    my ($err, $x, $X, $status);

    ok( ($x, $err) = new Compress::Raw::Bzip2(0), "Create bzdeflate object" );
    ok $x, "Compress::Raw::Bzip2 ok" ;
    cmp_ok $err, '==', BZ_OK, "status is BZ_OK" ;

    is $x->uncompressedBytes(), 0, "uncompressedBytes() == 0" ;
    is $x->compressedBytes(), 0, "compressedBytes() == 0" ;

    my $Answer = *Answer;
    $Answer = *Answer;
    $status = $x->bzdeflate($hello, $Answer) ;
    cmp_ok $status, '==', BZ_RUN_OK, "bzdeflate returned BZ_RUN_OK" ;

    $X = *X;
    cmp_ok  $x->bzflush($X), '==', BZ_RUN_OK, "bzflush returned BZ_RUN_OK" ;
    $Answer .= $X ;

    is $x->uncompressedBytes(), length $hello, "uncompressedBytes ok" ;
    is $x->compressedBytes(), length $Answer, "compressedBytes ok" ;

    $X = *X;
    cmp_ok $x->bzclose($X), '==', BZ_STREAM_END, "bzclose returned BZ_STREAM_END";
    $Answer .= $X ;

    my @Answer = split('', $Answer) ;

    my $k;
    ok(($k, $err) = new Compress::Raw::Bunzip2(0, 0));
    ok $k, "Compress::Raw::Bunzip2 ok" ;
    cmp_ok $err, '==', BZ_OK, "status is BZ_OK" ;

    is $k->compressedBytes(), 0, "compressedBytes() == 0" ;
    is $k->uncompressedBytes(), 0, "uncompressedBytes() == 0" ;
    my $GOT = *GOT;
    $GOT = *GOT;
    my $Z;
    $status = $k->bzinflate($Answer, $GOT) ;


    cmp_ok $status, '==', BZ_STREAM_END, "Got BZ_STREAM_END" ;
    is $GOT, $hello, "uncompressed data matches ok" ;
    is $k->compressedBytes(), length $Answer, "compressedBytes ok" ;
    is $k->uncompressedBytes(), length $hello , "uncompressedBytes ok";

}