📄 oneshot.pl
字号:
# # ok &$Func( { \@input, \@output } , AutoClose => 0), ' Compressed ok' ;# ## # is $output[0], 'first', " Array[0] unchanged";# ## # is_deeply \@input, \@keep, " Input array not changed" ;# # my @got = shift @output;# # foreach (@output) { push @got, anyUncompress($_) }# ## # is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";# ## # }# ## # if (0)# # {# # title "$TopType - From Array Ref to Buffer" ;# ## # # rewind the filehandle# # $of->open("<$file1") ;# ## # my $output ;# # ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;# ## # my $got = anyUncompress(\$output);# ## # is $got, join('', @expected), " Got Expected uncompressed data";# # }# ## # if (0)# # {# # title "$TopType - From Array Ref to Filename" ;# ## # my ($file3) = ("file3");# # my $lex = new LexFile($file3) ;# ## # # rewind the filehandle# # $of->open("<$file1") ;# ## # my $output ;# # ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;# ## # my $got = anyUncompress($file3);# ## # is $got, join('', @expected), " Got Expected uncompressed data";# # }# ## # if (0)# # {# # title "$TopType - From Array Ref to Filehandle" ;# ## # my ($file3) = ("file3");# # my $lex = new LexFile($file3) ;# ## # my $fh3 = new IO::File ">$file3";# ## # # rewind the filehandle# # $of->open("<$file1") ;# ## # my $output ;# # ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;# ## # $fh3->close();# ## # my $got = anyUncompress($file3);# ## # is $got, join('', @expected), " Got Expected uncompressed data";# # }# } foreach my $bit ($CompressClass ) { my $Error = getErrorRef($bit); my $Func = getTopFuncRef($bit); my $TopType = getTopFuncName($bit); for my $files ( [qw(a1)], [qw(a1 a2 a3)] ) { my $tmpDir1 = 'tmpdir1'; my $tmpDir2 = 'tmpdir2'; my $lex = new LexDir($tmpDir1, $tmpDir2) ; mkdir $tmpDir1, 0777; mkdir $tmpDir2, 0777; ok -d $tmpDir1, " Temp Directory $tmpDir1 exists"; #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist"; my @files = map { "$tmpDir1/$_.tmp" } @$files ; foreach (@files) { writeFile($_, "abc $_") } my @expected = map { "abc $_" } @files ; my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ; { title "$TopType - From FileGlob to FileGlob files [@$files]" ; ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' Compressed ok' or diag $$Error ; my @copy = @expected; for my $file (@outFiles) { is anyUncompress($file), shift @copy, " got expected from $file" ; } is @copy, 0, " got all files"; } { title "$TopType - From FileGlob to Array files [@$files]" ; my @buffer = ('first') ; ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), ' Compressed ok' or diag $$Error ; is shift @buffer, 'first'; my @copy = @expected; for my $buffer (@buffer) { is anyUncompress($buffer), shift @copy, " got expected " ; } is @copy, 0, " got all files"; } foreach my $ms (@MultiValues) { { title "$TopType - From FileGlob to Buffer files [@$files], MS $ms" ; my $buffer ; ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer, MultiStream => $ms), ' Compressed ok' or diag $$Error ; #hexDump(\$buffer); my $got = anyUncompress([ \$buffer, MultiStream => $ms ]); is $got, join("", @expected), " got expected" ; my @headers = getHeaders(\$buffer); is @headers, $ms ? @files : 1, " Header count ok"; } { title "$TopType - From FileGlob to Filename files [@$files], MS $ms" ; my $filename = "abcde"; my $lex = new LexFile($filename) ; ok &$Func("<$tmpDir1/a*.tmp>" => $filename, MultiStream => $ms), ' Compressed ok' or diag $$Error ; #hexDump(\$buffer); my $got = anyUncompress([$filename, MultiStream => $ms]); is $got, join("", @expected), " got expected" ; my @headers = getHeaders($filename); is @headers, $ms ? @files : 1, " Header count ok"; } { title "$TopType - From FileGlob to Filehandle files [@$files], MS $ms" ; my $filename = "abcde"; my $lex = new LexFile($filename) ; my $fh = new IO::File ">$filename"; ok &$Func("<$tmpDir1/a*.tmp>" => $fh, MultiStream => $ms, AutoClose => 1), ' Compressed ok' or diag $$Error ; #hexDump(\$buffer); my $got = anyUncompress([$filename, MultiStream => $ms]); is $got, join("", @expected), " got expected" ; my @headers = getHeaders($filename); is @headers, $ms ? @files : 1, " Header count ok"; } } } } foreach my $bit ($UncompressClass, 'IO::Uncompress::AnyUncompress', ) { my $Error = getErrorRef($bit); my $Func = getTopFuncRef($bit); my $TopType = getTopFuncName($bit); my $buffer = "abcde" ; my $buffer2 = "ABCDE" ; my $keep_orig = $buffer; 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 ; $expected = $incumbent . $buffer if $append ; { title "$TopType - From Buff to Buff, Append($append)" ; my $output ; $output = $incumbent if $append ; ok &$Func(\$comp, \$output, Append => $append, @opts), ' Uncompressed ok' ; is $keep_comp, $comp, " Input buffer not changed" ; is $output, $expected, " Uncompressed matches original"; } { title "$TopType - From Buff to Array, Append($append)" ; my @output = ('first'); #$output = $incumbent if $append ; ok &$Func(\$comp, \@output, Append => $append, @opts), ' Uncompressed ok' ; is $keep_comp, $comp, " Input buffer not changed" ; is $output[0], 'first', " Uncompressed matches original"; is ${ $output[1] }, $buffer, " Uncompressed matches original" or diag $output[1] ; is @output, 2, " only 2 elements in the array" ; } { title "$TopType - From Buff to Filename, Append($append)" ; my $lex = new LexFile(my $out_file) ; if ($append) { writeFile($out_file, $incumbent) } else { ok ! -e $out_file, " Output file does not exist" } ok &$Func(\$comp, $out_file, Append => $append, @opts), ' Uncompressed ok' ; ok -e $out_file, " Created output file"; my $content = readFile($out_file) ; is $keep_comp, $comp, " Input buffer not changed" ; is $content, $expected, " Uncompressed matches original"; } { title "$TopType - From Buff to Handle, Append($append)" ; my $lex = new LexFile(my $out_file) ; my $of ; if ($append) { writeFile($out_file, $incumbent) ; $of = new IO::File "+< $out_file" ; } else { ok ! -e $out_file, " Output file does not exist" ; $of = new IO::File "> $out_file" ; } isa_ok $of, 'IO::File', ' $of' ; ok &$Func(\$comp, $of, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ; ok -e $out_file, " Created output file"; my $content = readFile($out_file) ; is $keep_comp, $comp, " Input buffer not changed" ; is $content, $expected, " Uncompressed matches original"; } { title "$TopType - From Filename to Filename, Append($append)" ; my $lex = new LexFile(my $in_file, my $out_file) ; if ($append) { writeFile($out_file, $incumbent) } else { ok ! -e $out_file, " Output file does not exist" } writeFile($in_file, $comp); ok &$Func($in_file, $out_file, Append => $append, @opts), ' Uncompressed ok' ; ok -e $out_file, " Created output file"; my $content = readFile($out_file) ; is $keep_comp, $comp, " Input buffer not changed" ; is $content, $expected, " Uncompressed matches original"; } { title "$TopType - From Filename to Handle, Append($append)" ; my $lex = new LexFile(my $in_file, my $out_file) ; my $out ; if ($append) { writeFile($out_file, $incumbent) ; $out = new IO::File "+< $out_file" ; } else { ok ! -e $out_file, " Output file does not exist" ; $out = new IO::File "> $out_file" ; } isa_ok $out, 'IO::File', ' $out' ; writeFile($in_file, $comp); ok &$Func($in_file, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ; ok -e $out_file, " Created output file"; my $content = readFile($out_file) ; is $keep_comp, $comp, " Input buffer not changed" ; is $content, $expected, " Uncompressed matches original"; } { title "$TopType - From Filename to Buffer, Append($append)" ; my $lex = new LexFile(my $in_file) ; writeFile($in_file, $comp); my $output ; $output = $incumbent if $append ; ok &$Func($in_file, \$output, Append => $append, @opts), ' Uncompressed ok' ; is $keep_comp, $comp, " Input buffer not changed" ; is $output, $expected, " Uncompressed matches original"; } { title "$TopType - From Handle to Filename, Append($append)" ; my $lex = new LexFile(my $in_file, my $out_file) ; if ($append) { writeFile($out_file, $incumbent) } else { ok ! -e $out_file, " Output file does not exist" } writeFile($in_file, $comp); my $in = new IO::File "<$in_file" ; ok &$Func($in, $out_file, Append => $append, @opts), ' Uncompressed ok' ; ok -e $out_file, " Created output file"; my $content = readFile($out_file) ; is $keep_comp, $comp, " Input buffer not changed" ; is $content, $expected, " Uncompressed matches original"; } { title "$TopType - From Handle to Handle, Append($append)" ; my $lex = new LexFile(my $in_file, my $out_file) ; my $out ; if ($append) { writeFile($out_file, $incumbent) ; $out = new IO::File "+< $out_file" ; } else { ok ! -e $out_file, " Output file does not exist" ; $out = new IO::File "> $out_file" ; } isa_ok $out, 'IO::File', ' $out' ; writeFile($in_file, $comp); my $in = new IO::File "<$in_file" ; ok &$Func($in, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ; ok -e $out_file, " Created output file"; my $content = readFile($out_file) ; is $keep_comp, $comp, " Input buffer not changed" ; is $content, $expected, " Uncompressed matches original"; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -