#!/bin/sh
# autopkgtest check: run the RotateLabels program shipped in the source
# package, adapted for png files (changing extension mha-> png in source code,
# adding a factory, setting the name of the entry function to "main").
# (C) 2024 Pierre Gruet.
# Author: Pierre Gruet <pgt@debian.org>

set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM

cp debian/tests/RotateLabelsPng.cxx document/results/original.png $WORKDIR
cd $WORKDIR

# Get ITK major.minor version number to invoke the linker.
ITK_MINOR=$(dpkg --list | sed -n 's/.*libinsighttoolkit\([0-9]\+\.[0-9]\+\).*/\1/p')

# Building
g++ -Wall -Wextra -I /usr/include/ITK-${ITK_MINOR}/ -I ../include RotateLabelsPng.cxx -lITKCommon-${ITK_MINOR} -litksys-${ITK_MINOR} -litkvnl-${ITK_MINOR} -lITKIOImageBase-${ITK_MINOR} -lITKTransform-${ITK_MINOR} -litkvnl_algo-${ITK_MINOR} -lITKIOPNG-${ITK_MINOR} -o GenericLabelInterpolatorTest

# Running
./GenericLabelInterpolatorTest original.png . 3
