#!/bin/sh

set -e

# Allow outside-of-autopkgtest runs
if [ -z "$AUTOPKGTEST_TMP" ]; then
    AUTOPKGTEST_TMP=$(mktemp -d)
fi

cp -r ./ $AUTOPKGTEST_TMP/source
cd $AUTOPKGTEST_TMP/source

echo "Patch testpdfio.c to only do tests without using internal APIs"
patch -p0 < debian/tests/testpdfio-autopkgtest.patch

echo "Run standard ./configure"
./configure

make testpdfio.o testttf.o

LIBS="$(pkg-config --libs pdfio) -lz -lm"

echo "Build testttf/testpdfio tests against dynamic testttf/libpdfio"
cc -o ./testttf ./testttf.o ${LIBS}
cc -o ./testpdfio ./testpdfio.o ${LIBS}

# Do the tests
./testttf 2>test.log
./testpdfio 2>>test.log
LANG=fr_FR.UTF-8 ./testpdfio 2>>test.log

cd -
cd -
