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