#!/bin/sh

if test x"$srcdir" != x""; then
    builddir="."	# running from make check, but it does not define that
else
    srcdir=`echo "$0" | sed s,[^/]*$,,`
    test "$srcdir" = "$0" && srcdir=.
    test -z "$srcdir" && srcdir=.
    builddir="$srcdir"	# running manually, have to assume
fi

srcdir=`cd $srcdir;pwd`
builddir=`cd $builddir;pwd`

testfile="$srcdir/tests"
if [ $# -ge 1 ]; then testfile="$1"; fi

dirs=`awk -F '#' '{print $1}' $testfile`

basedir=`head -n 1 $testfile | awk '{print $2}'`
cd $srcdir; if [ ! -d $basedir ]; then
    cd ..; if [ ! -d $basedir ]; then exit 77; fi	# for make distcheck
fi
basedir=`cd $basedir;pwd`

cd $builddir
error=0

for dir in $dirs; do
    echo $dir
    ../src/a52dec -co float $basedir/$dir/stream >/dev/null 2>&1 >output.float
    ./compare output.float $basedir/$dir/output.float || error=1
    rm -f output.float
done

exit $error
