#!/bin/sh

# Enable verbose output if VERBOSE=1 (see: ../Makefile.am )
[ "$VERBOSE" = "1" ] && set -x

set -e

baseDir=$(dirname "$0")
. ${baseDir}/func.sh

#set

# autotools
#[ -f $abs_top_builddir/tests/config.sh ] && { . ${abs_top_builddir}/tests/config.sh; echo "Found test config autotools."; }
[ "x" != "x${CONFIG_SH}" -a -f ${CONFIG_SH} ] && {
    echo "Using config generated by autotools: '${CONFIG_SH}'";
    . ${CONFIG_SH};
}

# other cases
[ -f $baseDir/../config.sh ] && { echo "Using non-autotools config: $baseDir/../config.sh";
				  . ${baseDir}/../config.sh; }

. ${baseDir}/../config_default.sh

# set examplesBinDir from command line arg. (if provided)
[ "x${1}" != "x" ] && { echo "Using arg '"${1}"' as examplesBinDir";
                        examplesBinDir="${1}"; }

echo "Examples: $examplesBinDir"

#
# Test config
#
testName="adfinfo_hd"

#
# test_common.sh needs testName defined
#
. $baseDir/test_common.sh


#
# setup
#
setup() {
    adfinfo=$(get_test_cmd adfinfo)

    dumpName=a590_WD93028XA_6parts.hdd
    #$dumpfile=$(mktemp ${dumpName}_XXXXXX)
    #$dumpfile=${testtmp}/${testname}/${dumpname}
    dumpFile=tmp/${testName}/${dumpName}

    mkdir -vp tmp/$testName
    gzip -cd ${dumpsDir}/${dumpName}.gz > $dumpFile
}

#
# teardown
#

#. ./teardown.sh
if [ "x$testName" = "x" ]
then
    echo "$0: test not configured"
    exit 1
fi

trap cleanup 0 1 2
cleanup() {
    # path beginning must be hardcoded(!)
    rm -rfv tmp/${testName}/*
    rm -d tmp/${testName}
}


#
# run tests
#
setup
. ${baseDir}/test_runner.sh
run_tests "${testName}"
