#!/bin/bash

if [ $# -eq 2 ] ; then
	export TESTDIR=$1
	export GNOKII=$2
elif [ $# -eq 0 ] ; then
	export TESTDIR=`pwd`
	export GNOKII="../gnokii/gnokii --config $TESTDIR/.gnokiirc"
else
	echo "*** Usage: ./testit [Path to test files] [gnokii command] ***"
	exit 1
fi

# Backup LC_MESSAGES value
LC_MES_TMP=$LC_MESSAGES
export LC_MESSAGES=C

RETVAL=0
cd $TESTDIR
# For now ignore the tests that are known to fail:
#   - test.2.concatsms
#   - test.17.picture2
#   - test.26.cimelody
#   - test.27.cimelody2
for A in test.0.identify \
	test.1.sms test.29.sendsms test.30.emptysms test.3.ucs2sms test.8.send161sms\
	test.33.send140sms8bit test.34.send141sms8bit \
	test.10.oplogo test.14.oplogo-xpm \
	test.11.ringtone \
	test.13.emspicture test.15.emspicture2 test.18.emsanimation \
	test.16.imelody \
	test.40.getsms test.41.getsms test.42.getsms test.43.getsms; do
    echo -n "Doing $A... "
    B=`echo $A | sed s/test/out/`
    source $A 2>&1 | grep -v ^GNOKII | grep -v '^Doing operation' > my$B
    if cmp my$B $B > /dev/null 2>&1; then
	echo ok
    else
	echo '*** FAILED'
	diff -u $B my$B
	RETVAL=1
    fi
done

# Restore LC_MESSAGES value
export LC_MESSAGES=$LC_MES_TMP

exit $RETVAL

