From d4c47ce48c5de8bd1066ae3996f6e34cd790cd7c Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Fri, 21 Jun 2013 10:18:39 -0400 Subject: [PATCH] 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. --- Makefile.am | 2 +- tests/pam-formats.tap | 59 ++++++++++++++++++++++++++++++++++++ tests/testdata/image-1x1 | Bin 0 -> 34 bytes tests/testdata/image-1x1-mt | Bin 0 -> 24 bytes tests/testdata/palette-ramp | Bin 0 -> 1024 bytes tests/util/test-init.sh | 9 ++++++ 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100755 tests/pam-formats.tap create mode 100644 tests/testdata/image-1x1 create mode 100644 tests/testdata/image-1x1-mt create mode 100644 tests/testdata/palette-ramp 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 0000000000000000000000000000000000000000..0615d1fa72b9a25b07e1f056ede221b19af2b2b4 GIT binary patch literal 34 ecmZQ%U}RtbV+IBhAWI2|K>#G`6ve>sf*Ak_#{t3s literal 0 HcmV?d00001 diff --git a/tests/testdata/image-1x1-mt b/tests/testdata/image-1x1-mt new file mode 100644 index 0000000000000000000000000000000000000000..fdf87cae374f25e0152e124e65fa30e5902b3ede GIT binary patch literal 24 ZcmZQ%U}RtbV+IBhAWH&>85mwL0{{ct0UH1S literal 0 HcmV?d00001 diff --git a/tests/testdata/palette-ramp b/tests/testdata/palette-ramp new file mode 100644 index 0000000000000000000000000000000000000000..85a81646c09e1316fa3ecb0220da54c3ecce28a4 GIT binary patch literal 1024 zcmW;6iMFW#0EJ;&8c0$^lm=9$l+s|zIrse^>h5*+Uf+*iuZO?)S)qr&^;v-iK)>Hd zU!VbreF%a8VL&2D0tSNt1|mr$4V~jPLkUoZ{Y0xI5(^SJ`GQmWrDH#*! zx(Hk)BKCyN#{%;$5=En3iW4$HD& zEoe!$g~eil#gc4VEwEfJv9xJL>m_X4hP|RSIW|_S6;^9<$X#K*USsW$OPe(u$ARP0 zhCBzZ>%!fTN4|^AW`m7KJ_Q?io(IpTfI<(x@52u$q^*x22oQv{rCoq93=wW=NBa=l z?H1b|?J3$~x7%U2r-LI*m=NRkA}fsS-aa5x-r zIMRvE2ON(_98Ywn%Mqv338yn%C_UkPKI43$l&)u7E*D%9yQnx;svlu@4IdcESB zQBJojvMfWE(~XJ@d7dM`Q9)&n+wF#1K_%U9D2f6_Nq4FWlx2zXP8HQ9?)N+H71h+- zQB@VHni^^=)OC%zp_U#snx;Y1(u1B2+O|depeMarJRT1`p7f&k1JCCZ&lkPv^Tg}* u!s|^R>Rx!i-*|thqwgD^&j+85zV!1!*LCQ=^h3WLzTYptKlDrgzW)IXo?!t1 literal 0 HcmV?d00001 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}" -- 2.43.0