#!/bin/sh

NUMCHECK=`ls $srcdir/verify???.sql | wc | awk '{ print $1 }'`

NUMCHECK=$(( NUMCHECK * 2))
echo 1..$NUMCHECK # Number of tests to be executed.

CEGO=../src/cego
DBXML=db/cegodb.xml

echo "VERIFICATION PROTOCOL" > verify.stdout

VERIFYCOUNT=1

for CACHEENABLED in N Y
do
    for VERIFY in `ls $srcdir/verify???.sql`
    do
	VERIFYTITLE=`cat $VERIFY | grep '###'  | sed 's/--//'`" ( Cache = $CACHEENABLED )"

	$srcdir/mkdb $CACHEENABLED >> verify.stdout

	$CEGO --mode=batch --batchfile=$srcdir/preverify.sql --dbxml=$DBXML --user=lemke/lemke --poolsize=1000 --tableset=TS1 >> verify.stdout
	if [ $? -ne 0 ]
	then
	    echo "not ok $VERIFYCOUNT - $VERIFYTITLE"
	    exit 0
	fi

	$CEGO --mode=batch --batchfile=$VERIFY --dbxml=$DBXML --user=lemke/lemke --poolsize=1000 --tableset=TS1 >> verify.stdout
	if [ $? -ne 0 ]
	then
	    echo "not ok $VERIFYCOUNT - $VERIFYTITLE"
	    exit 0
	fi

	$CEGO --mode=batch --batchfile=$srcdir/postverify.sql --dbxml=$DBXML --user=lemke/lemke --poolsize=1000 --tableset=TS1 >> verify.stdout
	if [ $? -ne 0 ]
	then
	    echo "not ok $VERIFYCOUNT - $VERIFYTITLE"
	    exit 0
	fi
    
	RESULTCHECK=`$CEGO --mode=batch --batchfile=$srcdir/resultverify.sql --dbxml=$DBXML --user=lemke/lemke --poolsize=1000 --tableset=TS1 | grep GATE | awk -F\| '{ print $4 }' | grep ERROR`

	# echo $RESULTCHECK
	
	if [ "$RESULTCHECK" ]
	then
            echo "not ok $VERIFYCOUNT - $VERIFYTITLE"
	else
	    echo "ok $VERIFYCOUNT - $VERIFYTITLE"
	fi

	VERIFYCOUNT=`expr $VERIFYCOUNT + 1`
       
    done
done
exit 0
