#!/bin/sh
#
# Test the test command in btape
#
TestName="btape-test-tape"
JobName=btapetest
. scripts/functions

require_tape_drive

scripts/copy-btape-confs
scripts/cleanup-tape

change_jobname $JobName
start_test

if test "$debug" -eq 1 ; then
  $bin/btape -c bin/bareos-sd.conf Drive-0 <<END_OF_DATA | tee ${cwd}/tmp/log1.out
test
quit
END_OF_DATA
else
  $bin/btape -c bin/bareos-sd.conf Drive-0 <<END_OF_DATA >${cwd}/tmp/log1.out 2>&1
test
quit
END_OF_DATA
fi

if [ $? != 0 ] ; then
   echo " "
   echo " "
   echo "  !!!!! btape test failed!!! !!!!! "
   echo "  !!!!! btape test failed!!! !!!!! " >>test.out
   echo " "
   exit 1
fi

#
#  Increase block size to 262144
#
cp ${cwd}/bin/bareos-sd.conf ${cwd}/tmp/1
sed -e 's%64512%262144%' ${cwd}/tmp/1 >${cwd}/bin/bareos-sd.conf

if test "$debug" -eq 1 ; then
  $bin/btape -c bin/bareos-sd.conf Drive-0 <<END_OF_DATA | tee ${cwd}/tmp/log2.out
test
quit
END_OF_DATA
else
  $bin/btape -c bin/bareos-sd.conf Drive-0 <<END_OF_DATA >${cwd}/tmp/log2.out 2>&1
test
quit
END_OF_DATA
fi

if [ $? != 0 ] ; then
   echo " "
   echo " "
   echo "  !!!!! btape test failed!!! !!!!! "
   echo "  !!!!! btape test failed!!! !!!!! " >>test.out
   echo " "
else
   echo "  ===== btape test OK ===== "
   echo "  ===== btape test OK ===== " >>test.out
   scripts/cleanup
fi
