#!/bin/sh

echo "running tests..."

echo "Creating cabinet archive..."
OLDDIR=`pwd`
(cat files && echo -e "\n${OLDDIR}/libcabinet-0.30.cab") | (cd .. && ${OLDDIR}/listcab)

if [ "$?" != "0" ]; then
	exit 1
fi

echo "Extracting archived files into ./testdir/"

if [ ! -d testdir ]; then
	mkdir testdir
fi

cd testdir
../listcab ../libcabinet-0.30.cab `cat ../files`

if [ "$?" != "0" ]; then
	exit 1
fi

echo "Comparing files..."

for file in `find ./ \( -name "*" -a \! -type d \) -print`
do
	diff -q ${file} ../../${file}

	if [ "$?" != "0" ]; then
		echo "Test failed."
		echo "Extracted file ${file} differs from the original."
		exit 1
	fi
done


echo "Congradulations, all tests have succeeded."
echo "To install your library please run ./installlib"

exit 0
