#!/bin/bash
#Copyright 1999-2000, William Stearns <wstearns@pobox.com>
#FIXME - test all vars after running checksys for default values.
#FIXME - feed log entry into mason and compare to all output formats.
#FIXME - test that identical log entries, even separated, produce only one line of output.

error () {
	echo 
	echo Failed test: $*
	if [ -d /usr/src/mason-work ]; then
		echo Failed test: $* on $MASONVER >>/usr/src/mason-work/regression-log
	fi
	echo -n -e "\a" >/dev/stderr
	sleep 1
	echo -n -e "\a" >/dev/stderr
	sleep 1
	echo -n -e "\a" >/dev/stderr
	exit 1
}

echo -n Load library:...
. ./masonlib
echo Done

#Internal check.  If you want to check that the error function actually catches failures, uncomment the following.
#if ! false ; then									error testfail ; fi


echo ---------- General checks ----------
echo -n masonver...
if [ -z "$MASONVER" ]; then								error masonver ; fi

echo done.


echo ---------- Test should return true: ----------
#if !  ; then		error tx ; fi


echo done.

echo ---------- Test should return false: ----------
#if  ; then		error fx ; fi


echo done.


echo ---------- General return values ----------
#if [ ! `` = "" ]; then			error -x ; fi

echo -n clientportrange...
#CLIENTPORT, SERVERPORT, PRPROTO, ACKFLAG
#if [ ! `GENERALIZETCPACK= UCPOLICY= clientportrange ` = "" ]; then	error clientportrange-x ; fi
PORT_MASQ_BEGIN=61000 ; PORT_MASQ_END=65096 ; TRACEROUTE_BEGIN=33434 ; TRACEROUTE_END=33524
if [ ! `GENERALIZETCPACK= UCPOLICY= clientportrange 1056 113 tcp ""` = "1024:65535" ]; then	error clientportrange-1 ; fi
if [ ! `GENERALIZETCPACK= UCPOLICY= clientportrange 61000 113 tcp ""` = "61000:65096" ]; then	error clientportrange-2 ; fi
if [ ! `GENERALIZETCPACK= UCPOLICY= clientportrange 65096 113 tcp ""` = "61000:65096" ]; then	error clientportrange-3 ; fi
if [ ! `GENERALIZETCPACK= UCPOLICY= clientportrange 65097 113 tcp ""` = "1024:65535" ]; then	error clientportrange-4 ; fi
unset PORT_MASQ_BEGIN PORT_MASQ_END TRACEROUTE_BEGIN TRACEROUTE_END

echo -n generalportrange...
PORT_MASQ_BEGIN=61000 ; PORT_MASQ_END=65096
if [ ! `generalportrange 0` = "0" ]; then						error generalportrange-1 ; fi
if [ ! `generalportrange 1` = "0:1023" ]; then						error generalportrange-2 ; fi
if [ ! `generalportrange 1023` = "0:1023" ]; then					error generalportrange-3 ; fi
if [ ! `generalportrange 1024` = "1024:65535" ]; then					error generalportrange-4 ; fi
if [ ! `generalportrange 60999` = "1024:65535" ]; then					error generalportrange-5 ; fi
if [ ! `generalportrange 61000` = "61000:65096" ]; then					error generalportrange-6 ; fi
if [ ! `generalportrange 65096` = "61000:65096" ]; then					error generalportrange-7 ; fi
if [ ! `generalportrange 65097` = "1024:65535" ]; then					error generalportrange-8 ; fi
if [ ! `generalportrange 65535` = "65535" ]; then					error generalportrange-9 ; fi
if [ ! `generalportrange 113` = "113" ]; then						error generalportrange-10 ; fi
unset PORT_MASQ_BEGIN PORT_MASQ_END

echo -n nameof...
if [ ! `HOSTLOOKUP=NONE nameof 127.0.0.1` = "127.0.0.1" ]; then				error nameof-1 ; fi
if [ ! `HOSTLOOKUP=FILESONLY nameof 127.0.0.1` = "localhost" ]; then			error nameof-2 ; fi
if [ ! `HOSTLOOKUP=FULL nameof 127.0.0.1` = "localhost" ]; then				error nameof-3 ; fi



echo done.

echo ---------- Exit with a fanfare ----------
echo `cat $0 | sed -e 's/#.*//' | grep 'error .* fi' | grep -v regression | wc -l` regression tests successful on $MASONVER
if [ -d /usr/src/mason-work ]; then
	date >>/usr/src/mason-work/regression-log
	echo `cat $0 | sed -e 's/#.*//' | grep 'error .* fi' | grep -v regression | wc -l` regression tests successful on $MASONVER >>/usr/src/mason-work/regression-log
fi
exit 0

