#!/bin/sh
################################################################
#
#  [# Edit, Date, User, Module #]
#
#  test-script for monopoly-template
#
here=`pwd`
if test $? -ne 0 ; then exit 1; fi
tmp=/tmp/$$
mkdir $tmp
if test $? -ne 0 ; then exit 1; fi
cd $tmp
if test $? -ne 0 ; then exit 1; fi

fail()
{
	echo FAILED 1>&2
	cd $here
	chmod u+w `find $tmp -type d -print`
	rm -rf $tmp
	exit 1
}

pass()
{
	cd $here
	chmod u+w `find $tmp -type d -print`
	rm -rf $tmp
	exit 0
}

trap 'fail' 1 2 3 15

# find game file
gamefile=$here/game.data
if [ ! -r $gamefile ]; then
  gamefile=$here/baseline/game.data
  if [ ! -r $gamefile ]; then
    fail;
  fi
fi

###  Enter argument list for `monopoly' here ###
arglist='chkPlayerPtr'

cat > test.test 2>/dev/null << 'endOfSampleInput'

endOfSampleInput
if test $? -ne 0 ; then fail; fi

cat $gamefile test.test | /public/public/monopoly/diffpp > test.in
if test $? -ne 0 ; then fail; fi

cat > test.test 2>/dev/null << 'endOfExpectedOutput'
Nobody

Player
 Key Carter end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Get_out_of_jail_for_free end end 
 CardPtr Key <nil> end end 
end 

Player
 Key Reagan end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Go_to_jail end end 
 CardPtr Key Go_to_jail end end 
end 

Player
 Key Bush end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key <nil> end end 
 CardPtr Key Go_to_jail end end 
end 

Player
 Key Carter end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Get_out_of_jail_for_free end end 
 CardPtr Key <nil> end end 
end 

Player
 Key Bush end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key <nil> end end 
 CardPtr Key Go_to_jail end end 
end 

Player
 Key Carter end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Get_out_of_jail_for_free end end 
 CardPtr Key <nil> end end 
end 

Nobody

Player
 Key Reagan end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Go_to_jail end end 
 CardPtr Key Go_to_jail end end 
end 

Nobody
Nobody

Player
 Key Carter end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Get_out_of_jail_for_free end end 
 CardPtr Key <nil> end end 
end 

Player
 Key Carter end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Get_out_of_jail_for_free end end 
 CardPtr Key <nil> end end 
end 

Player
 Key Carter end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Get_out_of_jail_for_free end end 
 CardPtr Key <nil> end end 
end 

Player
 Key Clinton end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key <nil> end end 
 CardPtr Key Get_out_of_jail_for_free end end 
end 

Player
 Key Clinton end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key <nil> end end 
 CardPtr Key Get_out_of_jail_for_free end end 
end 

Player
 Key Reagan end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Go_to_jail end end 
 CardPtr Key Go_to_jail end end 
end 

Nobody

Player
 Key Carter end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Get_out_of_jail_for_free end end 
 CardPtr Key <nil> end end 
end 

Player
 Key Reagan end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Go_to_jail end end 
 CardPtr Key Go_to_jail end end 
end 

Player
 Key Carter end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Get_out_of_jail_for_free end end 
 CardPtr Key <nil> end end 
end 

Player
 Key Carter end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Get_out_of_jail_for_free end end 
 CardPtr Key <nil> end end 
end 

Player
 Key Reagan end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Go_to_jail end end 
 CardPtr Key Go_to_jail end end 
end 

Player
 Key Bush end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key <nil> end end 
 CardPtr Key Go_to_jail end end 
end 

Player
 Key Bush end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key <nil> end end 
 CardPtr Key Go_to_jail end end 
end 

Nobody

Player
 Key Carter end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Get_out_of_jail_for_free end end 
 CardPtr Key <nil> end end 
end 

Player
 Key Reagan end 
 Account 1000 end 
 SpacePtr Key GO end end 
 false
 CardPtr Key Go_to_jail end end 
 CardPtr Key Go_to_jail end end 
end 
endOfExpectedOutput
if test $? -ne 0 ; then fail; fi

cat $gamefile test.test | /public/public/monopoly/diffpp > test.ok
  
$here/monopoly $arglist < test.in | /public/public/monopoly/diffpp > test.out 2>/dev/null
if test $? -ne 0 ; then fail; fi

diff test.ok test.out
if test $? -ne 0 ; then fail; fi

# it probably worked
pass
