#!/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"
OPT="-Wall -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_REENTRANT -Wstrict-prototypes -Wshadow -funsigned-char -Wunused -Winit-self -Wcast-align -fno-strict-aliasing -O2 -g -I../common -I../include"

echo "Generating test-msg"
gcc $OPT test-msg.c $lib -o test-msg
echo "Generating test-string"
gcc $OPT test-string.c ../lib/mr_str.c $lib -o test-string
echo "Generating test-conf"
gcc $OPT test-conf.c $lib -o test-conf
echo "Generating test-mem"
gcc $OPT test-mem.c $lib -o test-mem

echo "Testing against previous run"
for f in test-conf test-string test-msg test-mem; 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
	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
