Blame t/19nonpv.t

Packit Service 4a2782
BEGIN {
Packit Service 4a2782
    if ($ENV{PERL_CORE}) {
Packit Service 4a2782
	chdir 't' if -d 't';
Packit Service 4a2782
	@INC = ("../lib", "lib/compress");
Packit Service 4a2782
    }
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
use lib qw(t t/compress);
Packit Service 4a2782
use strict;
Packit Service 4a2782
use warnings;
Packit Service 4a2782
Packit Service 4a2782
use Test::More ;
Packit Service 4a2782
use CompTestUtils;
Packit Service 4a2782
Packit Service 4a2782
BEGIN 
Packit Service 4a2782
{ 
Packit Service 4a2782
    # use Test::NoWarnings, if available
Packit Service 4a2782
    my $extra = 0 ;
Packit Service 4a2782
    $extra = 1
Packit Service 4a2782
        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
Packit Service 4a2782
Packit Service 4a2782
    plan tests => 38 + $extra ;
Packit Service 4a2782
Packit Service 4a2782
    use_ok('Compress::Raw::Zlib', 2) ;
Packit Service 4a2782
}
Packit Service 4a2782
 
Packit Service 4a2782
Packit Service 4a2782
Packit Service 4a2782
my $hello = <
Packit Service 4a2782
hello world
Packit Service 4a2782
this is a test
Packit Service 4a2782
EOM
Packit Service 4a2782
Packit Service 4a2782
my $len   = length $hello ;
Packit Service 4a2782
Packit Service 4a2782
# Check zlib_version and ZLIB_VERSION are the same.
Packit Service 4a2782
SKIP: {
Packit Service 4a2782
    skip "TEST_SKIP_VERSION_CHECK is set", 1 
Packit Service 4a2782
        if $ENV{TEST_SKIP_VERSION_CHECK};
Packit Service 4a2782
    is Compress::Raw::Zlib::zlib_version, ZLIB_VERSION,
Packit Service 4a2782
        "ZLIB_VERSION matches Compress::Raw::Zlib::zlib_version" ;
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
Packit Service 4a2782
{
Packit Service 4a2782
    title 'non-PV dictionary';
Packit Service 4a2782
    # ==============================
Packit Service 4a2782
Packit Service 4a2782
    my $dictionary = *hello ;
Packit Service 4a2782
Packit Service 4a2782
    ok my $x = new Compress::Raw::Zlib::Deflate({-Level => Z_BEST_COMPRESSION,
Packit Service 4a2782
			     -Dictionary => $dictionary}) ;
Packit Service 4a2782
 
Packit Service 4a2782
    my $dictID = $x->dict_adler() ;
Packit Service 4a2782
Packit Service 4a2782
    my ($X, $Y, $Z);
Packit Service 4a2782
    cmp_ok $x->deflate($hello, $X), '==', Z_OK;
Packit Service 4a2782
    cmp_ok $x->flush($Y), '==', Z_OK;
Packit Service 4a2782
    $X .= $Y ;
Packit Service 4a2782
 
Packit Service 4a2782
    ok my $k = new Compress::Raw::Zlib::Inflate(-Dictionary => $dictionary) ;
Packit Service 4a2782
 
Packit Service 4a2782
    cmp_ok $k->inflate($X, $Z), '==', Z_STREAM_END;
Packit Service 4a2782
    is $k->dict_adler(), $dictID;
Packit Service 4a2782
    is $hello, $Z ;
Packit Service 4a2782
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
{
Packit Service 4a2782
Packit Service 4a2782
    title  "deflate/inflate - non-PV buffers";
Packit Service 4a2782
    # ==============================
Packit Service 4a2782
Packit Service 4a2782
    my $hello = *hello ;
Packit Service 4a2782
    my ($err, $x, $X, $status); 
Packit Service 4a2782
 
Packit Service 4a2782
    ok( ($x, $err) = new Compress::Raw::Zlib::Deflate, "Create deflate object" );
Packit Service 4a2782
    ok $x, "Compress::Raw::Zlib::Deflate ok" ;
Packit Service 4a2782
    cmp_ok $err, '==', Z_OK, "status is Z_OK" ;
Packit Service 4a2782
 
Packit Service 4a2782
    ok ! defined $x->msg() ;
Packit Service 4a2782
    is $x->total_in(), 0, "total_in() == 0" ;
Packit Service 4a2782
    is $x->total_out(), 0, "total_out() == 0" ;
Packit Service 4a2782
Packit Service 4a2782
    $X = *X;
Packit Service 4a2782
    my $Answer = '';
Packit Service 4a2782
    $status = $x->deflate($hello, $X) ;
Packit Service 4a2782
    $Answer .= $X ;
Packit Service 4a2782
     
Packit Service 4a2782
    cmp_ok $status, '==', Z_OK, "deflate returned Z_OK" ;
Packit Service 4a2782
    
Packit Service 4a2782
    $X = *X;
Packit Service 4a2782
    cmp_ok  $x->flush($X), '==', Z_OK, "flush returned Z_OK" ;
Packit Service 4a2782
    $Answer .= $X ;
Packit Service 4a2782
     
Packit Service 4a2782
    ok ! defined $x->msg()  ;
Packit Service 4a2782
    is $x->total_in(), length $hello, "total_in ok" ;
Packit Service 4a2782
    is $x->total_out(), length $Answer, "total_out ok" ;
Packit Service 4a2782
     
Packit Service 4a2782
    my $k;
Packit Service 4a2782
    ok(($k, $err) = new Compress::Raw::Zlib::Inflate);
Packit Service 4a2782
    ok $k, "Compress::Raw::Zlib::Inflate ok" ;
Packit Service 4a2782
    cmp_ok $err, '==', Z_OK, "status is Z_OK" ;
Packit Service 4a2782
 
Packit Service 4a2782
    ok ! defined $k->msg(), "No error messages" ;
Packit Service 4a2782
    is $k->total_in(), 0, "total_in() == 0" ;
Packit Service 4a2782
    is $k->total_out(), 0, "total_out() == 0" ;
Packit Service 4a2782
    my $GOT = '';
Packit Service 4a2782
    my $Z;
Packit Service 4a2782
    $Z = *Z;
Packit Service 4a2782
    my $Alen = length $Answer;
Packit Service 4a2782
    $status = $k->inflate($Answer, $Z) ;
Packit Service 4a2782
    $GOT .= $Z ;
Packit Service 4a2782
     
Packit Service 4a2782
    cmp_ok $status, '==', Z_STREAM_END, "Got Z_STREAM_END" ;
Packit Service 4a2782
    is $GOT, $hello, "uncompressed data matches ok" ;
Packit Service 4a2782
    ok ! defined $k->msg(), "No error messages" ;
Packit Service 4a2782
    is $k->total_in(), $Alen, "total_in ok" ;
Packit Service 4a2782
    is $k->total_out(), length $hello , "total_out ok";
Packit Service 4a2782
Packit Service 4a2782
Packit Service 4a2782
    ok(($k, $err) = new Compress::Raw::Zlib::Inflate);
Packit Service 4a2782
    ok $k, "Compress::Raw::Zlib::Inflate ok" ;
Packit Service 4a2782
    cmp_ok $err, '==', Z_OK, "status is Z_OK" ;
Packit Service 4a2782
Packit Service 4a2782
    $Z = *Z;
Packit Service 4a2782
    $status = $k->inflate($hello, $Z);
Packit Service 4a2782
    is $Z, "", 'inflating *hello does not crash';
Packit Service 4a2782
Packit Service 4a2782
    $hello = *hello;
Packit Service 4a2782
    $status = $k->inflateSync($hello);
Packit Service 4a2782
    cmp_ok $status, "!=", Z_OK,
Packit Service 4a2782
       "inflateSync on *hello returns error (and does not crash)";
Packit Service 4a2782
}
Packit Service 4a2782