#
# test suite for scriptt.sh 
#
# Version:  
#   2.0.0 17.07.2011/bs
#    - inital release of the new test suite
#
#

#### --------------------------------------
# init variables
#
  TEST_LOGDIR="/var/tmp/${__SCRIPTNAME}_testsuite.$$/"
  mkdir -p "${TEST_LOGDIR}"

  DUMP_DIR="${TEST_LOGDIR}/DUMP"
  mkdir -p "${DUMP_DIR}"

  TMP="${TEST_LOGDIR}/TMP"
  mkdir -p "${TMP}"
  
  export DUMP_DIR TMP
  
  TEST_LOGFILE="${TEST_LOGDIR}/${__SCRIPTNAME}.tests.$$.log"
  THISSCRIPT="$0"
   
  NO_OF_TESTS_DONE=0
  NO_OF_TESTS_SUCC=0
  NO_OF_TESTS_FAIL=0
  NO_OF_TESTS_SKIPPED=0
  
  TESTS_SKIPPED=""
  TESTS_FAILED=""
  TESTS_SUCCEDED=""
  TEST_ERROR_MSGS=""
  
  CURRENT_TEST="${NOT_PROCESSED_PARAMETER}"


#### --------------------------------------
## Test sub routines
##
LogTestMsg() {
  typeset THISMSG="[$(date +"%d.%m.%Y %H:%M:%S") scriptt test suite] $*"
  echo "${THISMSG}" >>"${TEST_LOGFILE}"
  echo "${THISMSG}"
 }

LogTestErrorMsg() {
  LogTestMsg "ERROR: ${THISMSG}!"
 }

Testdie() {
  typeset THISRC=$1
  [ $# -ne 0 ] && shift
  typeset THISMSG="$*"
  if [ "${THISMSG}"x != ""x ] ; then
    [ "${THISRC}"x = "0"x ] && LogTestMsg "${THISMSG}" || LogTestErrorMsg "${THISMSG}"
  fi
  die ${THISRC}
}

Process_Test_Results() {
  if [ $1 = 0 ] ; then
    TESTRESULT=0 
    LogTestMsg "  The test \"${CURRENT_TEST}\" succeeded."
  else
   TESTRESULT=1
   LogTestMsg "  The test \"${CURRENT_TEST}\" failed; The return code of the script is ${CURRENT_TEST_RC}"
   LogTestMsg "  The logfile for this test is \"${CURRENT_TEST_LOGFILE}\" "
   echo "Output is: 
${OUTPUT}
 "
  fi     

# remove temporary files   
  for i in $( grep "RUNTIME INFO: Writing the PID" "${CURRENT_TEST_LOGFILE}" 2>/dev/null | cut -f8 -d " " ) ; do rm  /tmp/scriptt*${i}* 2>/dev/null; done
  for i in $( grep "RUNTIME INFO: Writing the PID" "${TEST_LOGDIR}//${CURRENT_TEST}.out" 2>/dev/null | cut -f8 -d " " ) ; do rm  /tmp/scriptt*${i}* 2>/dev/null; done

}

Update_Test_Summary() {

  typeset CURRENT_TEST="$1"
  typeset CURRENT_TEST_RESULT=$2
  shift 2

  [ $# -gt 2 ] && shift
  typeset CURRENT_ERROR_MESSAGE="$*"
  
  (( NO_OF_TESTS_DONE = NO_OF_TESTS_DONE + 1 ))
  if [ ${CURRENT_TEST_RESULT} = 0 ] ; then
    (( NO_OF_TESTS_SUCC = NO_OF_TESTS_SUCC + 1 ))
    TESTS_SUCCEDED="${TESTS_SUCCEDED} ${CURRENT_TEST}"
  else  
    (( NO_OF_TESTS_FAIL = NO_OF_TESTS_FAIL + 1 ))
    TESTS_FAILED="${TESTS_FAILED} ${CURRENT_TEST}"
    if [ "${CURRENT_ERROR_MESSAGE}"x != ""x ] ; then
      TEST_ERROR_MSGS="${TEST_ERROR_MSGS}
${CURRENT_ERROR_MESSAGE}"    
    fi
  fi
}

function TEST_SIGNAL_HANDLER {
  typeset THISRC=$1
  typeset ACTION=$2

  case ${ACTION} in
    quiet )
      :
      ;;
    * )
     echo ${__TRAP_SIGNAL}  ${INTERRUPTED_FUNCTION}
    ;;
  esac
  
  return ${THISRC}
}

function TEST_FUNC_001 {
  typeset __FUNCTION="TEST_FUNC_001";   ${__FUNCTION_INIT} ;  
  kill $1 $$
}


#### --------------------------------------
## function tests
##

function function_tests {
  typeset THISRC=0
  
  sourceString="autobahn12schiene"
  pos="7"
  length="4"
  expectedResult="hn12"
  LogMsg "Calling \"substr\" with ${sourceString}  ${pos} ${length}"
  resultString=$( substr ${sourceString}  ${pos} ${length} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi
  

#               123456789 1234567             
  sourceString="autobahn12schiene"
  pos="1"
  length="3"
  expectedResult="aut"
  LogMsg "Calling \"substr\" with ${sourceString}  ${pos} ${length}"
  resultString=$( substr ${sourceString}  ${pos} ${length} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

#               123456789 1234567             
  sourceString="autobahn12schiene"
  pos="15"
  length="3"
  expectedResult="ene"
  LogMsg "Calling \"substr\" with ${sourceString}  ${pos} ${length}"
  resultString=$( substr ${sourceString}  ${pos} ${length} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

#               123456789 1234567             
  sourceString="autobahn12schiene"
  pos="15"
  length="7"
  expectedResult="ene"
  LogMsg "Calling \"substr\" with ${sourceString}  ${pos} ${length}"
  resultString=$( substr ${sourceString}  ${pos} ${length} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

#               123456789 1234567             
  sourceString="autobahn12schiene"
  pos="1"
  length="17"
  expectedResult="autobahn12schiene"
  LogMsg "Calling \"substr\" with ${sourceString}  ${pos} ${length}"
  resultString=$( substr ${sourceString}  ${pos} ${length} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


#               123456789 1234567             
  sourceString="autobahn12schiene"
  pos="20"
  length="17"
  expectedResult=""
  LogMsg "Calling \"substr\" with ${sourceString}  ${pos} ${length}"
  resultString=$( substr ${sourceString} ${pos} ${length} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


#               123456789 123456789 12345
  sourceString="autobahn12auto12schiene12"
  searchString="auto"
  expectedResult="1"
  LogMsg "Calling \"pos\" with \"${searchString}\" \"${sourceString}\" "
  pos ${searchString}  ${sourceString} 
  result=$? 
  LogMsg "   The result is        \"${result}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${result}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

#               123456789 123456789 12345
  sourceString="autobahn12auto12schiene12"
  searchString="12schiene"
  expectedResult="15"
  LogMsg "Calling \"pos\" with \"${searchString}\" \"${sourceString}\" "
  pos ${searchString}  ${sourceString} 
  result=$? 
  LogMsg "   The result is        \"${result}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${result}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

#               123456789 123456789 12345
  sourceString="autobahn12auto12schiene12"
  searchString="auto12"
  expectedResult="11"
  LogMsg "Calling \"pos\" with \"${searchString}\" \"${sourceString}\" "
  pos ${searchString}  ${sourceString} 
  result=$? 
  LogMsg "   The result is        \"${result}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${result}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

#               123456789 123456789 12345
  sourceString="autobahn12auto12schiene12"
  searchString="auto"
  expectedResult="1"
  LogMsg "Calling \"pos\" with \"${searchString}\" \"${sourceString}\" "
  pos ${searchString}  ${sourceString} 
  result=$? 
  LogMsg "   The result is        \"${result}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${result}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


#               123456789 123456789 12345
  sourceString="autobahn12auto12schiene12"
  searchString="autobahnX"
  expectedResult="0"
  LogMsg "Calling \"pos\" with \"${searchString}\" \"${sourceString}\" "
  pos ${searchString}  ${sourceString} 
  result=$? 
  LogMsg "   The result is        \"${result}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${result}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

#               123456789 123456789 12345
  sourceString="autobahn12auto12schiene12"
  searchString="12schiene"
  expectedResult="15"
  LogMsg "Calling \"pos\" with \"${searchString}\" \"${sourceString}\" "
  pos ${searchString}  ${sourceString} 
  result=$? 
  LogMsg "   The result is        \"${result}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${result}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

#               123456789 123456789 12345
  sourceString="autobahn12auto12schiene12"
  searchString="schiene12"
  expectedResult="17"
  LogMsg "Calling \"pos\" with \"${searchString}\" \"${sourceString}\" "
  pos ${searchString}  ${sourceString} 
  result=$? 
  LogMsg "   The result is        \"${result}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${result}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


#               123456789 123456789 12345
  sourceString="autobahn12auto12schiene12"
  searchString="auto"
  expectedResult="11"
  LogMsg "Calling \"lastpos\" with \"${searchString}\" \"${sourceString}\" "
  lastpos ${searchString}  ${sourceString} 
  result=$? 
  LogMsg "   The result is        \"${result}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${result}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


#               123456789 1234567             
  sourceString="autobahn12schiene"
  searchString="ene"
  expectedResult="15"
  LogMsg "Calling \"lastpos\" with \"${searchString}\" \"${sourceString}\" "
  lastpos ${searchString}  ${sourceString} 
  result=$? 
  LogMsg "   The result is        \"${result}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${result}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

#               123456789 1234567             
  sourceString="autobahn12schiene"
  searchString="12"
  expectedResult="9"
  LogMsg "Calling \"lastpos\" with \"${searchString}\" \"${sourceString}\" "
  lastpos ${searchString}  ${sourceString} 
  result=$? 
  LogMsg "   The result is        \"${result}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${result}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  testNumber="4"
  LogMsg "Calling \"isNumber\" with ${testNumber} "
  isNumber ${testNumber} ; TESTRC=$?
  LogMsg "   The result is        ${TESTRC}"
  LogMsg "   The result should be 0"
  if [ ${TESTRC} != 0 ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

  testNumber="4.5"
  LogMsg "Calling \"isNumber\" with ${testNumber} "
  isNumber ${testNumber}  ; TESTRC=$?
  LogMsg "   The result is        ${TESTRC}"
  LogMsg "   The result should be 1"
  if [ ${TESTRC} != 1 ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

  testNumber="4a"
  LogMsg "Calling \"isNumber\" with ${testNumber} "
  isNumber ${testNumber} ; TESTRC=$?
  LogMsg "   The result is        ${TESTRC}"
  LogMsg "   The result should be 1"
  if [ ${TESTRC} != 1 ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

  testNumber="xy"
  LogMsg "Calling \"isNumber\" with ${testNumber} "
  isNumber ${testNumber} ; TESTRC=$?
  LogMsg "   The result is        ${TESTRC}"
  LogMsg "   The result should be 1"
  if [ ${TESTRC} != 1 ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

#               123456789 1234567             
  sourceString="autobahn12schiene"
  expectedResult="AUTOBAHN12SCHIENE"
  LogMsg "Calling \"toUppercase\" with \"${sourceString}\" "
  resultString=$( toUppercase  ${sourceString} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


#               123456789 1234567             
  sourceString="AUTOBAHN12SCHiene"
  expectedResult="autobahn12schiene"
  LogMsg "Calling \"toLowercase\" with \"${sourceString}\" "
  resultString=$( toLowercase  ${sourceString} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi



  sourceString="555"
  expectedResult="1000101011"
  LogMsg "Calling \"ConvertToBinary\" with \"${sourceString}\" "
  resultString=$( ConvertToBinary  ${sourceString} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  sourceString="255"
  expectedResult="11111111"
  LogMsg "Calling \"ConvertToBinary\" with \"${sourceString}\" "
  resultString=$( ConvertToBinary  ${sourceString} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  sourceString="0"
  expectedResult="0"
  LogMsg "Calling \"ConvertToBinary\" with \"${sourceString}\" "
  resultString=$( ConvertToBinary  ${sourceString} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi



  sourceString="555"
  expectedResult="22b"
  LogMsg "Calling \"ConvertToHex\" with \"${sourceString}\" "
  resultString=$( ConvertToHex  ${sourceString} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  sourceString="255"
  expectedResult="ff"
  LogMsg "Calling \"ConvertToHex\" with \"${sourceString}\" "
  resultString=$( ConvertToHex  ${sourceString} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  sourceString="0"
  expectedResult="0"
  LogMsg "Calling \"ConvertToHex\" with \"${sourceString}\" "
  resultString=$( ConvertToHex  ${sourceString} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi



  sourceString="555"
  expectedResult="1053"
  LogMsg "Calling \"ConvertToOctal\" with \"${sourceString}\" "
  resultString=$( ConvertToOctal  ${sourceString} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  sourceString="255"
  expectedResult="377"
  LogMsg "Calling \"ConvertToOctal\" with \"${sourceString}\" "
  resultString=$( ConvertToOctal  ${sourceString} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  sourceString="0"
  expectedResult=""
  LogMsg "Calling \"ConvertToOctal\" with \"${sourceString}\" "
  resultString=$( ConvertToOctal  ${sourceString} )
  LogMsg "   The result is        \"${resultString}\" "
  LogMsg "   The result should be \"${expectedResult}\" "
  if [ "${resultString}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi



  sourceString="aaa12345bbbb"
  oldSubstr="12345"
  newSubstr="ZZZZZ"
  expectedResult="aaaZZZZZbbbb"
  LogMsg "Calling \"replacestr\" with ${sourceString} ${oldSubstr} ${newSubstr}"
  replacestr ${sourceString} ${oldSubstr} ${newSubstr} resultvar
  THISRC=$?
  LogMsg "    The result is         \"${resultvar}\" "
  LogMsg "    The result should be  \"${expectedResult}\" "
  if [ "${resultvar}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  
  sourceString="aaa12345bbbb"
  oldSubstr="12345"
  newSubstr="ZZZZZ"
  expectedResult="aaaZZZZZbbbb"
  LogMsg "Calling \"replacestr\" with ${sourceString} ${oldSubstr} ${newSubstr}"
  resultvar=$(replacestr ${sourceString} ${oldSubstr} ${newSubstr} )
  THISRC=$?
  LogMsg "    The result is         \"${resultvar}\" "
  LogMsg "    The result should be  \"${expectedResult}\" "
  LogMsg "    The RC is ${THISRC}"
  if [ "${resultvar}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  sourceString="aaa12345bbbb12345"
  oldSubstr="12345"
  newSubstr="ZZZZZ"
  expectedResult="aaaZZZZZbbbb12345"
  LogMsg "Calling \"replacestr\" with ${sourceString} ${oldSubstr} ${newSubstr}"
  replacestr ${sourceString} ${oldSubstr} ${newSubstr} resultvar
  THISRC=$?
  LogMsg "    The result is         \"${resultvar}\" "
  LogMsg "    The result should be  \"${expectedResult}\" "
  LogMsg "    The RC is ${THISRC}"
  if [ "${resultvar}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi
  
  sourceString="aaa12345bbbb12345"
  oldSubstr="12345"
  newSubstr="ZZZZZ"
  expectedResult="aaaZZZZZbbbb12345"
  LogMsg "Calling \"replacestr\" with ${sourceString} ${oldSubstr} ${newSubstr}"
  resultvar=$(replacestr ${sourceString} ${oldSubstr} ${newSubstr} )
  THISRC=$?
  LogMsg "    The result is         \"${resultvar}\" "
  LogMsg "    The result should be  \"${expectedResult}\" "
  LogMsg "    The RC is ${THISRC}"
  if [ "${resultvar}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

  sourceString="aaa12345bbbb"
  oldSubstr="aaa"  
  newSubstr="ZZZ"
  expectedResult="ZZZ12345bbbb"
  LogMsg "Calling \"replacestr\" with ${sourceString} ${oldSubstr} ${newSubstr}"
  replacestr ${sourceString} ${oldSubstr} ${newSubstr} resultvar
  THISRC=$?
  LogMsg "    The result is         \"${resultvar}\" "
  LogMsg "    The result should be  \"${expectedResult}\" "
  LogMsg "    The RC is ${THISRC}"
  if [ "${resultvar}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi
  

  sourceString="aaa12345bbbb"
  oldSubstr="bbbb"
  newSubstr="ZZZZ"
  expectedResult="aaa12345ZZZZ"
  LogMsg "Calling \"replacestr\" with ${sourceString} ${oldSubstr} ${newSubstr}"
  replacestr ${sourceString} ${oldSubstr} ${newSubstr} resultvar
  THISRC=$?
  LogMsg "    The result is         \"${resultvar}\" "
  LogMsg "    The result should be  \"${expectedResult}\" "
  LogMsg "    The RC is ${THISRC}"
  if [ "${resultvar}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  sourceString="aaa12345bbbb"
  oldSubstr="aaa"  
  newSubstr=""
  expectedResult="12345bbbb"
  LogMsg "Calling \"replacestr\" with ${sourceString} ${oldSubstr} ${newSubstr}"
  resultvar=$(replacestr ${sourceString} ${oldSubstr} ${newSubstr} )
  THISRC=$?
  LogMsg "    The result is         \"${resultvar}\" "
  LogMsg "    The result should be  \"${expectedResult}\" "
  LogMsg "    The RC is ${THISRC}"
  if [ "${resultvar}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  sourceString="aaa12345bbbb"
  oldSubstr="123"  
  newSubstr=""
  expectedResult="aaa45bbbb"
  LogMsg "Calling \"replacestr\" with ${sourceString} ${oldSubstr} ${newSubstr}"
  resultvar=$(replacestr ${sourceString} ${oldSubstr} ${newSubstr} )
  THISRC=$?
  LogMsg "    The result is         \"${resultvar}\" "
  LogMsg "    The result should be  \"${expectedResult}\" "
  LogMsg "    The RC is ${THISRC}"
  if [ "${resultvar}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi


  sourceString="aaa12345bbbb"
  oldSubstr="aa"  
  newSubstr=""
  expectedResult="a12345bbbb"
  LogMsg "Calling \"replacestr\" with ${sourceString} ${oldSubstr} ${newSubstr}"
  resultvar=$(replacestr ${sourceString} ${oldSubstr} ${newSubstr} )
  THISRC=$?
  LogMsg "    The result is         \"${resultvar}\" "
  LogMsg "    The result should be  \"${expectedResult}\" "
  LogMsg "    The RC is ${THISRC}"
  if [ "${resultvar}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi
  

  sourceString="aaa12345bbbb"
  oldSubstr="bb"  
  newSubstr=""
  expectedResult="aaa12345bb"
  LogMsg "Calling \"replacestr\" with ${sourceString} ${oldSubstr} ${newSubstr}"
  resultvar=$(replacestr ${sourceString} ${oldSubstr} ${newSubstr} )
  THISRC=$?

  LogMsg "    The result is         \"${resultvar}\" "
  LogMsg "    The result should be  \"${expectedResult}\" "
  LogMsg "    The RC is ${THISRC}"
  if [ "${resultvar}"x != "${expectedResult}"x ] ; then
    (( THISRC = THISRC + 1 ))
   LogMsg "   ERROR: Test failed"
  fi

  
  LogMsg "Calling \"UserIsRoot\" ..."
  UserIsRoot
  [ $? -eq 0 ] && LogMsg "The user is root" || LogMsg "The user is NOT root"

  testUserID="root"
  LogMsg "Calling \"UserIs\" with \"${testUserID}\" "
  UserIs ${testUserID}
  LogMsg "   The result is $?"

  LogMsg "Calling \"GetCurrentUID\"  "
  THIS_UID=$( GetCurrentUID )
  LogMsg "   The result is ${THIS_UID}"

  testUID="65534"
  LogMsg "Calling \"GetUserName\" with \"${testUID}\"  "
  GetUserName ${testUID}
  LogMsg "   The result is \"${__USERNAME}\""

  testUID="0"
  LogMsg "Calling \"GetUserName\" with \"${testUID}\"  "
  GetUserName ${testUID}
  LogMsg "   The result is \"${__USERNAME}\""


  testUsername="nobody"
  LogMsg "Calling \"GetU_ID\" with \"${testUsername}\"  "
  GetUID ${testUsername}
  LogMsg "   The result is \"${__USER_ID}\""

  testUsername="avahi"
  LogMsg "Calling \"GetU_ID\" with \"${testUsername}\"  "
  GetUID ${testUsername}
  LogMsg "   The result is \"${__USER_ID}\""

  testUsername="root"
  LogMsg "Calling \"GetUID\" with \"${testUsername}\"  "
  GetUID ${testUsername}
  LogMsg "   The result is \"${__USER_ID}\""

  testUsername="uucp"
  LogMsg "Calling \"GetUID\" with \"${testUsername}\"  "
  GetUID ${testUsername}
  LogMsg "   The result is \"${__USER_ID}\""

  
  RAND_NUMBER1=$( rand ) ; RAND_RC1=$?
  LogMsg "The random number returned by rand() is ${RAND_NUMBER1}; the RC of rand() is ${RAND_RC1}"

  RAND_NUMBER2=$( rand ) ; RAND_RC2=$?
  LogMsg "The random number returned by rand() is ${RAND_NUMBER2}; the RC of rand() is ${RAND_RC2}"

  if [ "${RAND_NUMBER1}"x = "${RAND_NUMBER2}"x ] ; then
    LogMsg "The rand() function does not work."
    (( THISRC = THISRC + 1 ))
  else
    LogMsg "The rand() function seems to work."
  fi  

  return ${THISRC}
}

#### --------------------------------------
## Test main routine
##

  THIS_TEST_RC=0
  
  case ${CURRENT_TEST} in

    Parameter_quiet_test )
      :
      ;;

    long_parameter_test )
      echo "${__USER_RESPONSE_IS}"
      ;;

    plus_parameter_test )
      echo "${__USER_RESPONSE_IS}"
      ;;
      
    usr1_signal_handler_test_001 )
      STOP=0
      __SIGNAL_SIGUSR1_FUNCTION="TEST_SIGNAL_HANDLER 0"
      kill -USR1 $$
      ;;

    usr1_signal_handler_test_002 )
      __SIGNAL_SIGUSR1_FUNCTION="TEST_SIGNAL_HANDLER 0"
      TEST_FUNC_001 "-USR1"
      ;;

    usr2_signal_handler_test_001 )
      __SIGNAL_SIGUSR2_FUNCTION="TEST_SIGNAL_HANDLER 0"
      kill -USR2 $$
      ;;

    usr2_signal_handler_test_002 )
      __SIGNAL_SIGUSR2_FUNCTION="TEST_SIGNAL_HANDLER 0"
      TEST_FUNC_001 "-USR2"
      ;;

    hup_signal_handler_test_001 )
      __SIGNAL_SIGHUP_FUNCTION="TEST_SIGNAL_HANDLER 1"
      kill -HUP $$
      ;;

    hup_signal_handler_test_002 )
      __SIGNAL_SIGHUP_FUNCTION="TEST_SIGNAL_HANDLER 1"
      TEST_FUNC_001 "-HUP"
      ;;

    hup_signal_handler_test_003 )
      __VERBOSE_MODE=${__FALSE}
      __SIGNAL_SIGHUP_FUNCTION="TEST_SIGNAL_HANDLER 0 quiet"
      kill -HUP $$
      if [ "${__VERBOSE_MODE}"x = ${__TRUE}x ] ; then
        echo "ok"
        __VERBOSE_MODE=${__FALSE}
      else
        echo "error"
      fi
      ;;

    int_signal_handler_test_001 )
      __USER_BREAK_ALLOWED=${__FALSE}
      __SIGNAL_SIGINT_FUNCTION="TEST_SIGNAL_HANDLER 1"
      kill -INT $$
      ;;

    int_signal_handler_test_002 )
      __USER_BREAK_ALLOWED=${__FALSE}
      __SIGNAL_SIGINT_FUNCTION="TEST_SIGNAL_HANDLER 0"
      TEST_FUNC_001 "-INT"
      ;;

    int_signal_handler_test_003 )
      __USER_BREAK_ALLOWED=${__TRUE}
      __SIGNAL_SIGINT_FUNCTION="TEST_SIGNAL_HANDLER 0"
      kill -INT $$
      ;;

    term_signal_handler_test_001 )
      __SIGNAL_SIGTERM_FUNCTION="TEST_SIGNAL_HANDLER 0"
      kill -TERM $$
      ;;

    term_signal_handler_test_002 )
      __SIGNAL_SIGTERM_FUNCTION="TEST_SIGNAL_HANDLER 0"
      TEST_FUNC_001 "-TERM"
      ;;

    quit_signal_handler_test_001 )
      __SIGNAL_SIGQUIT_FUNCTION="TEST_SIGNAL_HANDLER 0"
      kill -QUIT $$
      ;;

    quit_signal_handler_test_002 )
      __SIGNAL_SIGQUIT_FUNCTION="TEST_SIGNAL_HANDLER 0"
      TEST_FUNC_001 "-QUIT"
      ;;
 
    syntax_error_test_001 | syntax_error_test_002 | syntax_error_test_003 )
       
#      TT="test=\$\{xxxx"
#      eval $TT
      exit
      ;;
    
    syntax_error_test_004 )
      INCLUDE_TEST_FILE="/tmp/${__SCRIPTNAME}_include"    
      includeScript "${INCLUDE_TEST_FILE}"
      ;;
      
    rbac_test_001 | tee_test_001 )
      :
      ;;

    cleanup_test001 )

      function TEST_EXIT_ROUTINE1 {
        echo "OK: exit routine called"
        [ -d "${TEST_TMP_DIR}" ] && echo "OK: exit routine: temp dir still exists" || echo "ERROR: exit routine: temp dir does not exist anymore"
        [ -f "${TEST_TMP_FILE}" ] && echo "OK: exit routine: temp file still exists"|| echo "ERROR: exit routine: temp file does not exist anymore"
      }

      function TEST_FINISH_ROUTINE1 {
        echo "OK: finish routine called"
        [ -d "${TEST_TMP_DIR}" ] && echo "ERROR: finish routine: temp dir still exists" || echo "OK: finish routine: temp dir does not exist anymore"
        [ -f "${TEST_TMP_FILE}" ] && echo "ERROR: finish routine: temp file still exists"|| echo "OK: finish routine: temp file does not exist anymore"
      }

      __EXITROUTINES="${__EXITROUTINES} TEST_EXIT_ROUTINE1"
      __FINISHROUTINES="${__FINISHROUTINES} TEST_FINISH_ROUTINE1"
      __LIST_OF_TMP_DIRS="${__LIST_OF_TMP_DIRS} ${TEST_TMP_DIR}"
      __LIST_OF_TMP_FILES="${__LIST_OF_TMP_FILES} ${TEST_TMP_FILE}"

      mkdir "${TEST_TMP_DIR}"
      touch "${TEST_TMP_FILE}"

      ;;
      
    cleanup_test002 )

      function TEST_EXIT_ROUTINE2 {
        echo "OK: exit routine called"
        [ -d "${TEST_TMP_DIR}" ] && echo "OK: exit routine: temp dir still exists" || echo "ERROR: exit routine: temp dir does not exist anymore"
        [ -f "${TEST_TMP_FILE}" ] && echo "OK: exit routine: temp file still exists"|| echo "ERROR: exit routine: temp file does not exist anymore"
      }

      function TEST_FINISH_ROUTINE2 {
        echo "OK: finish routine called"
        [ -d "${TEST_TMP_DIR}" ] && echo "OK: finish routine: temp dir still exists" || echo "ERROR: finish routine: temp dir does not exist anymore"
        [ -f "${TEST_TMP_FILE}" ] && echo "OK: finish routine: temp file still exists"|| echo "ERROR: finish routine: temp file does not exist anymore"
      }

      __EXITROUTINES="${__EXITROUTINES} TEST_EXIT_ROUTINE2"
      __FINISHROUTINES="${__FINISHROUTINES} TEST_FINISH_ROUTINE2"
      __LIST_OF_TMP_DIRS="${__LIST_OF_TMP_DIRS} ${TEST_TMP_DIR}"
      __LIST_OF_TMP_FILES="${__LIST_OF_TMP_FILES} ${TEST_TMP_FILE}"

      mkdir "${TEST_TMP_DIR}"
      touch "${TEST_TMP_FILE}"
      
#      test="${xxxx"
      eval "a=\${++}; echo $a "
      exit 0
      ;;

    cleanup_test003 )

      function TEST_EXIT_ROUTINE1 {
        echo "OK: exit routine called"
        [ -d "${TEST_TMP_DIR}" ] && echo "OK: exit routine: temp dir still exists" || echo "ERROR: exit routine: temp dir does not exist anymore"
        [ -f "${TEST_TMP_FILE}" ] && echo "OK: exit routine: temp file still exists"|| echo "ERROR: exit routine: temp file does not exist anymore"
      }

      function TEST_FINISH_ROUTINE1 {
        echo "OK: finish routine called"
        [ -d "${TEST_TMP_DIR}" ] && echo "ERROR: finish routine: temp dir still exists" || echo "OK: finish routine: temp dir does not exist anymore"
        [ -f "${TEST_TMP_FILE}" ] && echo "ERROR: finish routine: temp file still exists"|| echo "OK: finish routine: temp file does not exist anymore"
      }

      __EXITROUTINES="${__EXITROUTINES} TEST_EXIT_ROUTINE1"
      __FINISHROUTINES="${__FINISHROUTINES} TEST_FINISH_ROUTINE1"
      __LIST_OF_TMP_DIRS="${__LIST_OF_TMP_DIRS} ${TEST_TMP_DIR}"
      __LIST_OF_TMP_FILES="${__LIST_OF_TMP_FILES} ${TEST_TMP_FILE}"

      mkdir "${TEST_TMP_DIR}"
      touch "${TEST_TMP_FILE}"
      __CLEANUP_ON_ERROR=${__TRUE}
#      test="${xxxx"
      eval "a=\${++}; echo $a "
      
      ;;

    cleanup_test004 )

      function TEST_EXIT_ROUTINE1 {
        echo "OK: exit routine called"
        [ -d "${TEST_TMP_DIR}" ] && echo "OK: exit routine: temp dir still exists" || echo "ERROR: exit routine: temp dir does not exist anymore"
        [ -f "${TEST_TMP_FILE}" ] && echo "OK: exit routine: temp file still exists"|| echo "ERROR: exit routine: temp file does not exist anymore"
      }

      function TEST_FINISH_ROUTINE1 {
        echo "OK: finish routine called"
        [ -d "${TEST_TMP_DIR}" ] && echo "ERROR: finish routine: temp dir still exists" || echo "OK: finish routine: temp dir does not exist anymore"
        [ -f "${TEST_TMP_FILE}" ] && echo "ERROR: finish routine: temp file still exists"|| echo "OK: finish routine: temp file does not exist anymore"
      }

      __EXITROUTINES="${__EXITROUTINES} TEST_EXIT_ROUTINE1"
      __FINISHROUTINES="${__FINISHROUTINES} TEST_FINISH_ROUTINE1"
      __LIST_OF_TMP_DIRS="${__LIST_OF_TMP_DIRS} ${TEST_TMP_DIR}"
      __LIST_OF_TMP_FILES="${__LIST_OF_TMP_FILES} ${TEST_TMP_FILE}"

      mkdir "${TEST_TMP_DIR}"
      touch "${TEST_TMP_FILE}"
      SetHousekeeping ${__FALSE}
      ;;

    configfile_test001 )
      echo "${TESTVAR001}"
      ;;

    function_tests )
      function_tests
      die $?
      ;;

# no parameter -- inital call ; init the data

    * )  :
      ;;
    
  esac

#### --------------------------------------
## exit now if in a sub test
##

  if [ "${CURRENT_TEST}"x != ""x ] ; then
    Testdie ${THIS_TEST_RC}
  fi

#### --------------------------------------
## check the prerequisites
##

  LogTestMsg "Starting the test suite for \"${__SCRIPTNAME}\" "
  LogTestMsg "The shell used is compatible to ksh${__KSH_VERSION}"
  LogTestMsg "  Using the log directory \"${TEST_LOGDIR}\" "
   [ ! -d "${TEST_LOGDIR}" ] && Testdie 5 "The directory \"${TEST_LOGDIR}\" does not exist (and can not be created)"
  [ ! -r "${__SCRIPTNAME}" ] && Testdie 7 "Can not read the file \"${__SCRIPTNAME}\" "
  [ ! -x "${__SCRIPTNAME}" ] && Testdie 9 "Can not execute the file \"${__SCRIPTNAME}\" "
  touch "${TEST_LOGFILE}" || Testdie 11 "Can not write to the log file \"${TEST_LOGFILE}\" "
  [ ${__ONLY_ONCE} != ${__FALSE} ] && Testdie 13 "ONLY_ONCE must be FALSE for this test suite"
  
  
#### --------------------------------------

# do the tests

#### --------------------------------------
## test the parameter -q
##

  CURRENT_TEST="Parameter_quiet_test"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (Parameter -q) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = ""x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}
  
  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test the long parameter support
##
  CURRENT_TEST="long_parameter_test"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (test long parameter support) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} --yes ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} --yes  ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = "y"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"



#### --------------------------------------
## test the "+" parameter support
##
  CURRENT_TEST="plus_parameter_test"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (test \"+{switch}\" parameter support) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -y +y -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(          ${THISSCRIPT} -y +y -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = ""x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the user signal handler for USR1 in main
##

  CURRENT_TEST="usr1_signal_handler_test_001"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGUSR1 while in the main function) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = "SIGUSR1 main"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the user signal handler for USR1 in a function
##

  CURRENT_TEST="usr1_signal_handler_test_002"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGUSR1 while in a function) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = "SIGUSR1 TEST_FUNC_001"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test the user signal handler for USR2 in main
##

  CURRENT_TEST="usr2_signal_handler_test_001"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGUSR2 while in the main function) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = "SIGUSR2 main"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the user signal handler for USR2 in a function
##

  CURRENT_TEST="usr2_signal_handler_test_002"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGUSR2 while in a function) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = "SIGUSR2 TEST_FUNC_001"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the user signal handler for HUP in main
##

  CURRENT_TEST="hup_signal_handler_test_001"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGHUP while in the main function) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = "SIGHUP main"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the user signal handler for HUP in a function
##

  CURRENT_TEST="hup_signal_handler_test_002"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGHUP while in a function) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = "SIGHUP TEST_FUNC_001"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the user signal handler for HUP with a return code not equal zero
##
  CURRENT_TEST="hup_signal_handler_test_003"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGHUP handler with non-zero returncode) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = "ok"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}  

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test the user signal handler for INT in main
##

  CURRENT_TEST="int_signal_handler_test_001"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGINT while in the main function with BREAK disabled) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = "SIGINT main"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the user signal handler for INT in a function
##

  CURRENT_TEST="int_signal_handler_test_002"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGINT while in a function with BREAK disabled) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} "
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = "SIGINT TEST_FUNC_001"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the user signal handler for INT in main with BREAK=TRUE
##

  CURRENT_TEST="int_signal_handler_test_003"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGINT while in a function with BREAK enabled) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 252 ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test the user signal handler for TERM in main
##

  CURRENT_TEST="term_signal_handler_test_001"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGTERM while in the main function) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 253 -a "${OUTPUT}"x = "SIGTERM main"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the user signal handler for TERM in a function
##

  CURRENT_TEST="term_signal_handler_test_002"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGTERM while in a function) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 253 -a "${OUTPUT}"x = "SIGTERM TEST_FUNC_001"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"



#### --------------------------------------
## test the user signal handler for QUIT in main
##

  CURRENT_TEST="quit_signal_handler_test_001"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGHUP while in the main function) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 251 -a "${OUTPUT}"x = "SIGQUIT main"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the user signal handler for TERM in a function
##

  CURRENT_TEST="quit_signal_handler_test_002"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (SIGHUP while in a function) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 251 -a "${OUTPUT}"x = "SIGQUIT TEST_FUNC_001"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test the behaviour in case of a syntax error
##

  CURRENT_TEST="syntax_error_test_001"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (create env var dump in case of an error) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v  -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v  -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} 2>&1 )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
  
# process the test result  
  TESTRESULT=0
  
  echo "${OUTPUT}" | grep 'WARNING: You should use the function "die" to end the program' >/dev/null
  [ $? -ne 0 ] && TESTRESULT=1
  echo "${OUTPUT}" | grep 'Saving the current environment variables in the file' >/dev/null
  [ $? -ne 0 ] && TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test the behaviour in case of a syntax error (create env var dump in a specific directory)
##

  CURRENT_TEST="syntax_error_test_002"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (create env var dump in case of an error in a specified directory) ..."

  DUMPDIR="${TEST_LOGDIR}/${__SCRIPTNAME}_dump.$$"
  mkdir -p "${DUMPDIR}"
  
  LogTestMsg "   CMD: __CREATE_DUMP=${DUMPDIR} ${THISSCRIPT} -v -v  -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        __CREATE_DUMP=${DUMPDIR} ${THISSCRIPT} -v -v  -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} 2>&1 )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
   
# process the test result  
  TESTRESULT=0
  [  ! -f "${DUMPDIR}/${__SCRIPTNAME}".envvars.* ] && TESTRESULT=1
  [ ! -f "${DUMPDIR}/${__SCRIPTNAME}".exported_envvars.* ] && TESTRESULT=1
  OUTPUT="$( ls -l "${DUMPDIR}" )"
  rm -r "${DUMPDIR}"
  Process_Test_Results ${TESTRESULT}  
  
  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the behaviour in case of a syntax error (suppress creating the env var dump)
##

  CURRENT_TEST="syntax_error_test_003"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (suppress creating the env var dump) ..."

  DUMPDIR="${TEST_LOGDIR}/${__SCRIPTNAME}_dump.$$"
  mkdir -p "${DUMPDIR}"

  LogTestMsg "   CMD: __CREATE_DUMP=${DUMPDIR} ; __DUMP_ALREADY_CREATED=${__TRUE} ${THISSCRIPT} -v -v  -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        __CREATE_DUMP=${DUMPDIR} ; __DUMP_ALREADY_CREATED=${__TRUE} ${THISSCRIPT} -v -v  -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} 2>&1 )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
   
# process the test result  
  TESTRESULT=0
  [  -f "${DUMPDIR}/${__SCRIPTNAME}".envvars.* ] && TESTRESULT=1
  [  -f "${DUMPDIR}/${__SCRIPTNAME}".exported_envvars.* ] && TESTRESULT=1
  OUTPUT="$( ls -l "${DUMPDIR}" )"
  rm -r "${DUMPDIR}"
  Process_Test_Results ${TESTRESULT} 

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test the error handling for syntax errors in include files
##
  CURRENT_TEST="syntax_error_test_004"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (syntax error while executing an include file) ..."

#  INCLUDE_TEST_FILE="${TEST_LOGDIR}/${__SCRIPTNAME}_include"

  INCLUDE_TEST_FILE="/tmp/${__SCRIPTNAME}_include"    
  touch "${INCLUDE_TEST_FILE}" && chmod 755 "${INCLUDE_TEST_FILE}" && cat  <<EOT >"${INCLUDE_TEST_FILE}"   
#

#test=\${xxx
exit 

EOT
  
  LogTestMsg "   CMD: ${THISSCRIPT} -v -v  -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
   
  echo "${OUTPUT}" | grep "Trap occurred inside of the include script \"${INCLUDE_TEST_FILE}\"" >/dev/null
  TESTRESULT=$?
  Process_Test_Results ${TESTRESULT}
  rm "${INCLUDE_TEST_FILE}" 2>/dev/null
  
  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the RBAC feature
##

  CURRENT_TEST="rbac_test_001"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (RBAC feature) ..."

  RBAC_TEST_FILE="${TEST_LOGDIR}/${__SCRIPTNAME}_rbac.$$"
  RBAC_TEST_MSG="RBAC feature works"
  touch "${RBAC_TEST_FILE}" && chmod 755 "${RBAC_TEST_FILE}" && cat  <<EOT >>"${RBAC_TEST_FILE}"   
#!/usr/bin/ksh  
if [ "\$*" = "${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}" ] ; then
  echo "${RBAC_TEST_MSG}"
else
  echo "RBAC test failed."
fi
EOT


  LogTestMsg "   CMD: export __RBAC_BINARY="${RBAC_TEST_FILE}" ; __USE_RBAC=${__TRUE} ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        export __RBAC_BINARY="${RBAC_TEST_FILE}" ; __USE_RBAC=${__TRUE} ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
   
# process the test result  
  [  ${CURRENT_TEST_RC} -eq 0 -a "${OUTPUT}"x = "${RBAC_TEST_MSG}"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## test the tee feature
##
  CURRENT_TEST="tee_test_001"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (Parameter -T) ..."

  TEE_TEST_FILE1="${TEST_LOGDIR}/${__SCRIPTNAME}_tee1.$$"
  TEE_TEST_FILE2="${TEST_LOGDIR}/${__SCRIPTNAME}_tee2.$$"
  
  touch "${TEE_TEST_FILE1}"  "${TEE_TEST_FILE2}" 

  LogTestMsg "   CMD: export __PPID= ; __TEE_OUTPUT_FILE=${TEE_TEST_FILE1} ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} -T ${CURRENT_TEST}"
  OUTPUT="$(        export __PPID= ; __TEE_OUTPUT_FILE=${TEE_TEST_FILE1} ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} -T ${CURRENT_TEST} 2>&1 )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
   
# process the test result  
  echo "${OUTPUT}" | grep -v "STDOUT and STDERR" | grep -v "^$" >"${TEE_TEST_FILE2}"
  echo "$( cat "${TEE_TEST_FILE1}" | grep -v "^$" )" >"${TEE_TEST_FILE1}"
  OUTPUT="$( diff -b "${TEE_TEST_FILE1}" "${TEE_TEST_FILE2}" )"
  TESTRESULT=$?
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test the house keeping  feature 001
##

  CURRENT_TEST="cleanup_test001"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (is house keeping working at all?) ..."

  export TEST_TMP_DIR="/tmp/${__SCRIPTNAME}_testdir"
  export TEST_TMP_FILE="/tmp/${__SCRIPTNAME}_testfile"
  rm -r "${TEST_TMP_DIR}" 2>/dev/null
  rm  "${TEST_TMP_FILE}" 2>/dev/null

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} 2>&1 )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
   
# process the test result  
  OK_COUNT="$( echo "${OUTPUT}" | grep "OK:"  | wc -l | tr -d " " )"
  [  "${OK_COUNT}"x = "6"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}
  rm -r "${TEST_TMP_DIR}" 2>/dev/null
  rm  "${TEST_TMP_FILE}" 2>/dev/null
   
  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test the house keeping  feature 002
##

  CURRENT_TEST="cleanup_test002"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (No cleanup after a syntax error) ..."

  export TEST_TMP_DIR="/tmp/${__SCRIPTNAME}_testdir"
  export TEST_TMP_FILE="/tmp/${__SCRIPTNAME}_testfile"
  rm -r "${TEST_TMP_DIR}" 2>/dev/null
  rm  "${TEST_TMP_FILE}" 2>/dev/null

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} 2>&1 )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
   
# process the test result  
  OK_COUNT="$( echo "${OUTPUT}" | grep "OK:"  | wc -l | tr -d " " )"
  [  "${OK_COUNT}"x = "0"x -a -d "${TEST_TMP_DIR}" -a -f "${TEST_TMP_FILE}"  ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}
  rm -r "${TEST_TMP_DIR}" 2>/dev/null
  rm  "${TEST_TMP_FILE}" 2>/dev/null
   
   Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test the house keeping  feature 003  (Test __CLEANUP_ON_ERROR)
##

  CURRENT_TEST="cleanup_test003"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (Test __CLEANUP_ON_ERROR) ..."

  export TEST_TMP_DIR="/tmp/${__SCRIPTNAME}_testdir"
  export TEST_TMP_FILE="/tmp/${__SCRIPTNAME}_testfile"
  rm -r "${TEST_TMP_DIR}" 2>/dev/null
  rm  "${TEST_TMP_FILE}" 2>/dev/null

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(          ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} 2>&1 )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
   
# process the test result  
  OK_COUNT="$( echo "${OUTPUT}" | grep "OK:"  | wc -l | tr -d " " )"
  [  "${OK_COUNT}"x = "6"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  rm -r "${TEST_TMP_DIR}" 2>/dev/null
  rm  "${TEST_TMP_FILE}" 2>/dev/null
   
   Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## testing user defined config files (Test usage of __CONFIG_FILE)
##
  CURRENT_TEST="configfile_test001"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (Test usage of __CONFIG_FILE) ..."

  TEST_CONFIG_FILE="${TEST_LOGDIR}/${__SCRIPTNAME}_config_test"
  rm  "${TEST_CONFIG_FILE}" 2>/dev/null

  echo  "TESTVAR001=ok" >"${TEST_CONFIG_FILE}"

  LogTestMsg "   CMD: CONFIG_FILE=${TEST_CONFIG_FILE} ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(          CONFIG_FILE=${TEST_CONFIG_FILE} ${THISSCRIPT} -v -v -q -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} 2>&1 )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
   
# process the test result  
  [ "${OUTPUT}"x = "ok"x ] && TESTRESULT=0 || TESTRESULT=1
  
  Process_Test_Results ${TESTRESULT}

#  rm  "${TEST_CONFIG_FILE}" 2>/dev/null
   
   Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test the house keeping  feature 004
##

  CURRENT_TEST="cleanup_test004"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (No cleanup after SetHousekeeping \${__FALSE}) ..."
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (No cleanup after SetHousekeeping \${__FALSE}) ..."

  export TEST_TMP_DIR="/tmp/${__SCRIPTNAME}_testdir"
  export TEST_TMP_FILE="/tmp/${__SCRIPTNAME}_testfile"
  rm -r "${TEST_TMP_DIR}" 2>/dev/null
  rm  "${TEST_TMP_FILE}" 2>/dev/null

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} 2>&1 )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
   
# process the test result  
  OK_COUNT="$( echo "${OUTPUT}" | grep "OK:"  | wc -l | tr -d " " )"
  [  "${OK_COUNT}"x = "0"x -a -d "${TEST_TMP_DIR}" -a -f "${TEST_TMP_FILE}"  ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}
  rm -r "${TEST_TMP_DIR}" 2>/dev/null
  rm  "${TEST_TMP_FILE}" 2>/dev/null
   
   Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"


#### --------------------------------------
## test general functions of the script
##

  CURRENT_TEST="function_tests"
  CURRENT_TEST_LOGFILE="${TEST_LOGDIR}/${CURRENT_TEST}.log"
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (general function tests) ..."
  LogTestMsg "Doing the test \"${CURRENT_TEST}\" (general function tests) ..."

  LogTestMsg "   CMD: ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST}"
  OUTPUT="$(        ${THISSCRIPT} -v -v -l ${CURRENT_TEST_LOGFILE} ${CURRENT_TEST} 2>&1 )" ;  CURRENT_TEST_RC=$?
  echo "${OUTPUT}" >"${TEST_LOGDIR}//${CURRENT_TEST}.out"
   
# process the test result  
  [  "${CURRENT_TEST_RC}"x = "0"x ] && TESTRESULT=0 || TESTRESULT=1
  Process_Test_Results ${TESTRESULT}

  Update_Test_Summary "${CURRENT_TEST}"  "${TESTRESULT}"

#### --------------------------------------
## write the test summary
##
  echo ""
  LogTestMsg "Test suite for \"${__SCRIPTNAME}\" done "
  LogTestMsg "The logs of the tests are in the directory \"${TEST_LOGDIR}\" "
  LogTestMsg "The test suite log file is \"${TEST_LOGFILE}\" "
  
  LogTestMsg "Test summaries"
  LogTestMsg "--------------"
  LogTestMsg "The shell used is compatible to ksh${__KSH_VERSION}"
  LogTestMsg "${NO_OF_TESTS_DONE} test(s) executed"
  LogTestMsg "${NO_OF_TESTS_SUCC} test(s) succeeded"
  LogTestMsg "${NO_OF_TESTS_FAIL} test(s) failed."
  LogTestMsg "${NO_OF_TESTS_SKIPPED} test(s) skipped."
  echo ""
  LogTestMsg "Tests succeeded are: ${TESTS_SUCCEDED}"
  echo ""
  [ ${NO_OF_TESTS_FAIL} != 0 ] && LogTestMsg "Tests failed are: ${TESTS_FAILED}"
  echo ""
  [ "${TEST_ERROR_MSGS}"x != ""x ]  && LogTestMsg  "Test error messages are:
${TEST_ERROR_MSGS}"

  echo ""
   if [ ${NO_OF_TESTS_SKIPPED} != 0 ] ; then
    LogTestMsg "Tests skipped are: ${TESTS_SKIPPED}"
  fi

#### --------------------------------------

  die 0
