#!/bin/sh

cd tests || { echo "ERROR: Could not change to tests directory" ; exit 1; } >&2
tests=../../$srcdir/tests

testname=$(basename $0)
rm -f $testname.log
rm -rf run$testname

mkdir run$testname && cd run$testname || { echo "ERROR: Could not change to test directory" ; exit 1; } >&2

tar -xf $tests/flatdata.tar.gz || { echo "ERROR: Could not extract data test files" ; exit 1; } >&2
tar -xf $tests/flatdata-par2files.tar.gz || { echo "ERROR: Could not extract par test files" ; exit 1; } >&2

banner="rename using PAR 2.0 data"
dashes=`echo "$banner" | sed s/./-/g`

echo $dashes
echo $banner
echo $dashes

mv test-1.data rename4
mv test-2.data rename5
mv test-3.data rename6
mv test-4.data rename7
mv test-5.data rename9
mv test-6.data rename8
mv test-7.data rename3
mv test-8.data rename1
mv test-9.data rename2

../../par2 r testdata.par2 rename* > ../$testname.log || { echo "ERROR: Initial PAR 2.0 verification and rename failed" ; exit 1; } >&2
test -e test-1.data ||  { echo "ERROR: rename failed" ; exit 1; } >&2
test -e test-2.data ||  { echo "ERROR: rename failed" ; exit 1; } >&2
test -e test-3.data ||  { echo "ERROR: rename failed" ; exit 1; } >&2
test -e test-4.data ||  { echo "ERROR: rename failed" ; exit 1; } >&2
test -e test-5.data ||  { echo "ERROR: rename failed" ; exit 1; } >&2
test -e test-6.data ||  { echo "ERROR: rename failed" ; exit 1; } >&2
test -e test-7.data ||  { echo "ERROR: rename failed" ; exit 1; } >&2
test -e test-8.data ||  { echo "ERROR: rename failed" ; exit 1; } >&2
test -e test-9.data ||  { echo "ERROR: rename failed" ; exit 1; } >&2

cd ..
rm -rf run$testname

exit 0;

