Compress::Zlib
[p5sagit/p5-mst-13.2.git] / ext / Compress / IO / Zlib / t / 050interop-gzip.t
1 BEGIN {
2     if ($ENV{PERL_CORE}) {
3         chdir 't' if -d 't';
4         @INC = ("../lib", "lib/compress");
5     }
6 }
7
8 use lib qw(t t/compress);
9 use strict;
10 use warnings;
11 use bytes;
12
13 use Test::More ;
14
15 my $GZIP ;
16
17 BEGIN {
18
19     # Check external gzip is available
20     my $name = 'gzip';
21     for my $dir (split ":", $ENV{PATH})
22     {
23         $GZIP = "$dir/$name"
24             if -x "$dir/$name" ;
25     }
26
27     plan(skip_all => "Cannot find $name")
28         if ! $GZIP ;
29
30     
31     # use Test::NoWarnings, if available
32     my $extra = 0 ;
33     $extra = 1
34         if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
35
36     plan tests => 7 + $extra ;
37
38     use_ok('IO::Compress::Gzip',     ':all') ;
39     use_ok('IO::Uncompress::Gunzip', ':all') ;
40
41 }
42
43 use CompTestUtils;
44
45 sub readWithGzip
46 {
47     my $file = shift ;
48
49     my $comp = "$GZIP -dc" ;
50
51     open F, "$comp $file |";
52     local $/;
53     $_[0] = <F>;
54     close F;
55
56     return $? ;
57 }
58
59 sub getGzipInfo
60 {
61     my $file = shift ;
62 }
63
64 sub writeWithGzip
65 {
66     my $file = shift ;
67     my $content = shift ;
68     my $options = shift || '';
69
70     unlink $file ;
71     my $gzip = "$GZIP -c $options >$file" ;
72
73     open F, "| $gzip" ;
74     print F $content ;
75     close F ;
76
77     return $? ;
78 }
79
80
81 {
82     title "Test interop with $GZIP" ;
83
84     my $file;
85     my $file1;
86     my $lex = new LexFile $file, $file1;
87     my $content = "hello world\n" ;
88     my $got;
89
90     is writeWithGzip($file, $content), 0, "writeWithGzip ok";
91
92     gunzip $file => \$got ;
93     is $got, $content;
94
95
96     gzip \$content => $file1;
97     $got = '';
98     is readWithGzip($file1, $got), 0, "readWithGzip returns 0";
99     is $got, $content, "got content";
100 }
101
102