From: Nick Bowler Date: Fri, 21 Jun 2013 14:18:39 +0000 (-0400) Subject: tests: Add a simple test to validate PAM output formats. X-Git-Url: https://git.draconx.ca/gitweb/liblbx.git/commitdiff_plain/d4c47ce48c5de8bd1066ae3996f6e34cd790cd7c tests: Add a simple test to validate PAM output formats. This tests that the PAM output produces the correct image type for all four of the lbximg modes. --- diff --git a/Makefile.am b/Makefile.am index ccadd43..c3aecbb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..42f3892 --- /dev/null +++ b/tests/pam-formats.tap @@ -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 . + +. "$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 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 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 index 0000000..85a8164 Binary files /dev/null and b/tests/testdata/palette-ramp differ diff --git a/tests/util/test-init.sh b/tests/util/test-init.sh index e8a53da..5cd161a 100644 --- a/tests/util/test-init.sh +++ b/tests/util/test-init.sh @@ -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}"