From 2d2f61966525cb948bcb6307cccbc3493b1825b5 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 16 Aug 2017 06:26:31 -0400 Subject: Implement Pl_RunLength pipeline --- libtests/build.mk | 1 + libtests/libtests.testcov | 3 ++ libtests/qtest/runlength.test | 75 +++++++++++++++++++++++++++++++++ libtests/qtest/runlength/01 | 1 + libtests/qtest/runlength/01.encoded | 1 + libtests/qtest/runlength/02 | 1 + libtests/qtest/runlength/02.encoded | 1 + libtests/qtest/runlength/03 | Bin 0 -> 516 bytes libtests/qtest/runlength/03.encoded | Bin 0 -> 275 bytes libtests/qtest/runlength/04 | 1 + libtests/qtest/runlength/04.encoded | 1 + libtests/qtest/runlength/05 | 1 + libtests/qtest/runlength/05.encoded | 1 + libtests/qtest/runlength/empty.encoded | 1 + libtests/runlength.cc | 47 +++++++++++++++++++++ 15 files changed, 135 insertions(+) create mode 100644 libtests/qtest/runlength.test create mode 100644 libtests/qtest/runlength/01 create mode 100644 libtests/qtest/runlength/01.encoded create mode 100644 libtests/qtest/runlength/02 create mode 100644 libtests/qtest/runlength/02.encoded create mode 100644 libtests/qtest/runlength/03 create mode 100644 libtests/qtest/runlength/03.encoded create mode 100644 libtests/qtest/runlength/04 create mode 100644 libtests/qtest/runlength/04.encoded create mode 100644 libtests/qtest/runlength/05 create mode 100644 libtests/qtest/runlength/05.encoded create mode 100644 libtests/qtest/runlength/empty.encoded create mode 100644 libtests/runlength.cc (limited to 'libtests') 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 ; + 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 Binary files /dev/null and b/libtests/qtest/runlength/03 differ diff --git a/libtests/qtest/runlength/03.encoded b/libtests/qtest/runlength/03.encoded new file mode 100644 index 00000000..0fac6b58 Binary files /dev/null and b/libtests/qtest/runlength/03.encoded 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 +#include +#include + +#include +#include +#include +#include + +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; +} -- cgit v1.2.3-54-g00ecf