#!/bin/csh -f
#
# A simplified 'Hello' test of TAO.  This is converted from the test delivered
# with TAO itself, such that this does not require an ACE/TAO installation.
# The full set of test files (to send to the outside user) are to be collected
# into one directory and sent together:
#
#     1) this script
#     2) $TAO_ROOT/tests/Hello/client
#     3) $TAO_ROOT/tests/Hello/server
#
# Successfully running this test should only require those three files
# and having the ACE/TAO libs in the user's LD_LIBRARY_PATH.
#

#
# Start Message
#
set giveMesg = 1
if ($giveMesg == 1) then
   echo ""
   echo "# You are running the 'Hello' test of TAO (The ACE ORB)."
   echo "# The output of this test should look something like:"
   echo "#"
   echo '# (nnnnn|nnnnn) - string returned <Hello there.>'
   echo '# (nnnnn|nnnnn) server - event loop finished'
   echo "#"
   echo "# Beginning test ..............................."
   echo ""
endif

#
# Init
#
unalias rm
set iorfile = server.ior
rm -f $iorfile
if !((-x ./server) && (-x ./client)) then
   echo "ERROR: test files seem to be missing.  Contact OPUS."
   exit 1
endif

#
# Start the server and then wait for the iorfile
#
(./server -o $iorfile &)

@ i=0
set foundIt = 0
while ($i < 5)
   sleep 1
   if (-e $iorfile) then
      set foundIt = 1
      @ i=5
   endif
   @ i++
end
if ($foundIt != 1) then
   echo "ERROR: cannot find file $iorfile"
   echo "Please kill the server process manually by 'kill'ing:"
   ps | grep "server -o $iorfile" | grep -v "grep server -o"
   exit 1
endif

#
# Start the client and see what happens
#
./client -k file://$iorfile

set junk = $status
if ($junk != 0) then
   echo "ERROR: client returned $junk"
   echo "Please kill the server process manually by 'kill'ing:"
   ps | grep "server -o $iorfile" | grep -v "grep server -o"
   exit 1
endif

# if we get here, the client exited normally and the server should be down too

sleep 1
set junk = (`ps | grep "server -o $iorfile" | grep -v "grep server -o"`)
if ($#junk == 0) then
   echo ""
   echo "Test finished successfully."
   echo ""
else
   echo ""
   echo "junk = ..${junk}.."
   echo "ERROR: there may still be a server running ..."
   echo "Please kill the server process manually by 'kill'ing:"
   ps | grep "server -o $iorfile" | grep -v "grep server -o"
   exit 1
endif

rm -f $iorfile
