aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qtest/runlength.test
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2017-08-16 12:26:31 +0200
committerJay Berkenbilt <ejb@ql.org>2017-08-19 20:50:55 +0200
commit2d2f61966525cb948bcb6307cccbc3493b1825b5 (patch)
tree862dbdd156d2af563d0d20f755f7abeb2c200889 /libtests/qtest/runlength.test
parente0d1cd1f4b2de30967f9c70460c2d0765f003676 (diff)
downloadqpdf-2d2f61966525cb948bcb6307cccbc3493b1825b5.tar.zst
Implement Pl_RunLength pipeline
Diffstat (limited to 'libtests/qtest/runlength.test')
-rw-r--r--libtests/qtest/runlength.test75
1 files changed, 75 insertions, 0 deletions
diff --git a/libtests/qtest/runlength.test b/libtests/qtest/runlength.test
new file mode 100644
index 00000000..26b6155d
--- /dev/null
+++ b/libtests/qtest/runlength.test
@@ -0,0 +1,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);
+}