File: 07bufsize.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (111 lines) | stat: -rw-r--r-- 2,703 bytes parent folder | download | duplicates (4)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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 bytes;

use Test::More ;

BEGIN
{
    plan skip_all => "Lengthy Tests Disabled\n" .
                     "set COMPRESS_ZLIB_RUN_ALL or COMPRESS_ZLIB_RUN_MOST to run this test suite"
        unless defined $ENV{COMPRESS_ZLIB_RUN_ALL} or defined $ENV{COMPRESS_ZLIB_RUN_MOST};


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

    plan tests => 288 + $extra ;

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

use CompTestUtils;

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

my $len   = length $hello ;

# Check zlib_version and ZLIB_VERSION are the same.
test_zlib_header_matches_library();

for my $i (1 .. 13)
{

    print "#\n#Length $i\n#\n";

    my $hello = "I am a HAL 9000 computer" x 2001;
    my $tmp = $hello ;

    my @hello = ();
    push @hello, $1
	while $tmp =~ s/^(.{$i})//;
    push @hello, $tmp if length $tmp ;

    my ($err, $x, $X, $status);

    ok( ($x, $err) = new Compress::Raw::Zlib::Deflate (-AppendOutput => 1));
    ok $x ;
    cmp_ok $err, '==', Z_OK, "  status is Z_OK" ;

    ok ! defined $x->msg(), "  no msg" ;
    is $x->total_in(), 0, "  total_in == 0" ;
    is $x->total_out(), 0, "  total_out == 0" ;

    my $out ;
    foreach (@hello)
    {
        $status = $x->deflate($_, $out) ;
        last unless $status == Z_OK ;

    }
    cmp_ok $status, '==', Z_OK, "  status is Z_OK" ;

    cmp_ok $x->flush($out), '==', Z_OK, "  flush returned Z_OK" ;

    ok ! defined $x->msg(), "  no msg"  ;
    is $x->total_in(), length $hello, "  length total_in" ;
    is $x->total_out(), length $out, "  length total_out" ;

    my @Answer = ();
    $tmp = $out;
    push @Answer, $1 while $tmp =~ s/^(.{$i})//;
    push @Answer, $tmp if length $tmp ;

    my $k;
    ok(($k, $err) = new Compress::Raw::Zlib::Inflate( -AppendOutput => 1));
    ok $k ;
    cmp_ok $err, '==', Z_OK, "  status is Z_OK" ;

    ok ! defined $k->msg(), "  no msg" ;
    is $k->total_in(), 0, "  total_in == 0" ;
    is $k->total_out(), 0, "  total_out == 0" ;
    my $GOT = '';
    my $Z;
    $Z = 1 ;#x 2000 ;
    foreach (@Answer)
    {
        $status = $k->inflate($_, $GOT) ;
        last if $status == Z_STREAM_END or $status != Z_OK ;

    }

    cmp_ok $status, '==', Z_STREAM_END, "  status is Z_STREAM_END" ;
    is $GOT, $hello, "  got expected output" ;
    ok ! defined $k->msg(), "  no msg" ;
    is $k->total_in(), length $out, "  length total_in ok" ;
    is $k->total_out(), length $hello, "  length total_out ok" ;

}