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


require_tape_drive
require_autochanger

scripts/cleanup
scripts/copy-2tape-confs

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
capcmd
speed
test
yes
quit
END_OF_DATA
else
  $bin/btape -c bin/bareos-sd.conf Drive-0 <<END_OF_DATA | tee ${cwd}/tmp/log1.out
capcmd
speed
test
yes
quit
END_OF_DATA
fi

if [ $? != 0 ] ; then
   echo " "
   echo " "
   echo "  !!!!! btape-changer test failed!!! !!!!! "
   echo "  !!!!! btape-changer 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
yes
quit
END_OF_DATA
else
  $bin/btape -c bin/bareos-sd.conf Drive-0 <<END_OF_DATA >${cwd}/tmp/log2.out 2>&1
test
yes
quit
END_OF_DATA
fi

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