]> git.draconx.ca Git - liblbx.git/commitdiff
tests: Zero out transparent pixels before calculating digest.
authorNick Bowler <nbowler@draconx.ca>
Thu, 23 Jan 2014 01:12:02 +0000 (20:12 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 23 Jan 2014 03:12:18 +0000 (22:12 -0500)
The colour value of transparent pixels is irrelevant from a correctness
perspective, but we are nevertheless including that information in the
tests.  While we could zero out the values in the PAM output code it's
better to make the tests more robust.

This adds an external dependency on netpbm's pamarith and pamchannel
tools for the test suite.  Restructure the tests so that these tools
are optional.  If the tools are not available (or not working) then we
must accept the fact that images with an alpha channel may have false
negatives (but not false positives) -- record a SKIP result for an MD5
mismatch in that case.

configure.ac
tests/util/test-defs.sh.in
tests/util/test-init.sh

index af2b64f3d789dac4723e99aeff29b6f2b49c7bcc..8a460a9347806d86ffafacf8ec2786b32323e671 100644 (file)
@@ -1,4 +1,4 @@
-dnl Copyright © 2009, 2013 Nick Bowler
+dnl Copyright © 2009, 2013-2014 Nick Bowler
 dnl
 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 dnl This is free software: you are free to do what the fuck you want to.
@@ -51,12 +51,18 @@ AS_CASE([$enable_lbxgui],
 
 AM_CONDITIONAL([BUILD_LBXGUI], [$have_gtk])
 
+# Check for utilities used by the test suite.
 DX_PROG_MD5SUM
 AS_IF([test x"$dx_cv_md5sum_works" = x"yes"],
        [AC_SUBST([HAVE_MD5SUM], [true])],
        [AC_SUBST([HAVE_MD5SUM], [false])])
 AC_SUBST([MD5SUM])
 
+AC_CHECK_PROGS([PAMARITH], [pamarith], [false])
+AC_CHECK_PROGS([PAMCHANNEL], [pamchannel], [false])
+AC_SUBST([PAMCHANNEL])
+AC_SUBST([PAMARITH])
+
 AC_CONFIG_FILES([
        tests/util/test-defs.sh
        Makefile
index d56b97ca7afd2fbf277f14254d14ddaa1c085af7..663fdee5e898c3afcb311d139fb86ad743eb3615 100644 (file)
@@ -7,4 +7,7 @@ MKDIR_P='@MKDIR_P@'
 HAVE_MD5SUM='@HAVE_MD5SUM@'
 MD5SUM='@MD5SUM@'
 
+PAMCHANNEL='@PAMCHANNEL@'
+PAMARITH='@PAMARITH@'
+
 EXEEXT='@EXEEXT@'
index d59b8532177d210c749499384f046e466980f5d4..2c72bf3a2f195b647340bbe8813e482f400c22cb 100644 (file)
@@ -113,20 +113,57 @@ dx_pam_header() {
                END { exit ret }' ${1+"$@"}
 }
 
-dx_check_pam_md5_() {
+# 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" || 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
+}
 
-       tail -n +"$ENDHDR" "$1" > "$1.px" || return
-       echo "$2  $1.px" > "$1.md5" || return
-       $MD5SUM -c "$1.md5"
+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
-               command_ok_ "$1" dx_check_pam_md5_ "$1" "$2"
+               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_ "$1"
+               skip_ -r "md5sum unavailable or broken" "$1"
        fi
 }