summaryrefslogtreecommitdiff
path: root/ext/IO-Compress/t/050interop-gzip.t
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2009-05-05 12:09:48 +0200
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2009-05-05 12:18:11 +0200
commit9de654f174a7c7ca88031e2ac4a33add560d0c8c (patch)
tree7763181344f0e6240e96c5a444c8a5b57c986dc8 /ext/IO-Compress/t/050interop-gzip.t
parentf1bef09e9115ebdc1c8818193d6c4cbb8bc050e6 (diff)
parent216e7dec1076aa94d5b8331c187c135e4952955a (diff)
downloadperl-9de654f174a7c7ca88031e2ac4a33add560d0c8c.tar.gz
Merge branch 'blead' into smartmatch
Conflicts: t/op/switch.t
Diffstat (limited to 'ext/IO-Compress/t/050interop-gzip.t')
-rw-r--r--ext/IO-Compress/t/050interop-gzip.t143
1 files changed, 143 insertions, 0 deletions
diff --git a/ext/IO-Compress/t/050interop-gzip.t b/ext/IO-Compress/t/050interop-gzip.t
new file mode 100644
index 0000000000..22be0646c8
--- /dev/null
+++ b/ext/IO-Compress/t/050interop-gzip.t
@@ -0,0 +1,143 @@
+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 ;
+use CompTestUtils;
+
+my $GZIP ;
+
+
+sub ExternalGzipWorks
+{
+ my $lex = new LexFile my $outfile;
+ my $content = qq {
+Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut tempus odio id
+ dolor. Camelus perlus. Larrius in lumen numen. Dolor en quiquum filia
+ est. Quintus cenum parat.
+};
+
+ writeWithGzip($outfile, $content)
+ or return 0;
+
+ my $got ;
+ readWithGzip($outfile, $got)
+ or return 0;
+
+ if ($content ne $got)
+ {
+ diag "Uncompressed content is wrong";
+ return 0 ;
+ }
+
+ return 1 ;
+}
+
+sub readWithGzip
+{
+ my $file = shift ;
+
+ my $lex = new LexFile my $outfile;
+
+ my $comp = "$GZIP -dc" ;
+
+ if ( system("$comp $file >$outfile") == 0 )
+ {
+ $_[0] = readFile($outfile);
+ return 1
+ }
+
+ diag "'$comp' failed: $?";
+ return 0 ;
+}
+
+sub getGzipInfo
+{
+ my $file = shift ;
+}
+
+sub writeWithGzip
+{
+ my $file = shift ;
+ my $content = shift ;
+ my $options = shift || '';
+
+ my $lex = new LexFile my $infile;
+ writeFile($infile, $content);
+
+ unlink $file ;
+ my $comp = "$GZIP -c $options $infile >$file" ;
+
+ return 1
+ if system($comp) == 0 ;
+
+ diag "'$comp' failed: $?";
+ return 0 ;
+}
+
+BEGIN {
+
+ # Check external gzip is available
+ my $name = $^O =~ /mswin/i ? 'gzip.exe' : 'gzip';
+ my $split = $^O =~ /mswin/i ? ";" : ":";
+
+ for my $dir (reverse split $split, $ENV{PATH})
+ {
+ $GZIP = "$dir/$name"
+ if -x "$dir/$name" ;
+ }
+
+ plan(skip_all => "Cannot find $name")
+ if ! $GZIP ;
+
+ plan(skip_all => "$name doesn't work as expected")
+ if ! ExternalGzipWorks();
+
+
+ # use Test::NoWarnings, if available
+ my $extra = 0 ;
+ $extra = 1
+ if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
+
+ plan tests => 7 + $extra ;
+
+ use_ok('IO::Compress::Gzip', ':all') ;
+ use_ok('IO::Uncompress::Gunzip', ':all') ;
+
+}
+
+
+{
+ title "Test interop with $GZIP" ;
+
+ my $file;
+ my $file1;
+ my $lex = new LexFile $file, $file1;
+ my $content = qq {
+Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut tempus odio id
+ dolor. Camelus perlus. Larrius in lumen numen. Dolor en quiquum filia
+ est. Quintus cenum parat.
+};
+ my $got;
+
+ ok writeWithGzip($file, $content), "writeWithGzip ok";
+
+ gunzip $file => \$got ;
+ is $got, $content, "got content";
+
+
+ gzip \$content => $file1;
+ $got = '';
+ ok readWithGzip($file1, $got), "readWithGzip ok";
+ is $got, $content, "got content";
+}
+
+