aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
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
parente0d1cd1f4b2de30967f9c70460c2d0765f003676 (diff)
downloadqpdf-2d2f61966525cb948bcb6307cccbc3493b1825b5.tar.zst
Implement Pl_RunLength pipeline
Diffstat (limited to 'libtests')
-rw-r--r--libtests/build.mk1
-rw-r--r--libtests/libtests.testcov3
-rw-r--r--libtests/qtest/runlength.test75
-rw-r--r--libtests/qtest/runlength/011
-rw-r--r--libtests/qtest/runlength/01.encoded1
-rw-r--r--libtests/qtest/runlength/021
-rw-r--r--libtests/qtest/runlength/02.encoded1
-rw-r--r--libtests/qtest/runlength/03bin0 -> 516 bytes
-rw-r--r--libtests/qtest/runlength/03.encodedbin0 -> 275 bytes
-rw-r--r--libtests/qtest/runlength/041
-rw-r--r--libtests/qtest/runlength/04.encoded1
-rw-r--r--libtests/qtest/runlength/051
-rw-r--r--libtests/qtest/runlength/05.encoded1
-rw-r--r--libtests/qtest/runlength/empty.encoded1
-rw-r--r--libtests/runlength.cc47
15 files changed, 135 insertions, 0 deletions
diff --git a/libtests/build.mk b/libtests/build.mk
index f779d211..7977c8c5 100644
--- a/libtests/build.mk
+++ b/libtests/build.mk
@@ -14,6 +14,7 @@ BINS_libtests = \
qutil \
random \
rc4 \
+ runlength \
sha2
TARGETS_libtests = $(foreach B,$(BINS_libtests),libtests/$(OUTPUT_DIR)/$(call binname,$(B)))
diff --git a/libtests/libtests.testcov b/libtests/libtests.testcov
index a5fe625f..01ca9efe 100644
--- a/libtests/libtests.testcov
+++ b/libtests/libtests.testcov
@@ -24,3 +24,6 @@ InputSource start_chars matched but not check 0
InputSource not enough bytes 0
InputSource findLast found more than one 0
InputSource found match at buf[0] 0
+Pl_RunLength: switch to run 1
+Pl_RunLength flush full buffer 1
+Pl_RunLength flush empty buffer 0
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);
+}
diff --git a/libtests/qtest/runlength/01 b/libtests/qtest/runlength/01
new file mode 100644
index 00000000..c39144df
--- /dev/null
+++ b/libtests/qtest/runlength/01
@@ -0,0 +1 @@
+wwwwwwwwwwwwwwwwwwwwwwwwwqqqqqrstv \ No newline at end of file
diff --git a/libtests/qtest/runlength/01.encoded b/libtests/qtest/runlength/01.encoded
new file mode 100644
index 00000000..fc26c6f6
--- /dev/null
+++ b/libtests/qtest/runlength/01.encoded
@@ -0,0 +1 @@
+čwüqrstv€ \ No newline at end of file
diff --git a/libtests/qtest/runlength/02 b/libtests/qtest/runlength/02
new file mode 100644
index 00000000..b5d6cfc8
--- /dev/null
+++ b/libtests/qtest/runlength/02
@@ -0,0 +1 @@
+wwwwwwwwwwwwwwwwwwwwwwwwwqqqqqrstvxxxxxxxxxxxxxxxxxxxxxxx \ No newline at end of file
diff --git a/libtests/qtest/runlength/02.encoded b/libtests/qtest/runlength/02.encoded
new file mode 100644
index 00000000..85bb323e
--- /dev/null
+++ b/libtests/qtest/runlength/02.encoded
@@ -0,0 +1 @@
+čwüqrstvęx€ \ No newline at end of file
diff --git a/libtests/qtest/runlength/03 b/libtests/qtest/runlength/03
new file mode 100644
index 00000000..b8dbdb28
--- /dev/null
+++ b/libtests/qtest/runlength/03
Binary files differ
diff --git a/libtests/qtest/runlength/03.encoded b/libtests/qtest/runlength/03.encoded
new file mode 100644
index 00000000..0fac6b58
--- /dev/null
+++ b/libtests/qtest/runlength/03.encoded
Binary files differ
diff --git a/libtests/qtest/runlength/04 b/libtests/qtest/runlength/04
new file mode 100644
index 00000000..9ad537ac
--- /dev/null
+++ b/libtests/qtest/runlength/04
@@ -0,0 +1 @@
+wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab \ No newline at end of file
diff --git a/libtests/qtest/runlength/04.encoded b/libtests/qtest/runlength/04.encoded
new file mode 100644
index 00000000..0c97dde2
--- /dev/null
+++ b/libtests/qtest/runlength/04.encoded
@@ -0,0 +1 @@
+wabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab€ \ No newline at end of file
diff --git a/libtests/qtest/runlength/05 b/libtests/qtest/runlength/05
new file mode 100644
index 00000000..979bf52b
--- /dev/null
+++ b/libtests/qtest/runlength/05
@@ -0,0 +1 @@
+ababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababbbbbb \ No newline at end of file
diff --git a/libtests/qtest/runlength/05.encoded b/libtests/qtest/runlength/05.encoded
new file mode 100644
index 00000000..2a645eef
--- /dev/null
+++ b/libtests/qtest/runlength/05.encoded
@@ -0,0 +1 @@
+~abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababaűb€ \ No newline at end of file
diff --git a/libtests/qtest/runlength/empty.encoded b/libtests/qtest/runlength/empty.encoded
new file mode 100644
index 00000000..5416677b
--- /dev/null
+++ b/libtests/qtest/runlength/empty.encoded
@@ -0,0 +1 @@
+€ \ No newline at end of file
diff --git a/libtests/runlength.cc b/libtests/runlength.cc
new file mode 100644
index 00000000..3dfe0563
--- /dev/null
+++ b/libtests/runlength.cc
@@ -0,0 +1,47 @@
+#include <qpdf/Pl_RunLength.hh>
+#include <qpdf/Pl_StdioFile.hh>
+#include <qpdf/QUtil.hh>
+
+#include <stdio.h>
+#include <string.h>
+#include <iostream>
+#include <stdlib.h>
+
+int main(int argc, char* argv[])
+{
+ if (argc != 4)
+ {
+ std::cerr << "Usage: runlength {-encode|-decode} infile outfile"
+ << std::endl;
+ exit(2);
+ }
+
+ bool encode = (strcmp("-encode", argv[1]) == 0);
+ char* infilename = argv[2];
+ char* outfilename = argv[3];
+
+ FILE* infile = QUtil::safe_fopen(infilename, "rb");
+ FILE* outfile = QUtil::safe_fopen(outfilename, "wb");
+ Pl_StdioFile out("stdout", outfile);
+ unsigned char buf[100];
+ bool done = false;
+ Pl_RunLength rl(
+ "runlength", &out,
+ (encode ? Pl_RunLength::a_encode : Pl_RunLength::a_decode));
+ while (! done)
+ {
+ size_t len = fread(buf, 1, sizeof(buf), infile);
+ if (len <= 0)
+ {
+ done = true;
+ }
+ else
+ {
+ rl.write(buf, len);
+ }
+ }
+ rl.finish();
+ fclose(infile);
+ fclose(outfile);
+ return 0;
+}