#!/bin/sh
# Run the libtiff test suite and emit ptest-style PASS/FAIL/SKIP lines.
cd "$(dirname "$0")/test" || exit 1

# test_ifd_loop_detection is built with -DSOURCE_DIR="../../tiff-4.7.2/test" and opens
# its images via that relative path; symlink it to the installed test dir.
if [ ! -e "../../tiff-4.7.2/test" ]; then
    mkdir -p "$(dirname ../../tiff-4.7.2/test)"
    ln -sf "$(pwd)" "../../tiff-4.7.2/test" 2>/dev/null || true
fi

CPROGS="ascii_tag long_tag short_tag strip_rw rewrite custom_dir \
custom_dir_EXIF_231 defer_strile_loading defer_strile_writing test_directory \
test_IFD_enlargement test_open_options test_append_to_strip \
test_ifd_loop_detection testtypes test_signed_tags raw_decode"

for t in $CPROGS; do
    if [ -x "./$t" ]; then
        if ./"$t" >/dev/null 2>&1; then echo "PASS: $t"; else echo "FAIL: $t"; fi
    fi
done

for t in *.sh; do
    [ "$t" = "common.sh" ] && continue
    case "$t" in
        *jbig*) echo "SKIP: $t (JBIG support not enabled)"; continue ;;
        tiffcp-thumbnail.sh)
            command -v thumbnail >/dev/null 2>&1 || { echo "SKIP: $t (thumbnail tool not built)"; continue; } ;;
    esac
    if sh "./$t" >/dev/null 2>&1; then echo "PASS: $t"; else echo "FAIL: $t"; fi
done
