#!/bin/sh

set -e
set -x

CMAKE_ARGS='-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++'

rm -rf $PWD/zint-code

git clone https://git.code.sf.net/p/zint/code zint-code

cd $PWD/zint-code
git checkout a312cd
cd ..

export LD_LIBRARY_PATH=$PWD/zint-code/build/backend
export PATH=$PWD/zint-code/build/frontend:${PATH}

mkdir -p $PWD/zint-code/build
cd $PWD/zint-code/build
cmake -DCMAKE_BUILD_TYPE=Debug -DZINT_TEST:BOOL=ON -DZINT_STATIC:BOOL=ON ${CMAKE_ARGS} ..
cmake --build .

cd backend

echo "--- tests/test_bmp begin" && valgrind --leak-check=full tests/test_bmp || echo "--- tests/test_bmp end"
echo "--- tests/test_bmp-static begin" && valgrind --leak-check=full tests/test_bmp-static || echo "--- tests/test_bmp-static end"
echo "--- tests/test_emf begin" && valgrind --leak-check=full tests/test_emf || echo "--- tests/test_emf end"
echo "--- tests/test_emf-static begin" && valgrind --leak-check=full tests/test_emf-static || echo "--- tests/test_emf-static end"
echo "--- tests/test_gif begin" && valgrind --leak-check=full tests/test_gif || echo "--- tests/test_gif end"
echo "--- tests/test_gif-static begin" && valgrind --leak-check=full tests/test_gif-static || echo "--- tests/test_gif-static end"
echo "--- tests/test_png begin" && valgrind --leak-check=full tests/test_png || echo "--- tests/test_png end"
echo "--- tests/test_png-static begin" && valgrind --leak-check=full tests/test_png-static || echo "--- tests/test_png-static end"
echo "--- tests/test_print begin" && valgrind --leak-check=full tests/test_print || echo "--- tests/test_print end"
echo "--- tests/test_print-static begin" && valgrind --leak-check=full tests/test_print-static || echo "--- tests/test_print-static end"
echo "--- tests/test_ps begin" && valgrind --leak-check=full tests/test_ps || echo "--- tests/test_ps end"
echo "--- tests/test_ps-static begin" && valgrind --leak-check=full tests/test_ps-static || echo "--- tests/test_ps-static end"
echo "--- tests/test_svg begin" && valgrind --leak-check=full tests/test_svg || echo "--- tests/test_svg end"
echo "--- tests/test_svg-static begin" && valgrind --leak-check=full tests/test_svg-static || echo "--- tests/test_svg-static end"
echo "--- tests/test_tif begin" && valgrind --leak-check=full tests/test_tif || echo "--- tests/test_tif end"
echo "--- tests/test_tif-static begin" && valgrind --leak-check=full tests/test_tif-static || echo "--- tests/test_tif-static end"

