aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lz4/buildfile6
-rw-r--r--tests/lz4/driver.cxx47
-rw-r--r--tests/lz4/testscript78
-rw-r--r--tests/lz4/truncated-content.lz4bin0 -> 108 bytes
-rw-r--r--tests/lz4/truncated-header12.lz4bin0 -> 12 bytes
-rw-r--r--tests/lz4/truncated-header6.lz41
6 files changed, 132 insertions, 0 deletions
diff --git a/tests/lz4/buildfile b/tests/lz4/buildfile
new file mode 100644
index 0000000..8944dba
--- /dev/null
+++ b/tests/lz4/buildfile
@@ -0,0 +1,6 @@
+# file : tests/lz4/buildfile
+# license : MIT; see accompanying LICENSE file
+
+import libs = libbutl%lib{butl}
+
+exe{driver}: {hxx cxx}{*} $libs testscript
diff --git a/tests/lz4/driver.cxx b/tests/lz4/driver.cxx
new file mode 100644
index 0000000..e3da5e6
--- /dev/null
+++ b/tests/lz4/driver.cxx
@@ -0,0 +1,47 @@
+// file : tests/lz4/driver.cxx -*- C++ -*-
+// license : MIT; see accompanying LICENSE file
+
+#include <iostream>
+#include <exception>
+
+#include <libbutl/lz4.hxx>
+#include <libbutl/fdstream.mxx>
+#include <libbutl/filesystem.mxx> // entry_stat, path_entry()
+
+using namespace std;
+using namespace butl;
+
+// Usage: argv[0] [-c|-d] <input-file> <output-file>
+//
+int
+main (int argc, const char* argv[])
+try
+{
+ assert (argc == 4);
+
+ ifdstream ifs (argv[2], fdopen_mode::binary, ifdstream::badbit);
+ ofdstream ofs (argv[3], fdopen_mode::binary);
+
+ if (argv[1][1] == 'c')
+ {
+ // @@ TODO: would be nice to get it from fd.
+ //
+ entry_stat st (path_entry (argv[2], true /* follow_symlinks */).second);
+
+ lz4::compress (ofs, ifs,
+ 1 /* compression_level */,
+ 4 /* block_size_id (64KB) */,
+ st.size);
+ }
+ else
+ {
+ lz4::decompress (ofs, ifs);
+ }
+
+ ofs.close ();
+}
+catch (const std::exception& e)
+{
+ cerr << e.what () << endl;
+ return 1;
+}
diff --git a/tests/lz4/testscript b/tests/lz4/testscript
new file mode 100644
index 0000000..1806c94
--- /dev/null
+++ b/tests/lz4/testscript
@@ -0,0 +1,78 @@
+# file : tests/lz4/testscript
+# license : MIT; see accompanying LICENSE file
+
++touch zero
++echo 'The quick brown fox jumps over the lazy dog.' >=small
++cat <<EOI >=1kb
+The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
+the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox
+jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The
+quick brown fox jumps over the lazy dog. The quick brown fox jumps over the
+lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox
+jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The
+quick brown fox jumps over the lazy dog. The quick brown fox jumps over the
+lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox
+jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The
+quick brown fox jumps over the lazy dog. The quick brown fox jumps over the
+lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox
+jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The
+quick brown fox jumps over the lazy dog. The quick brown fox jumps over the
+lazy dog. The quick brown fox jumps over th
+EOI
++cat 1kb 1kb 1kb 1kb 1kb 1kb 1kb 1kb >=8kb
++cat 8kb 8kb 8kb 8kb 8kb 8kb 8kb 8kb >=64kb
++cat 64kb 64kb 64kb 64kb 64kb 64kb 64kb 64kb >=512kb
+
+: rt-zero
+:
+$* -c ../zero zero.lz4 &zero.lz4;
+$* -d zero.lz4 zero &zero;
+diff ../zero zero
+
+: rt-small
+:
+$* -c ../small small.lz4 &small.lz4;
+$* -d small.lz4 small &small;
+diff ../small small
+
+: rt-1kb
+:
+$* -c ../1kb 1kb.lz4 &1kb.lz4;
+$* -d 1kb.lz4 1kb &1kb;
+diff ../1kb 1kb
+
+: rt-8kb
+:
+$* -c ../8kb 8kb.lz4 &8kb.lz4;
+$* -d 8kb.lz4 8kb &8kb;
+diff ../8kb 8kb
+
+: rt-64kb
+:
+$* -c ../64kb 64kb.lz4 &64kb.lz4;
+$* -d 64kb.lz4 64kb &64kb;
+diff ../64kb 64kb
+
+: rt-512kb
+:
+$* -c ../512kb 512kb.lz4 &512kb.lz4;
+$* -d 512kb.lz4 512kb &512kb;
+diff ../512kb 512kb
+
+: truncated-header6
+:
+$* -d $src_base/truncated-header6.lz4 out &out 2>>EOE !=0
+incomplete frame header
+EOE
+
+: truncated-header12
+:
+$* -d $src_base/truncated-header12.lz4 out &out 2>>EOE !=0
+incomplete frame header
+EOE
+
+: truncated-content
+:
+$* -d $src_base/truncated-content.lz4 out &out 2>>EOE !=0
+incomplete compressed content
+EOE
diff --git a/tests/lz4/truncated-content.lz4 b/tests/lz4/truncated-content.lz4
new file mode 100644
index 0000000..2a9a39d
--- /dev/null
+++ b/tests/lz4/truncated-content.lz4
Binary files differ
diff --git a/tests/lz4/truncated-header12.lz4 b/tests/lz4/truncated-header12.lz4
new file mode 100644
index 0000000..101088e
--- /dev/null
+++ b/tests/lz4/truncated-header12.lz4
Binary files differ
diff --git a/tests/lz4/truncated-header6.lz4 b/tests/lz4/truncated-header6.lz4
new file mode 100644
index 0000000..a00e998
--- /dev/null
+++ b/tests/lz4/truncated-header6.lz4
@@ -0,0 +1 @@
+"Ml@ \ No newline at end of file