#!/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='chckSpacePtr'

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'
DeedSpace
 Key  p1a  end 
 DeedPtr  Key  p1a  end end 
end 

DeedSpace
 Key  p1b  end 
 DeedPtr  Key  p1b  end end 
end 

DeedSpace
 Key  s1  end 
 DeedPtr  Key  s1  end end 
end 

DeedSpace
 Key  p2a  end 
 DeedPtr  Key  p2a  end end 
end 

DeedSpace
 Key  p2b  end 
 DeedPtr  Key  p2b  end end 
end 

DeedSpace
 Key  p2c  end 
 DeedPtr  Key  p2c  end end 
end 

DeedSpace
 Key  p3a  end 
 DeedPtr  Key  p3a  end end 
end 

DeedSpace
 Key  u1  end 
 DeedPtr  Key  u1  end end 
end 

DeedSpace
 Key  p3b  end 
 DeedPtr  Key  p3b  end end 
end 

DeedSpace
 Key  p3c  end 
 DeedPtr  Key  p3c  end end 
end 

DeedSpace
 Key  s2  end 
 DeedPtr  Key  s2  end end 
end 

DeedSpace
 Key  p4a  end 
 DeedPtr  Key  p4a  end end 
end 

DeedSpace
 Key  p4b  end 
 DeedPtr  Key  p4b  end end 
end 

DeedSpace
 Key  p4c  end 
 DeedPtr  Key  p4c  end end 
end 

DeedSpace
 Key  p5a  end 
 DeedPtr  Key  p5a  end end 
end 

DeedSpace
 Key  p5b  end 
 DeedPtr  Key  p5b  end end 
end 

DeedSpace
 Key  p5c  end 
 DeedPtr  Key  p5c  end end 
end 

DeedSpace
 Key  s3  end 
 DeedPtr  Key  s3  end end 
end 

DeedSpace
 Key  p6a  end 
 DeedPtr  Key  p6a  end end 
end 

DeedSpace
 Key  p6b  end 
 DeedPtr  Key  p6b  end end 
end 

DeedSpace
 Key  u2  end 
 DeedPtr  Key  u2  end end 
end 

DeedSpace
 Key  p6c  end 
 DeedPtr  Key  p6c  end end 
end 

DeedSpace
 Key  p7a  end 
 DeedPtr  Key  p7a  end end 
end 

DeedSpace
 Key  p7b  end 
 DeedPtr  Key  p7b  end end 
end 

DeedSpace
 Key  p7c  end 
 DeedPtr  Key  p7c  end end 
end 

DeedSpace
 Key  s4  end 
 DeedPtr  Key  s4  end end 
end 

DeedSpace
 Key  p8a  end 
 DeedPtr  Key  p8a  end end 
end 

DeedSpace
 Key  p8b  end 
 DeedPtr  Key  p8b  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
