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