]> git.draconx.ca Git - liblbx.git/blobdiff - tests/util/test-init.sh
tests: Allow custom test command wrappers
[liblbx.git] / tests / util / test-init.sh
index 5cd161a2d6d8ddfe4d8caa22b3a49d59bfb5b430..1754f6a3b4a77ba7d0a6a9d0cd567f7a7ab48633 100644 (file)
@@ -1,6 +1,6 @@
 # 2ooM: The Master of Orion II Reverse Engineering Project
 # Common test suite initialization functions.
-# Copyright © 2013 Nick Bowler
+# Copyright © 2013-2014 Nick Bowler
 #
 # 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
@@ -25,8 +25,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-set -e
-
 test ${test_lib_sourced-no} = yes && return 0
 test_lib_sourced=yes
 
@@ -86,11 +84,10 @@ testdata=$srcdir/tests/testdata
 dx_testname=`expr x"$argv0" : x'.*/\(.*\)\.'`
 dx_testdir=tests/$dx_testname.dir
 
-dx_cleanup_testdir()
-{
+dx_cleanup_testdir() {
        exitstatus=$1
 
-       cd "$builddir"
+       cd "$builddir" || return
        if test "$exitstatus" -eq 0 &&
           test $tap_pass_count_ -eq $tap_count_
        then
@@ -98,15 +95,17 @@ dx_cleanup_testdir()
        fi
 }
 
-dx_create_testdir()
-{
-       $MKDIR_P "$dx_testdir"
+dx_create_testdir_() {
+       $MKDIR_P "$dx_testdir" || return
        trap 'dx_cleanup_testdir $?' 0
        cd "$dx_testdir"
 }
 
-dx_pam_header()
-{
+dx_create_testdir() {
+       dx_create_testdir_ || bailout_ "failed to create test directory"
+}
+
+dx_pam_header() {
        awk 'BEGIN { ret=1 }
                NR==1 { if (!/^P7$/) exit 1 }
                /^P7$/,/^ENDHDR$/ { ret=0; if ($2) print $1"="$2 }
@@ -114,14 +113,65 @@ dx_pam_header()
                END { exit ret }' ${1+"$@"}
 }
 
+# Set all transparent pixels in a PAM image to black.  This assumes (fine for
+# LBX images) that all pixels are either fully-transparent or fully-opaque.
+dx_pam_normalize() {
+       dx_pam_header "$1" > "$1.sh" || return
+       ( . "./$1.sh" || exit
+               case $TUPLTYPE in
+               GRAYSCALE_ALPHA) $PAMCHANNEL -infile "$1" 1 > "$1.alpha" ;;
+               RGB_ALPHA) $PAMCHANNEL -infile "$1" 3 > "$1.alpha" ;;
+               *) rm -f "$1.alpha" ;;
+               esac
+       ) || return
+
+       if test -e "$1.alpha"; then
+               $PAMARITH -and "$1" "$1.alpha"
+       else
+               cat "$1"
+       fi
+}
+
+dx_check_pam_md5_() {
+       ( dx_pam_header "$1" > "$1.sh" || exit
+               . "./$1.sh" || exit
+               tail -n +"$ENDHDR" "$1" > "$1.px"
+       ) || return 55
+
+       $MD5SUM -c <<EOF
+$2  $1.px
+EOF
+}
+
+dx_check_pam_md5() {
+       if $HAVE_MD5SUM; then
+               if dx_pam_normalize "$1" > "$1.tmp"; then
+                       mv -f "$1.tmp" "$1"
+                       dx_md5_reliable=true
+               else
+                       dx_md5_reliable=false
+               fi
+
+               dx_check_pam_md5_ "$1" "$2"
+               case $? in
+               0)  ok_ "$1" ;;
+               55) not_ok_ "$1" ;;
+               *) if $dx_md5_reliable; then
+                       not_ok_ "$1"
+               else
+                       skip_ -r "netpbm unavailable or broken" "$1"
+               fi ;;
+               esac
+       else
+               skip_ -r "md5sum unavailable or broken" "$1"
+       fi
+}
+
 # Variables to run the LBX tools.  Default to the build tree, but can also be
 # set explicitly to test installed tools.
 : "${LBXTOOL=$builddir/lbxtool$EXEEXT}"
 : "${LBXIMG=$builddir/lbximg$EXEEXT}"
 
-# Set MALLOC_CHECK_ in the environment of the test programs which will enable
-# malloc instrumentation on glibc-based systems to hopefully catch some forms
-# of memory corruption.
-dx_test_wrapper="$builddir/libtool --mode=execute env MALLOC_CHECK_=3"
+dx_test_wrapper="$builddir/libtool --mode=execute${TESTWRAPPER:+ }$TESTWRAPPER"
 LBXTOOL="$dx_test_wrapper $LBXTOOL"
 LBXIMG="$dx_test_wrapper $LBXIMG"