summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtest/compile.sh3
-rwxr-xr-xtest/deflate18
-rw-r--r--test/inflate-app.c34
-rwxr-xr-xtest/test.sh17
4 files changed, 72 insertions, 0 deletions
diff --git a/test/compile.sh b/test/compile.sh
new file mode 100755
index 0000000..3d6306f
--- /dev/null
+++ b/test/compile.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec gcc -ggdb -Wall -Wextra -pedantic -I../src -o inflate inflate-app.c ../src/inflate.c
diff --git a/test/deflate b/test/deflate
new file mode 100755
index 0000000..0271d59
--- /dev/null
+++ b/test/deflate
@@ -0,0 +1,18 @@
+#!/usr/bin/env python3
+
+import sys
+import zlib
+
+level = -1
+if len(sys.argv) > 2:
+ level = int(sys.argv[2])
+
+try:
+ with open(sys.argv[1], "rb") as f:
+ input_data = f.read()
+except FileNotFoundError:
+ input_data = sys.argv[1].encode("utf-8")
+
+output = zlib.compress(input_data, level=level)
+
+sys.stdout.buffer.write(output)
diff --git a/test/inflate-app.c b/test/inflate-app.c
new file mode 100644
index 0000000..dddc807
--- /dev/null
+++ b/test/inflate-app.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "inflate.h"
+
+unsigned char *inbuf;
+unsigned char *outbuf;
+
+int main(void)
+{
+ // 16 MB
+ inbuf = malloc(4096 * 4096);
+ outbuf = malloc(4096 * 4096);
+
+ if (inbuf == NULL || outbuf == NULL) {
+ return 1;
+ }
+
+ size_t in_size = fread(inbuf, 1, 4096 * 4096, stdin);
+
+ if (in_size == 0) {
+ return 1;
+ }
+
+ int16_t out_size = inflate_zlib(inbuf, in_size, outbuf, 65535);
+
+ if (out_size < 0) {
+ return -out_size;
+ }
+
+ fwrite(outbuf, 1, out_size, stdout);
+
+ return 0;
+}
diff --git a/test/test.sh b/test/test.sh
new file mode 100755
index 0000000..e60aaa0
--- /dev/null
+++ b/test/test.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+set -eu
+
+cd "$(dirname "$0")"
+
+./compile.sh
+
+for file in $(find .. -type f -size -65000c); do
+ if ! ./deflate $file | ./inflate > tmp; then
+ echo "inflate error at $file"
+ ./deflate $file | ./inflate > tmp
+ fi
+ diff $file tmp
+done
+
+rm -f tmp