#!/bin/bash
set -e

pkg=libbigwig
CUR_DIR=`pwd`

export LC_ALL=C.UTF-8
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

cp -a ${CUR_DIR}/test "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

echo "1c52065211fdc44eea45751a9cbfffe0 test/Local.bw" >> checksums
echo "8e116bd114ffd2eb625011d451329c03 test/Write.bw" >> checksums
echo "ef104f198c6ce8310acc149d0377fc16 test/example_output.bw" >> checksums

LIB_STATIC=`find /usr/lib -name libBigWig.a`

#Compile using installed libbigwig
echo 'Compiling ...'
gcc -g -Wall   test/testLocal.c ${LIB_STATIC} -lBigWig -lcurl -lm -lz -o testlocal
gcc -g -Wall   test/testWrite.c ${LIB_STATIC} -lBigWig -lm -lz -lcurl -o testWrite
gcc -g -Wall   test/exampleWrite.c ${LIB_STATIC} -lBigWig -lcurl -lm -lz -o examplewrite

echo '------------------------------'

echo -e "Test 1"
./testlocal test/test.bw > test/Local.bw

echo -e "Test 2"
./testWrite test/test.bw test/Write.bw

echo -e "Test 3"
./examplewrite

md5sum --check checksums
echo -e "PASS"
