#!/bin/bash
#
# $Id$
#
# test script for library functions
#

lib="../lib/mr_conf.c ../lib/mr_msg.c ../lib/mr_err.c ../lib/mr_mem.c ../lib/mr_str.c ../lib/mr_file.c"
OPT="-Wall -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_REENTRANT -Wstrict-prototypes -Wshadow -funsigned-char -Wunused -Wcast-align -fno-strict-aliasing -O2 -g -I../common -I../include"

prg="test-conf test-string test-msg test-mem"

for i in $prg ; do
	echo "Generating $i"
	gcc $OPT $i.c $lib -o $i
done

echo "Testing against previous run"
for f in $prg ; do
	chmod 755 $f
	./$f > /tmp/$f.res
	diff -q $f.res /tmp/$f.res
	if [ $? -ne 0 ]; then
		echo "$f test KO !!"
	else
		echo "$f test OK"
	fi
done
for f in $prg ; do
	valgrind -q --error-exitcode=1 --leak-check=yes ./$f 2>&1 > /tmp/valgrind-$f.res
	if [ $? -ne 0 ]; then
		echo "valgrind $f test KO !!"
	fi
done
