1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;
chdir("runlength") or die "chdir testdir failed: $!\n";
require TestDriver;
my $td = new TestDriver('runlength');
cleanup();
my @files = (
"01", # basic case, ends with copy
"02", # basic case, ends with run
"03", # long run run
"04", # ends with copy, length % 128 == 0
"05", # run starts at byte 128
"empty", # empty file
);
# Create this rather than committing an empty file, which always looks
# like an error.
open(F, ">empty");
close(F);
foreach my $f (@files)
{
$td->runtest("encode $f",
{$td->COMMAND => "runlength -encode $f a"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check encoded output",
{$td->FILE => "a"},
{$td->FILE => "$f.encoded"});
$td->runtest("decode $f.encoded",
{$td->COMMAND => "runlength -decode $f.encoded a"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check decoded output",
{$td->FILE => "a"},
{$td->FILE => "$f"});
}
concatenate("01.encoded", "02.encoded", "concat.encoded");
concatenate("01", "02", "concat");
$td->runtest("decode with embedded EOD",
{$td->COMMAND => "runlength -decode concat.encoded a"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check decoded output",
{$td->FILE => "a"},
{$td->FILE => "concat"});
cleanup();
$td->report(2 + (4 * scalar(@files)));
sub cleanup
{
system("rm -f a concat concat.encoded empty");
}
sub concatenate
{
my ($a, $b, $out) = @_;
open(F, ">$out");
foreach my $f ($a, $b)
{
local $/ = undef;
open(G, "<$f");
print F <G>;
close(G);
}
close(F);
}
|