Commit 917b8295 authored by Daniel Friesel's avatar Daniel Friesel
Browse files

add tests

parent db4aac34
Loading
Loading
Loading
Loading

test/compile.sh

0 → 100755
+3 −0
Original line number Diff line number Diff line
#!/bin/sh

exec gcc -ggdb -Wall -Wextra -pedantic -I../src -o inflate inflate-app.c ../src/inflate.c

test/deflate

0 → 100755
+18 −0
Original line number Diff line number Diff line
#!/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)

test/inflate-app.c

0 → 100644
+34 −0
Original line number Diff line number Diff line
#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;
}

test/test.sh

0 → 100755
+17 −0
Original line number Diff line number Diff line
#!/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