xref: /openbsd-src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/18lvalue.t (revision fdcd7346e28d9d56be488c988b2929cfac6342e0)
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;
11use bytes;
12
13use Test::More ;
14
15BEGIN
16{
17    plan(skip_all => "lvalue sub tests need Perl ??")
18        if $] < 5.006 ;
19
20    # use Test::NoWarnings, if available
21    my $extra = 0 ;
22    $extra = 1
23        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
24
25    plan tests => 10 + $extra ;
26
27    use_ok('Compress::Raw::Zlib', 2) ;
28}
29
30use CompTestUtils;
31
32
33
34my $hello = <<EOM ;
35hello world
36this is a test
37EOM
38
39my $len   = length $hello ;
40
41# Check zlib_version and ZLIB_VERSION are the same.
42test_zlib_header_matches_library();
43
44{
45    title 'deflate/inflate with lvalue sub';
46
47    my $hello = "I am a HAL 9000 computer" ;
48    my $data = $hello ;
49
50    my($X, $Z);
51    sub getData : lvalue { $data }
52    sub getX    : lvalue { $X }
53    sub getZ    : lvalue { $Z }
54
55    ok my $x = new Compress::Raw::Zlib::Deflate ( -AppendOutput => 1 );
56
57    cmp_ok $x->deflate(getData, getX), '==',  Z_OK ;
58
59    cmp_ok $x->flush(getX), '==', Z_OK ;
60
61    my $append = "Appended" ;
62    $X .= $append ;
63
64    ok my $k = new Compress::Raw::Zlib::Inflate ( -AppendOutput => 1 ) ;
65
66    cmp_ok $k->inflate(getX, getZ), '==', Z_STREAM_END ; ;
67
68    ok $hello eq $Z ;
69    is $X, $append;
70
71}
72