#!@BASHREAL@

# Harness for rastertogutenprint tester.
#
# Copyright 2007-2017 Robert Krawitz (rlk@alum.mit.edu)
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

if [[ -n "$STP_TEST_LOG_PREFIX" ]] ; then
    redir="${STP_TEST_LOG_PREFIX}${0##*/}_$$.log"
    if [[ -n $BUILD_VERBOSE ]] ; then
	exec > >(tee -a "$redir" >&3)
    else
	exec 1>>"$redir"
    fi
    exec 2>&1
fi

STP_TEST_PROFILE=${STP_TEST_PROFILE:-full}

[[ -n $STP_TEST_COMPONENTS && $STP_TEST_COMPONENTS != '*CUPS*' && $STP_TEST_COMPONENTS != '*test-rastertogutenprint*' ]] && exit 77

set -e

declare FASTOPT="-o StpDitherAlgorithm=VeryFast -l -N -o ColorCorrection=Raw"
declare MIN_PRINTERS="@MINIMAL_PRINTERS_TO_TEST@"

function runit() {
    echo "================================================================"
    echo "$@"
    [[ -z $STP_TEST_DEBUG ]] && "$@"
}

function test_minimal() {
    runit ./test-rastertogutenprint -s $FASTOPT -p 1 \
	  $MIN_PRINTERS
}

function test_fast() {
    runit ./test-rastertogutenprint -S -s $FASTOPT -p 2
}

function test_full() {
    runit ./test-rastertogutenprint -l -p 2 $FASTOPT
    runit ./test-rastertogutenprint -S -s -X
}

function test_valgrind_minimal() {
    runit ./test-rastertogutenprint -v -v -s $FASTOPT -p 1 \
	  $MIN_PRINTERS
}

function test_valgrind_fast() {
    test_valgrind_minimal
}

function test_valgrind() {
    runit ./test-rastertogutenprint -v -v -S -s $FASTOPT -p 2
}

case "$STP_TEST_PROFILE" in
    full|fast|valgrind|valgrind_minimal|valgrind_fast|minimal)
	test_"$STP_TEST_PROFILE"
	;;
    *)
	exit 77
	;;
esac
