Compress::Zlib
[p5sagit/p5-mst-13.2.git] / t / lib / compress / truncate.pl
index 55e4719..a8f0224 100644 (file)
@@ -5,17 +5,7 @@ use warnings;
 use bytes;
 
 use Test::More ;
-use ZlibTestUtils;
-
-BEGIN {
-    # use Test::NoWarnings, if available
-    my $extra = 0 ;
-    $extra = 1
-        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
-
-    plan tests => 2374 + $extra;
-
-}
+use CompTestUtils;
 
 sub run
 {
@@ -53,7 +43,7 @@ EOM
         {
             my $lex = new LexFile my $name ;
         
-            title "Fingerprint Truncation - length $i";
+            title "Fingerprint Truncation - length $i, Transparent $trans";
 
             my $part = substr($compressed, 0, $i);
             writeFile($name, $part);
@@ -65,7 +55,7 @@ EOM
                 ok $gz;
                 ok ! $gz->error() ;
                 my $buff ;
-                ok $gz->read($buff) == length($part) ;
+                is $gz->read($buff), length($part) ;
                 ok $buff eq $part ;
                 ok $gz->eof() ;
                 $gz->close();
@@ -84,7 +74,7 @@ EOM
         {
             my $lex = new LexFile my $name ;
         
-            title "Header Truncation - length $i";
+            title "Header Truncation - length $i, Transparent $trans";
 
             my $part = substr($compressed, 0, $i);
             writeFile($name, $part);
@@ -97,21 +87,26 @@ EOM
         
         foreach my $i ($header_size .. length($compressed) - 1 - $trailer_size)
         {
+            next if $i == 0 ;
+
             my $lex = new LexFile my $name ;
         
-            title "Compressed Data Truncation - length $i";
+            title "Compressed Data Truncation - length $i, Transparent $trans";
 
             my $part = substr($compressed, 0, $i);
             writeFile($name, $part);
             ok my $gz = new $UncompressClass $name,
+                                             -Strict      => 1,
                                              -BlockSize   => $blocksize,
-                                             -Transparent => $trans;
+                                             -Transparent => $trans
+                 or diag $$UnError;
+
             my $un ;
-            my $status = 0 ;
-            $status = $gz->read($un) while $status >= 0 ;
-            ok $status < 0 ;
-            ok $gz->eof() ;
+            my $status = 1 ;
+            $status = $gz->read($un) while $status > 0 ;
+            cmp_ok $status, "<", 0 ;
             ok $gz->error() ;
+            ok $gz->eof() ;
             $gz->close();
         }
         
@@ -125,7 +120,7 @@ EOM
             {
                 my $lex = new LexFile my $name ;
             
-                ok 1, "Length $i, Lax $lax" ;
+                ok 1, "Compressed Trailer Truncation - Length $i, Lax $lax, Transparent $trans" ;
                 my $part = substr($compressed, 0, $i);
                 writeFile($name, $part);
                 ok my $gz = new $UncompressClass $name,
@@ -148,7 +143,7 @@ EOM
                 }
                 else
                 {
-                    ok $status < 0 
+                    cmp_ok $status, "<", 0 
                         or diag "Status $status Error is " . $gz->error() ;
                     ok $gz->eof()
                         or diag "Status $status Error is " . $gz->error() ;
@@ -163,89 +158,3 @@ EOM
 
 1;
 
-__END__
-
-
-foreach my $CompressClass ( 'IO::Compress::RawDeflate')
-{
-    my $UncompressClass = getInverse($CompressClass);
-    my $Error = getErrorRef($UncompressClass);
-
-    my $compressed ;
-        ok( my $x = new IO::Compress::RawDeflate \$compressed);
-        ok $x->write($hello) ;
-        ok $x->close ;
-
-                           
-    my $cc = $compressed ;
-
-    my $gz ;
-    ok($gz = new $UncompressClass(\$cc,
-                                  -Transparent => 0))
-            or diag "$$Error\n";
-    my $un;
-    ok $gz->read($un) > 0 ;
-    ok $gz->close();
-    ok $un eq $hello ;
-    
-    for my $trans (0 .. 1)
-    {
-        title "Testing $CompressClass, Transparent = $trans";
-
-        my $info = $gz->getHeaderInfo() ;
-        my $header_size = $info->{HeaderLength};
-        my $trailer_size = $info->{TrailerLength};
-        ok 1, "Compressed size is " . length($compressed) ;
-        ok 1, "Header size is $header_size" ;
-        ok 1, "Trailer size is $trailer_size" ;
-
-        
-        title "Compressed Data Truncation";
-        foreach my $i (0 .. $blocksize)
-        {
-        
-            my $lex = new LexFile my $name ;
-        
-            ok 1, "Length $i" ;
-            my $part = substr($compressed, 0, $i);
-            writeFile($name, $part);
-            my $gz = new $UncompressClass $name,
-                                       -BlockSize   => $blocksize,
-                                       -Transparent => $trans;
-            if ($trans) {
-                ok $gz;
-                ok ! $gz->error() ;
-                my $buff = '';
-                is $gz->read($buff), length $part ;
-                is $buff, $part ;
-                ok $gz->eof() ;
-                $gz->close();
-            }
-            else {
-                ok !$gz;
-            }
-        }
-
-        foreach my $i ($blocksize+1 .. length($compressed)-1)
-        {
-        
-            my $lex = new LexFile my $name ;
-        
-            ok 1, "Length $i" ;
-            my $part = substr($compressed, 0, $i);
-            writeFile($name, $part);
-            ok my $gz = new $UncompressClass $name,
-                                             -BlockSize   => $blocksize,
-                                             -Transparent => $trans;
-            my $un ;
-            my $status = 0 ;
-            $status = $gz->read($un) while $status >= 0 ;
-            ok $status < 0 ;
-            ok $gz->eof() ;
-            ok $gz->error() ;
-            $gz->close();
-        }
-    }
-    
-}
-