]> git.draconx.ca Git - liblbx.git/commitdiff
tests: Add a simple test to validate PAM output formats.
authorNick Bowler <nbowler@draconx.ca>
Fri, 21 Jun 2013 14:18:39 +0000 (10:18 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sat, 22 Jun 2013 13:56:37 +0000 (09:56 -0400)
This tests that the PAM output produces the correct image type for
all four of the lbximg modes.

Makefile.am
tests/pam-formats.tap [new file with mode: 0755]
tests/testdata/image-1x1 [new file with mode: 0644]
tests/testdata/image-1x1-mt [new file with mode: 0644]
tests/testdata/palette-ramp [new file with mode: 0644]
tests/util/test-init.sh

index ccadd435ccd78a300204d67c617714b2930ca1e4..c3aecbb5161a2bbbeb15aa2fb1b619b869acd9c6 100644 (file)
@@ -55,7 +55,7 @@ TAP_LOG_COMPILER = $(SHELL)
 TAP_LOG_DRIVER = AM_TAP_AWK='$(AWK)' \
        $(SHELL) $(srcdir)/tests/util/tap-driver.sh
 
-TESTS = tests/empty-image.tap
+TESTS = tests/empty-image.tap tests/pam-formats.tap
 
 mostlyclean-local: clean-testdirs
 clean-testdirs:
diff --git a/tests/pam-formats.tap b/tests/pam-formats.tap
new file mode 100755 (executable)
index 0000000..42f3892
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# 2ooM: The Master of Orion II Reverse Engineering Project
+# Test that the PAM writer emits the smallest output format.
+# Copyright © 2013 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
+# the Free Software Foundation, either version 3 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 <http://www.gnu.org/licenses/>.
+
+. "$srcdir/tests/util/test-init.sh" || exit 99
+
+plan_ 8
+dx_create_testdir
+
+check_image()
+{
+       dx_pam_header "$1" > "$1.sh" || return
+       . "./$1.sh" || return
+
+       test x"$WIDTH"  = x"1"  || return
+       test x"$HEIGHT" = x"1"  || return
+       test x"$DEPTH"  = x"$2" || return
+
+       case $DEPTH in
+       1) test x"$TUPLTYPE" = x"GRAYSCALE" ;;
+       2) test x"$TUPLTYPE" = x"GRAYSCALE_ALPHA" ;;
+       3) test x"$TUPLTYPE" = x"RGB" ;;
+       4) test x"$TUPLTYPE" = x"RGB_ALPHA" ;;
+       *) false
+       esac
+}
+
+command_ok_ "decoding image-1x1 (no palette)" \
+       $LBXIMG -F pam --output-prefix test0 -dnf "$testdata/image-1x1"
+command_ok_ "PAM format GRAYSCALE" check_image test0.000.pam 1
+
+command_ok_ "decoding image-1x1-mt (no palette)" \
+       $LBXIMG -F pam --output-prefix test1 -dnf "$testdata/image-1x1-mt"
+command_ok_ "PAM format GRAYSCALE_ALPHA" check_image test1.000.pam 2
+
+command_ok_ "decoding image-1x1 (with palette)" \
+       $LBXIMG -F pam --output-prefix test2 -p "$testdata/palette-ramp" \
+               -df "$testdata/image-1x1"
+command_ok_ "PAM format RGB" check_image test2.000.pam 3
+
+command_ok_ "decoding image-1x1-mt (with palette)" \
+       $LBXIMG -F pam --output-prefix test3 -p "$testdata/palette-ramp" \
+               -df "$testdata/image-1x1-mt"
+command_ok_ "PAM format RGB_ALPHA" check_image test3.000.pam 4
diff --git a/tests/testdata/image-1x1 b/tests/testdata/image-1x1
new file mode 100644 (file)
index 0000000..0615d1f
Binary files /dev/null and b/tests/testdata/image-1x1 differ
diff --git a/tests/testdata/image-1x1-mt b/tests/testdata/image-1x1-mt
new file mode 100644 (file)
index 0000000..fdf87ca
Binary files /dev/null and b/tests/testdata/image-1x1-mt differ
diff --git a/tests/testdata/palette-ramp b/tests/testdata/palette-ramp
new file mode 100644 (file)
index 0000000..85a8164
Binary files /dev/null and b/tests/testdata/palette-ramp differ
index e8a53dae9fa02f93c05743e8099e6da7de0debde..5cd161a2d6d8ddfe4d8caa22b3a49d59bfb5b430 100644 (file)
@@ -105,6 +105,15 @@ dx_create_testdir()
        cd "$dx_testdir"
 }
 
+dx_pam_header()
+{
+       awk 'BEGIN { ret=1 }
+               NR==1 { if (!/^P7$/) exit 1 }
+               /^P7$/,/^ENDHDR$/ { ret=0; if ($2) print $1"="$2 }
+               /^ENDHDR$/ { print $1"="NR+1; exit }
+               END { exit ret }' ${1+"$@"}
+}
+
 # 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}"