#!/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

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

/public/public/monopoly/diffpp > test.in 2>/dev/null << 'endOfSampleInput'

Index
 TestObject1  1 Key a end end
 TestObject1  2 Key b end end
 TestObject1  3 Key a end end
 TestObject1  4 Key c end end
 TestObject1  5 Key a end end
 TestObject1  6 Key b end end
 TestObject1  7 Key c end end
 TestObject1  8 Key a end end
 TestObject1  9 Key hello end end
 TestObject1 10 Key a end end
 TestObject1 11 Key d end end
 TestObject1 12 Key hi end end
 TestObject1 13 Key c end end
 TestObject1 14 Key a end end
end

Index
 TestObject2  1 Key a end end
 TestObject2  2 Key b end end
 TestObject2  3 Key a end end
 TestObject2  4 Key c end end
 TestObject2  5 Key a end end
 TestObject2  6 Key b end end
 TestObject2  7 Key c end end
 TestObject2  8 Key a end end
 TestObject2  9 Key b end end
 TestObject2 10 Key a end end
 TestObject2 11 Key d end end
 TestObject2 12 Key hello end end
 TestObject2 13 Key c end end
 TestObject2 14 Key a end end
end

Key iostatustest end
Pointer Key hi end end

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

/public/public/monopoly/diffpp > test.ok 2>/dev/null << 'endOfExpectedOutput'

Pointer Key <nil> end end
Pointer Key hello end end

Pointer Key hi end end

TestObject1 12 Key hi end end
TestObject2 12 Key hello end end

p == q (before assignment) ? 0
p == q (after assignment) ? 1

Pointer Key hello end end
Pointer Key hello end end

TestObject2 12 Key hello end end

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

$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
