# #-- fwd_compress_c00c.test --#
# source the master var file when it's there
[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
# use .tpkg.var.test for in test variable passing
[ -f .tpkg.var.test ] && source .tpkg.var.test

# check what sort of netcat we have
if nc -h 2>&1 | grep "q secs"; then
	ncopt="-q 3 -i 2"
else
	ncopt="-i 2 --no-shutdown"
fi

PRE="../.."
# do the test
echo "> query overeinder.net | nc $ncopt tcp | xxd."
echo "0020eb41010000010000000000000a6f76657265696e646572036e65740000010001" | xxd -r -p | nc $ncopt 127.0.0.1 $UNBOUND_PORT | xxd | tee outfile
echo "> cat logfiles"
cat fwd.log 
cat unbound.log
echo "> cat outfile"
cat outfile
echo "> check answer"
if grep "0000000: 007a" outfile; then
	echo "too big!"
	exit 1
fi
if grep "0000000: 006c" outfile; then
	echo "OK"
else	
	echo "bad size, not OK"
	exit 1
fi

if grep "^00000000: 006c" outfile; then
	echo "fixup xxd with long file positions"
	sed -e 's/^0//' < outfile > outfile2
	mv outfile2 outfile
	cat outfile
fi

if diff fwd_compress_c00c.good outfile; then
	echo "Diff OK"
else
	echo "Diff in output"
	exit 1
fi

exit 0
