OBJS = $(patsubst %.c, %.o, $(wildcard src/*.c))
TEST_OBJS = $(patsubst %.c, %.o, $(wildcard test/*.c))
TESTS = $(patsubst %.c, %, $(wildcard test/*.c))
-RUN_TESTS = $(addprefix run_, $(TESTS))
+ITESTS = $(wildcard itest/*.sh)
+RUN_TESTS = $(addprefix run_, $(TESTS)) $(addprefix run_, $(ITESTS))
TOOLS = $(patsubst %.c, %, $(wildcard tools/*.c))
default: $(BIN) $(RUN_TESTS) $(TOOLS)
--- /dev/null
+#!/bin/sh
+
+set -e
+
+TANS=src/tANS
+TEST_FILES="empty random repeating text yes zero"
+
+compare_stree_only_roundtrip() {
+ TEMP=$(mktemp)
+ trap "echo 'FAIL: compare_stree_only_roundtrip $1' >&2; rm -f $TEMP" EXIT
+ $TANS -cs $1 | $TANS -ds > $TEMP
+ diff $1 $TEMP
+ echo "PASS: compare_stree_only_roundtrip $1" >&2
+ rm -f $TEMP
+ trap '' EXIT
+}
+
+compare_roundtrip() {
+ TEMP=$(mktemp)
+ trap "echo 'FAIL: compare_roundtrip $1' >&2; rm -f $TEMP" EXIT
+ $TANS -c $1 | $TANS -d > $TEMP
+ diff $1 $TEMP
+ echo "PASS: compare_roundtrip $1" >&2
+ rm -f $TEMP
+ trap '' EXIT
+}
+
+for FILE in $TEST_FILES; do
+ compare_stree_only_roundtrip itest/$FILE
+ compare_roundtrip itest/$FILE
+done
#include <string.h>
#include <unistd.h>
-
-//FIXME
-#include <math.h>
-
#define MAX_BUFSZ 1048576
#define INIT_READSZ 1024
#define N_SYMBOLS 256
tANS_rl_encode_st_init(st, symbol_tbls);
len = (uint32_t) fread(read_buf, 1, read_sz, input);
+ if (len == 0) break;
if (stree_encode(len, read_buf, enc_buf, aux_buf) != 0) goto fail;
for (i = 0; i < len; ++i) {
if (read_sz > MAX_BUFSZ) read_sz = MAX_BUFSZ;
}
+ if (ferror(input)) goto fail;
+
free(freq_tbls);
free(symbol_tbls);
free(st);
}
tANS_rl_decode_st_init(st, symbol_tbls);
- if (fread(&len, sizeof len, 1, input) != 1) goto fail;
+ if (fread(&len, sizeof len, 1, input) != 1) break;
if (fread(&bits, sizeof bits, 1, input) != 1) goto fail;
if (fread(&st->x, sizeof st->x, 1, input) != 1) goto fail;
if (fread(read_buf + 4, (bits + 7) / 8, 1, input) != 1) goto fail;
if (!read_buf || !write_buf || !aux_buf) goto fail;
- while (!feof(input)) {
+ do {
len = (uint32_t) fread(read_buf, 1, read_sz, input);
if (stree_encode(len, read_buf, write_buf, aux_buf) != 0) goto fail;
- if (fwrite(write_buf, len, 1, output) != 1) goto fail;
- }
+ if (len > 0 && fwrite(write_buf, len, 1, output) != 1) goto fail;
+ } while (len > 0);
+
+ if (ferror(input)) goto fail;
free(read_buf);
free(write_buf);
if (!read_buf || !write_buf || !aux_buf) goto fail;
- while (!feof(input)) {
+ do {
len = (uint32_t) fread(read_buf, 1, read_sz, input);
if (stree_decode(len, read_buf, write_buf, aux_buf) != 0) goto fail;
- if (fwrite(write_buf, len, 1, output) != 1) goto fail;
- }
+ if (len > 0 && fwrite(write_buf, len, 1, output) != 1) goto fail;
+ } while (len > 0);
+
+ if (ferror(input)) goto fail;
free(read_buf);
free(write_buf);