Don't require to have at least DB_File or *DBM_File
[p5sagit/p5-mst-13.2.git] / t / lib / compress / oneshot.pl
index 048006c..0646958 100644 (file)
@@ -4,7 +4,7 @@ use warnings;
 use bytes;
 
 use Test::More ;
-use ZlibTestUtils;
+use CompTestUtils;
 
 BEGIN {
     plan(skip_all => "oneshot needs Perl 5.005 or better - you have Perl $]" )
@@ -16,9 +16,9 @@ BEGIN {
     $extra = 1
         if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
 
-    plan tests => 944 + $extra ;
+    plan tests => 970 + $extra ;
 
-    use_ok('IO::Uncompress::AnyInflate', qw(anyinflate $AnyInflateError)) ;
+    use_ok('IO::Uncompress::AnyUncompress', qw(anyuncompress $AnyUncompressError)) ;
 
 }
 
@@ -32,9 +32,10 @@ sub run
     my $TopFuncName     = getTopFuncName($CompressClass);
 
 
+    my @MultiValues     = getMultiValues($CompressClass);
 
     foreach my $bit ($CompressClass, $UncompressClass,
-                     'IO::Uncompress::AnyInflate',
+                     'IO::Uncompress::AnyUncompress',
                     )
     {
         my $Error = getErrorRef($bit);
@@ -50,7 +51,7 @@ sub run
         like $@, mkErr("^$TopType: unknown key value\\(s\\) Fred"), '  Illegal Parameters';
 
         eval { $a = $Func->() ;} ;
-        like $@, mkErr("^$TopType: expected at least 1 parameters"), '  No Parameters';
+        like $@, "/^$TopType: expected at least 1 parameters/", '  No Parameters';
 
         eval { $a = $Func->(\$x, \1) ;} ;
         like $$Error, "/^$TopType: output buffer is read-only/", '  Output is read-only' ;
@@ -74,18 +75,44 @@ sub run
                 '  Input and Output filename are the same';
         }
 
+        {
+            my $dir = "tmpdir";
+            my $lex = new LexDir $dir ;
+            mkdir $dir, 0777 ;
+
+            $a = $Func->($dir, \$x) ;
+            is $a, undef, "  $TopType returned undef";
+            like $$Error, "/input file '$dir' is a directory/",
+                '  Input filename is a directory';
+
+            $a = $Func->(\$x, $dir) ;
+            is $a, undef, "  $TopType returned undef";
+            like $$Error, "/output file '$dir' is a directory/",
+                '  Output filename is a directory';
+        }
+
         eval { $a = $Func->(\$in, \$in) ;} ;
         like $@, mkErr("^$TopType: input and output buffer are identical"),
             '  Input and Output buffer are the same';
             
-        my $lex = new LexFile my $out_file ;
-        open OUT, ">$out_file" ;
-        eval { $a = $Func->(\*OUT, \*OUT) ;} ;
-        like $@, mkErr("^$TopType: input and output handle are identical"),
-            '  Input and Output handle are the same';
-            
-        close OUT;
-        is -s $out_file, 0, "  File zero length" ;
+        SKIP:
+        {
+            # Threaded 5.6.x seems to have a problem comparing filehandles.
+            use Config;
+
+            skip 'Cannot compare filehandles with threaded $]', 2
+                if $] >= 5.006  && $] < 5.007 && $Config{useithreads};
+
+            my $lex = new LexFile my $out_file ;
+            open OUT, ">$out_file" ;
+            eval { $a = $Func->(\*OUT, \*OUT) ;} ;
+            like $@, mkErr("^$TopType: input and output handle are identical"),
+                '  Input and Output handle are the same';
+                
+            close OUT;
+            is -s $out_file, 0, "  File zero length" ;
+        }
+
         {
             my %x = () ;
             my $object = bless \%x, "someClass" ;
@@ -136,7 +163,39 @@ sub run
     }
 
     foreach my $bit ($UncompressClass,
-                     'IO::Uncompress::AnyInflate',
+                     'IO::Uncompress::AnyUncompress',
+                    )
+    {
+        my $Error = getErrorRef($bit);
+        my $Func = getTopFuncRef($bit);
+        my $TopType = getTopFuncName($bit);
+
+        {
+            my $in ;
+            my $out ;
+            my @x ;
+
+            SKIP:
+            {
+                use Config;
+
+                skip 'readonly + threads', 1
+                    if $Config{useithreads};
+
+                
+                eval { $a = $Func->(\$in, \$out, TrailingData => \"abc") ;} ;
+                like $@, mkErr("^$TopType: Parameter 'TrailingData' not writable"),
+                    '  TrailingData output not writable';
+            }
+
+            eval { $a = $Func->(\$in, \$out, TrailingData => \@x) ;} ;
+            like $@, mkErr("^$TopType: Parameter 'TrailingData' not a scalar reference"),
+                '  TrailingData output not scaral reference';
+        }
+    }
+
+    foreach my $bit ($UncompressClass,
+                     'IO::Uncompress::AnyUncompress',
                     )
     {
         my $Error = getErrorRef($bit);
@@ -199,8 +258,8 @@ sub run
 
         #is $result, $data, "  data ok";
 
-        ok ! anyinflate(\$out => \$result, Transparent => 0), "  anyinflate ok";
-        ok $AnyInflateError, "  Got error '$AnyInflateError'" ;
+        ok ! anyuncompress(\$out => \$result, Transparent => 0), "anyuncompress ok";
+        ok $AnyUncompressError, "  Got error '$AnyUncompressError'" ;
     }
 
 
@@ -213,6 +272,10 @@ sub run
         my $TopTypeInverse = getInverse($bit);
         my $FuncInverse = getTopFuncRef($TopTypeInverse);
 
+        my @opts = ();
+        @opts = (RawInflate => 1)
+            if $CompressClass eq 'IO::Compress::RawInflate';
+
         for my $append ( 1, 0 )
         {
             my $already = '';
@@ -485,7 +548,7 @@ sub run
 
         }
 
-        foreach my $ms (1, 0)
+        foreach my $ms (@MultiValues)
         {
             {
                 title "$TopType - From Array Ref to Buffer, MultiStream $ms" ;
@@ -546,6 +609,61 @@ sub run
         }
     }
 
+    foreach my $bit ($UncompressClass,
+                    #'IO::Uncompress::AnyUncompress',
+                    )
+    {
+        my $Error = getErrorRef($bit);
+        my $Func = getTopFuncRef($bit);
+        my $TopType = getTopFuncName($bit);
+        my $CompressClass = getInverse($bit);
+        my $C_Func = getTopFuncRef($CompressClass);
+
+
+        
+        my $data = "mary had a little lamb" ;
+        my $keep = $data ;
+        my $extra = "after the main event";
+
+        foreach my $fb ( qw( filehandle buffer ) )
+        {
+            title "Trailingdata with $TopType, from $fb";
+
+            my $lex = new LexFile my $name ;
+            my $input ;
+
+            my $compressed ;
+            ok &$C_Func(\$data, \$compressed), '  Compressed ok' ;
+            $compressed .= $extra;
+
+            if ($fb eq 'buffer')
+            {
+                $input = \$compressed;
+            }
+            else
+            {
+                writeFile($name, $compressed);
+
+                $input = new IO::File "<$name" ;
+            }
+
+            my $trailing;
+            my $out;
+            ok $Func->($input, \$out, TrailingData => $trailing), "  Uncompressed OK" ;
+            is $out, $keep, "  Got uncompressed data";
+
+            my $rest = '';
+            if ($fb eq 'filehandle')
+            {
+                read($input, $rest, 10000) ;
+            }
+
+            is $trailing . $rest, $extra, "  Got trailing data";
+            
+        }
+    }
+
+
 #    foreach my $bit ($CompressClass)
 #    {
 #        my $Error = getErrorRef($bit);
@@ -789,7 +907,7 @@ sub run
                 is @copy, 0, "  got all files";
             }
 
-            foreach my $ms (0, 1)
+            foreach my $ms (@MultiValues)
             {
                 {
                     title "$TopType - From FileGlob to Buffer files [@$files], MS $ms" ;
@@ -852,7 +970,7 @@ sub run
     }
 
     foreach my $bit ($UncompressClass,
-                     'IO::Uncompress::AnyInflate',
+                     'IO::Uncompress::AnyUncompress',
                     )
     {
         my $Error = getErrorRef($bit);
@@ -863,12 +981,16 @@ sub run
         my $buffer2 = "ABCDE" ;
         my $keep_orig = $buffer;
 
-        my $comp = compressBuffer($TopType, $buffer) ;
-        my $comp2 = compressBuffer($TopType, $buffer2) ;
+        my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
+        my $comp2 = compressBuffer(getTopFuncName($UncompressClass), $buffer2) ;
         my $keep_comp = $comp;
 
         my $incumbent = "incumbent data" ;
 
+        my @opts = (Strict => 1);
+        push @opts,  (RawInflate => 1)
+            if $bit eq 'IO::Uncompress::AnyUncompress';
+
         for my $append (0, 1)
         {
             my $expected = $buffer ;
@@ -879,7 +1001,7 @@ sub run
 
                 my $output ;
                 $output = $incumbent if $append ;
-                ok &$Func(\$comp, \$output, Append => $append), '  Uncompressed ok' ;
+                ok &$Func(\$comp, \$output, Append => $append, @opts), '  Uncompressed ok' ;
 
                 is $keep_comp, $comp, "  Input buffer not changed" ;
                 is $output, $expected, "  Uncompressed matches original";
@@ -890,7 +1012,7 @@ sub run
 
                 my @output = ('first');
                 #$output = $incumbent if $append ;
-                ok &$Func(\$comp, \@output, Append => $append), '  Uncompressed ok' ;
+                ok &$Func(\$comp, \@output, Append => $append, @opts), '  Uncompressed ok' ;
 
                 is $keep_comp, $comp, "  Input buffer not changed" ;
                 is $output[0], 'first', "  Uncompressed matches original";
@@ -908,7 +1030,7 @@ sub run
                 else
                   { ok ! -e $out_file, "  Output file does not exist" }
 
-                ok &$Func(\$comp, $out_file, Append => $append), '  Uncompressed ok' ;
+                ok &$Func(\$comp, $out_file, Append => $append, @opts), '  Uncompressed ok' ;
 
                 ok -e $out_file, "  Created output file";
                 my $content = readFile($out_file) ;
@@ -932,7 +1054,7 @@ sub run
                 }
                 isa_ok $of, 'IO::File', '  $of' ;
 
-                ok &$Func(\$comp, $of, Append => $append, AutoClose => 1), '  Uncompressed ok' ;
+                ok &$Func(\$comp, $of, Append => $append, AutoClose => 1, @opts), '  Uncompressed ok' ;
 
                 ok -e $out_file, "  Created output file";
                 my $content = readFile($out_file) ;
@@ -952,7 +1074,7 @@ sub run
 
                 writeFile($in_file, $comp);
 
-                ok &$Func($in_file, $out_file, Append => $append), '  Uncompressed ok' ;
+                ok &$Func($in_file, $out_file, Append => $append, @opts), '  Uncompressed ok' ;
 
                 ok -e $out_file, "  Created output file";
                 my $content = readFile($out_file) ;
@@ -978,7 +1100,7 @@ sub run
 
                 writeFile($in_file, $comp);
 
-                ok &$Func($in_file, $out, Append => $append, AutoClose => 1), '  Uncompressed ok' ;
+                ok &$Func($in_file, $out, Append => $append, AutoClose => 1, @opts), '  Uncompressed ok' ;
 
                 ok -e $out_file, "  Created output file";
                 my $content = readFile($out_file) ;
@@ -996,7 +1118,7 @@ sub run
                 my $output ;
                 $output = $incumbent if $append ;
 
-                ok &$Func($in_file, \$output, Append => $append), '  Uncompressed ok' ;
+                ok &$Func($in_file, \$output, Append => $append, @opts), '  Uncompressed ok' ;
 
                 is $keep_comp, $comp, "  Input buffer not changed" ;
                 is $output, $expected, "  Uncompressed matches original";
@@ -1014,7 +1136,7 @@ sub run
                 writeFile($in_file, $comp);
                 my $in = new IO::File "<$in_file" ;
 
-                ok &$Func($in, $out_file, Append => $append), '  Uncompressed ok' ;
+                ok &$Func($in, $out_file, Append => $append, @opts), '  Uncompressed ok' ;
 
                 ok -e $out_file, "  Created output file";
                 my $content = readFile($out_file) ;
@@ -1041,7 +1163,7 @@ sub run
                 writeFile($in_file, $comp);
                 my $in = new IO::File "<$in_file" ;
 
-                ok &$Func($in, $out, Append => $append, AutoClose => 1), '  Uncompressed ok' ;
+                ok &$Func($in, $out, Append => $append, AutoClose => 1, @opts), '  Uncompressed ok' ;
 
                 ok -e $out_file, "  Created output file";
                 my $content = readFile($out_file) ;
@@ -1060,7 +1182,7 @@ sub run
                 my $output ;
                 $output = $incumbent if $append ;
 
-                ok &$Func($in, \$output, Append => $append), '  Uncompressed ok' ;
+                ok &$Func($in, \$output, Append => $append, @opts), '  Uncompressed ok' ;
 
                 is $keep_comp, $comp, "  Input buffer not changed" ;
                 is $output, $expected, "  Uncompressed matches original";
@@ -1079,7 +1201,7 @@ sub run
                 my $output ;
                 $output = $incumbent if $append ;
 
-                ok &$Func('-', \$output, Append => $append), '  Uncompressed ok' 
+                ok &$Func('-', \$output, Append => $append, @opts), '  Uncompressed ok' 
                     or diag $$Error ;
 
                    open(STDIN, "<&SAVEIN");
@@ -1101,7 +1223,7 @@ sub run
             writeFile($in_file, $comp . $appended . $comp . $appended) ;
             my $in = new IO::File "<$in_file" ;
 
-            ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), '  Uncompressed ok' ;
+            ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp, @opts), '  Uncompressed ok' ;
 
             is $out, $expected, "  Uncompressed matches original";
 
@@ -1110,7 +1232,7 @@ sub run
             is $buff, $appended, "  Appended data ok";
 
             $out = '';
-            ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), '  Uncompressed ok' ;
+            ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp, @opts), '  Uncompressed ok' ;
 
             is $out, $expected, "  Uncompressed matches original";
 
@@ -1135,7 +1257,7 @@ sub run
 
             my $output ;
 
-            ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp), '  Uncompressed ok' 
+            ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp, @opts), '  Uncompressed ok' 
                 or diag $$Error ;
 
             my $buff ;
@@ -1149,7 +1271,7 @@ sub run
     }
 
     foreach my $bit ($UncompressClass,
-                     'IO::Uncompress::AnyInflate',
+                     'IO::Uncompress::AnyUncompress',
                     )
     {
         # TODO -- Add Append mode tests
@@ -1161,18 +1283,21 @@ sub run
         my $buffer = "abcde" ;
         my $keep_orig = $buffer;
 
-
-        my $null = compressBuffer($TopType, "") ;
-        my $undef = compressBuffer($TopType, undef) ;
-        my $comp = compressBuffer($TopType, $buffer) ;
+        my $null = compressBuffer(getTopFuncName($UncompressClass), "") ;
+        my $undef = compressBuffer(getTopFuncName($UncompressClass), undef) ;
+        my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
         my $keep_comp = $comp;
 
+        my @opts = ();
+        @opts = (RawInflate => 1)
+            if $bit eq 'IO::Uncompress::AnyUncompress';
+
         my $incumbent = "incumbent data" ;
 
         my $lex = new LexFile(my $file1, my $file2) ;
 
-        writeFile($file1, compressBuffer($TopType,"data1"));
-        writeFile($file2, compressBuffer($TopType,"data2"));
+        writeFile($file1, compressBuffer(getTopFuncName($UncompressClass),"data1"));
+        writeFile($file2, compressBuffer(getTopFuncName($UncompressClass),"data2"));
 
         my $of = new IO::File "<$file1" ;
         ok $of, "  Created output filehandle" ;
@@ -1188,7 +1313,7 @@ sub run
             title "$TopType - From ArrayRef to Buffer" ;
 
             my $output  ;
-            ok &$Func(\@input, \$output, AutoClose => 0), '  UnCompressed ok' ;
+            ok &$Func(\@input, \$output, AutoClose => 0, @opts), '  UnCompressed ok' ;
 
             is $output, join('', @expected)
         }
@@ -1199,7 +1324,7 @@ sub run
             my $lex = new LexFile my $output;
             $of->open("<$file1") ;
 
-            ok &$Func(\@input, $output, AutoClose => 0), '  UnCompressed ok' ;
+            ok &$Func(\@input, $output, AutoClose => 0, @opts), '  UnCompressed ok' ;
 
             is readFile($output), join('', @expected)
         }
@@ -1211,7 +1336,7 @@ sub run
             my $fh = new IO::File ">$output" ;
             $of->open("<$file1") ;
 
-            ok &$Func(\@input, $fh, AutoClose => 0), '  UnCompressed ok' ;
+            ok &$Func(\@input, $fh, AutoClose => 0, @opts), '  UnCompressed ok' ;
             $fh->close;
 
             is readFile($output), join('', @expected)
@@ -1222,7 +1347,7 @@ sub run
 
             my @output = (\'first') ;
             $of->open("<$file1") ;
-            ok &$Func(\@input, \@output, AutoClose => 0), '  UnCompressed ok' ;
+            ok &$Func(\@input, \@output, AutoClose => 0, @opts), '  UnCompressed ok' ;
 
             is_deeply \@input, \@keep, "  Input array not changed" ;
             is_deeply [map { defined $$_ ? $$_ : "" } @output], 
@@ -1233,7 +1358,7 @@ sub run
     }
 
     foreach my $bit ($UncompressClass,
-                     'IO::Uncompress::AnyInflate',
+                     'IO::Uncompress::AnyUncompress',
                     )
     {
         # TODO -- Add Append mode tests
@@ -1249,11 +1374,15 @@ sub run
         mkdir $tmpDir1, 0777;
         mkdir $tmpDir2, 0777;
 
+        my @opts = ();
+        @opts = (RawInflate => 1)
+            if $bit eq 'IO::Uncompress::AnyUncompress';
+
         ok   -d $tmpDir1, "  Temp Directory $tmpDir1 exists";
         #ok ! -d $tmpDir2, "  Temp Directory $tmpDir2 does not exist";
 
         my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
-        foreach (@files) { writeFile($_, compressBuffer($TopType, "abc $_")) }
+        foreach (@files) { writeFile($_, compressBuffer(getTopFuncName($UncompressClass), "abc $_")) }
 
         my @expected = map { "abc $_" } @files ;
         my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
@@ -1261,7 +1390,7 @@ sub run
         {
             title "$TopType - From FileGlob to FileGlob" ;
 
-            ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), '  UnCompressed ok' 
+            ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>", @opts), '  UnCompressed ok' 
                 or diag $$Error ;
 
             my @copy = @expected;
@@ -1277,7 +1406,7 @@ sub run
             title "$TopType - From FileGlob to Arrayref" ;
 
             my @output = (\'first');
-            ok &$Func("<$tmpDir1/a*.tmp>" => \@output), '  UnCompressed ok' 
+            ok &$Func("<$tmpDir1/a*.tmp>" => \@output, @opts), '  UnCompressed ok' 
                 or diag $$Error ;
 
             my @copy = ('first', @expected);
@@ -1293,7 +1422,7 @@ sub run
             title "$TopType - From FileGlob to Buffer" ;
 
             my $output ;
-            ok &$Func("<$tmpDir1/a*.tmp>" => \$output), '  UnCompressed ok' 
+            ok &$Func("<$tmpDir1/a*.tmp>" => \$output, @opts), '  UnCompressed ok' 
                 or diag $$Error ;
 
             is $output, join('', @expected), "  got expected uncompressed data";
@@ -1304,7 +1433,7 @@ sub run
 
             my $lex = new LexFile my $output ;
             ok ! -e $output, "  $output does not exist" ;
-            ok &$Func("<$tmpDir1/a*.tmp>" => $output), '  UnCompressed ok' 
+            ok &$Func("<$tmpDir1/a*.tmp>" => $output, @opts), '  UnCompressed ok' 
                 or diag $$Error ;
 
             ok -e $output, "  $output does exist" ;
@@ -1317,7 +1446,7 @@ sub run
             my $output = 'abc' ;
             my $lex = new LexFile $output ;
             my $fh = new IO::File ">$output" ;
-            ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1), '  UnCompressed ok' 
+            ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1, @opts), '  UnCompressed ok' 
                 or diag $$Error ;
 
             ok -e $output, "  $output does exist" ;