/test-suite.log
/INSTALL
+
+/atconfig
+/atlocal
+/package.m4
+/testsuite
+/testsuite.deps
+/testsuite.log
# This is free software: you are free to do what the fuck you want to.
# There is NO WARRANTY, to the extent permitted by law.
-AUTOMAKE_OPTIONS = parallel-tests color-tests
ACLOCAL_AMFLAGS = -I m4 -I common/m4
# For Gnulib
EXTRA_DIST = bootstrap $(DX_BASEDIR)/scripts/fix-gnulib.pl m4/gnulib-cache.m4
CLEANFILES = $(EXTRA_LTLIBRARIES)
+DISTCLEANFILES =
AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib \
-I$(top_builddir)/src -I$(top_srcdir)/src \
lbxgui_LDFLAGS = $(AM_LDFLAGS) -export-dynamic
lbxgui_LDADD = liblbx.la $(GTK_LIBS)
-TEST_EXTENSIONS = .tap
-
-TAP_LOG_COMPILER = $(SHELL)
-TAP_LOG_DRIVER = AM_TAP_AWK='$(AWK)' \
- $(SHELL) $(srcdir)/tests/util/tap-driver.sh
-
-TESTS = tests/broken-archives.tap tests/empty-image.tap tests/pam-formats.tap \
- tests/moo2-mainmenu.tap tests/moo2-logo.tap tests/moo2-starbg.tap \
- tests/moo2-ships.tap tests/moo2-monster.tap
-
-mostlyclean-local: clean-testdirs
-clean-testdirs:
- for dir in $(TESTS:.tap=.dir); do \
- case $$dir in \
- *.dir) rm -rf "$$dir" ;; \
- esac; \
- done
-.PHONY: clean-testdirs
-
OPTFILES = src/toolopts.opt src/imgopts.opt
.opt.h:
$(AM_V_GEN) $(AWK) -f $(DX_BASEDIR)/scripts/gen-options.awk $< >$@.tmp
EXTRA_DIST += src/gui/lbxgui.glade.xml
CLEANFILES += src/gui/lbxgui.glade.c
-include lib/gnulib.mk
+atlocal: config.status
+ $(AM_V_GEN) :; { \
+ printf ': "$${%s=%s}"\n' \
+ datadir '$(datadir)' \
+ LN_S '$(LN_S)' \
+ MD5SUM '$(MD5SUM)' \
+ PAMARITH '$(PAMARITH)' \
+ PAMCHANNEL '$(PAMCHANNEL)' \
+ ; } >$@.tmp
+ $(AM_V_at) mv -f $@.tmp $@
+check_DATA = atlocal
+CLEANFILES += atlocal
+
+# Data files used in test cases
+dist_check_DATA = tests/testdata/image-0x0 tests/testdata/image-1x1 \
+ tests/testdata/image-1x1-mt tests/testdata/palette-ramp \
+ tests/testdata/arch-trunc.lbx
+
+include $(top_srcdir)/common/snippet/autotest.mk
+include $(top_srcdir)/lib/gnulib.mk
AC_SUBST([PAMCHANNEL])
AC_SUBST([PAMARITH])
-AC_CONFIG_FILES([tests/util/test-defs.sh Makefile])
+AC_CONFIG_TESTDIR([.])
+DX_PROG_AUTOTEST
+AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"])
+
+AC_CONFIG_FILES([Makefile])
AC_OUTPUT
-#!/bin/sh
-#
-# 2ooM: The Master of Orion II Reverse Engineering Project
-# Test that EOF when unpacking an archive is an error.
-# Copyright © 2014 Nick Bowler
+# Copyright © 2014, 2021 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
# 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
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
-plan_ 1
-dx_create_testdir
+AT_BANNER([Archive format tests])
-failed=false
-$LBXTOOL -xf "$testdata/arch-trunc.lbx" || failed=true
-command_ok_ "EOF handled in archive" $failed
+AT_SETUP([EOF while reading archive])
+AT_CHECK([lbxtool -xf "$testdata/arch-trunc.lbx"], [1], [], [ignore])
+AT_CLEANUP
--- /dev/null
+# Copyright © 2013, 2021 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 <https://www.gnu.org/licenses/>.
+
+AT_BANNER([Image format tests])
+
+m4_divert_push([PREPARE_TESTS])dnl
+# Read the header from a PAM image (from standard input) and set declared
+# parameters in shell variables. For example, if the PAM header specifies
+# DEPTH 2, the shell variable pam_DEPTH will be set to 2.
+#
+# Returns a nonzero status if the header could not be parsed.
+pam_read_header () {
+ pam_save_IFS=$IFS
+ pam_p7_seen=false pam_endhdr_seen=false
+
+ while IFS= read a; do
+ case $a in
+ P7)
+ $pam_p7_seen && break # duplicated header
+ pam_p7_seen=true
+ ;;
+ ENDHDR)
+ pam_endhdr_seen=true
+ break
+ ;;
+ *)
+ IFS=$pam_save_IFS read b c <<EOF
+$a
+EOF
+ b=AS_TR_SH([$b])
+ AS_VAR_SET([pam_$b], [$c])
+ ;;
+ esac
+ done
+
+ IFS=$pam_save_IFS
+ $pam_p7_seen && $pam_endhdr_seen
+}
+
+pam_check_header () {
+ for pam_arg
+ do
+ AS_UNSET([pam_$pam_arg])
+ done
+
+ pam_read_header || return
+
+ for pam_arg
+ do
+ AS_VAR_SET_IF([pam_$pam_arg],
+ [AS_VAR_COPY([pam_val], [pam_$pam_arg])],
+ [AS_UNSET([pam_val])])
+ AS_ECHO(["$pam_arg${pam_val+ = }${pam_val- unset}"])
+ done
+}
+m4_divert_pop([PREPARE_TESTS])
+
+AT_SETUP([Empty image])
+
+AT_CHECK([lbximg -F pbm -dnf "$testdata/image-0x0" && cat out.000.pbm], [0],
+[P1
+0 0
+])
+
+AT_CLEANUP
+
+AT_SETUP([PAM output format (no palette)])
+
+# image-1x1 (no palette)
+AT_CHECK([lbximg -F pam -dnf "$testdata/image-1x1"])
+AT_CHECK([pam_check_header WIDTH HEIGHT DEPTH TUPLTYPE <out.000.pam], [0],
+[WIDTH = 1
+HEIGHT = 1
+DEPTH = 1
+TUPLTYPE = GRAYSCALE
+])
+
+AT_CLEANUP
+
+AT_SETUP([PAM output format (no palette + transparency)])
+
+# image-1x1 (no palette)
+AT_CHECK([lbximg -F pam -dnf "$testdata/image-1x1-mt"])
+AT_CHECK([pam_check_header WIDTH HEIGHT DEPTH TUPLTYPE <out.000.pam], [0],
+[WIDTH = 1
+HEIGHT = 1
+DEPTH = 2
+TUPLTYPE = GRAYSCALE_ALPHA
+])
+
+AT_CLEANUP
+
+AT_SETUP([PAM output format (palette)])
+
+# image-1x1 (no palette)
+AT_CHECK([lbximg -F pam -df "$testdata/image-1x1" \
+ -p "$testdata/palette-ramp"])
+AT_CHECK([pam_check_header WIDTH HEIGHT DEPTH TUPLTYPE <out.000.pam], [0],
+[WIDTH = 1
+HEIGHT = 1
+DEPTH = 3
+TUPLTYPE = RGB
+])
+
+AT_CLEANUP
+
+AT_SETUP([PAM output format (palette + transparency)])
+
+# image-1x1 (no palette)
+AT_CHECK([lbximg -F pam -df "$testdata/image-1x1-mt" \
+ -p "$testdata/palette-ramp"])
+AT_CHECK([pam_check_header WIDTH HEIGHT DEPTH TUPLTYPE <out.000.pam], [0],
+[WIDTH = 1
+HEIGHT = 1
+DEPTH = 4
+TUPLTYPE = RGB_ALPHA
+])
+
+AT_CLEANUP
+++ /dev/null
-#!/bin/sh
-#
-# 2ooM: The Master of Orion II Reverse Engineering Project
-# Test correct decoding of various images in logo.lbx
-# 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
-# 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
-
-test x"${MOO2DATA+set}" = x"set" ||
- skip_all_ "test requires original data files"
-dx_create_testdir
-
-plan_ 7
-
-command_ok_ "unpacking logo.lbx" $LBXTOOL -xf "$MOO2DATA/logo.lbx"
-
-diag_ "Test image with transparency and embedded palette"
-command_ok_ "decoding logo.lbx.000" \
- $LBXIMG -F pam --output-prefix test0 -df logo.lbx.000
-dx_check_pam_md5 "test0.000.pam" e51c564aa638dc62dd1fd79e6f6cc375
-
-diag_ "Test image with animation and embedded palette"
-command_ok_ "decoding logo.lbx.001" \
- $LBXIMG -F pam --output-prefix test1 -df logo.lbx.001
-dx_check_pam_md5 "test1.000.pam" 13a60ede277eebe8fec69f03c5cb5843
-dx_check_pam_md5 "test1.030.pam" c687fc35b940d0bfdaea5b6d51aa03c4
-dx_check_pam_md5 "test1.063.pam" 7c694409997fe15272abe71f3fea2759
+++ /dev/null
-#!/bin/sh
-#
-# 2ooM: The Master of Orion II Reverse Engineering Project
-# Test correct decoding of various images in mainmenu.lbx
-# 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
-# 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
-
-test x"${MOO2DATA+set}" = x"set" ||
- skip_all_ "test requires original data files"
-dx_create_testdir
-
-plan_ 10
-
-command_ok_ "unpacking fonts.lbx" $LBXTOOL -xf "$MOO2DATA/fonts.lbx"
-command_ok_ "unpacking mainmenu.lbx" $LBXTOOL -xf "$MOO2DATA/mainmenu.lbx"
-
-diag_ "Test image with embedded palette"
-command_ok_ "decoding mainmenu.lbx.021" \
- $LBXIMG -F pam --output-prefix test0 -df mainmenu.lbx.021
-dx_check_pam_md5 "test0.000.pam" 848e33a0addc6e9acdc4fee6cbd56639
-
-diag_ "Test image with external palette"
-command_ok_ "decoding mainmenu.lbx.007" \
- $LBXIMG -F pam --output-prefix test1 --palette fonts.lbx.006 \
- -df mainmenu.lbx.007
-dx_check_pam_md5 "test1.000.pam" f301ffcc1a2faa3a0aa68514784012ec
-
-diag_ "Test image with animation and external palette"
-command_ok_ "decoding mainmenu.lbx.000" \
- $LBXIMG -F pam --output-prefix test2 --palette fonts.lbx.006 \
- -df mainmenu.lbx.000
-dx_check_pam_md5 "test2.000.pam" 7c3b347e03d42cd7bd1597f9dd58594e
-dx_check_pam_md5 "test2.015.pam" 2a66f4c30ca315cc061606b27cef4adf
-dx_check_pam_md5 "test2.049.pam" 848e33a0addc6e9acdc4fee6cbd56639
+++ /dev/null
-#!/bin/sh
-#
-# 2ooM: The Master of Orion II Reverse Engineering Project
-# Test correct decoding of various images in monster.lbx
-# 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
-# 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
-
-test x"${MOO2DATA+set}" = x"set" ||
- skip_all_ "test requires original data files"
-dx_create_testdir
-
-plan_ 6
-
-command_ok_ "unpacking fonts.lbx" $LBXTOOL -xf "$MOO2DATA/fonts.lbx"
-command_ok_ "unpacking monster.lbx" $LBXTOOL -xf "$MOO2DATA/monster.lbx"
-
-diag_ "Test image with animation, transparency and non-zero chunk size"
-command_ok_ "decoding monster.lbx.007" \
- $LBXIMG -F pam --output-prefix test0 --palette fonts.lbx.004 \
- -df monster.lbx.007 --override monster.lbx.014
-dx_check_pam_md5 "test0.000.pam" 35d32459bfce6b19df14cafd2faf398b
-dx_check_pam_md5 "test0.005.pam" 924fafdc83e0414331e0c627c3f9b3c7
-dx_check_pam_md5 "test0.019.pam" 272ca2d13132a1b0497e47225ee680e2
+++ /dev/null
-#!/bin/sh
-#
-# 2ooM: The Master of Orion II Reverse Engineering Project
-# Test correct decoding of various images in ships.lbx
-# 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
-# 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
-
-test x"${MOO2DATA+set}" = x"set" ||
- skip_all_ "test requires original data files"
-dx_create_testdir
-
-plan_ 4
-
-command_ok_ "unpacking fonts.lbx" $LBXTOOL -xf "$MOO2DATA/fonts.lbx"
-command_ok_ "unpacking ships.lbx" $LBXTOOL -xf "$MOO2DATA/ships.lbx"
-
-diag_ "Test image with external palette and override"
-command_ok_ "decoding ships.lbx.042" \
- $LBXIMG -F pam --output-prefix test0 --palette fonts.lbx.012 \
- -df ships.lbx.042 --override ships.lbx.049
-dx_check_pam_md5 "test0.000.pam" 4ababc13ae860494d4f512f8ebeca834
+++ /dev/null
-#!/bin/sh
-#
-# 2ooM: The Master of Orion II Reverse Engineering Project
-# Test correct decoding of various images in starbg.lbx
-# 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
-# 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
-
-test x"${MOO2DATA+set}" = x"set" ||
- skip_all_ "test requires original data files"
-dx_create_testdir
-
-plan_ 4
-
-command_ok_ "unpacking fonts.lbx" $LBXTOOL -xf "$MOO2DATA/fonts.lbx"
-command_ok_ "unpacking starbg.lbx" $LBXTOOL -xf "$MOO2DATA/starbg.lbx"
-
-diag_ "Test image with raw flag"
-command_ok_ "decoding starbg.lbx.009" \
- $LBXIMG -F pam --output-prefix test0 --palette fonts.lbx.005 \
- -df starbg.lbx.009
-dx_check_pam_md5 "test0.000.pam" 3b6ccbe3fc46e13c1fa80edf611d7a62
--- /dev/null
+# Copyright © 2013, 2021 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 <https://www.gnu.org/licenses/>.
+
+AT_BANNER([Original data file tests])
+
+AT_ARG_OPTION_ARG([moo2-datadir],
+ [AS_HELP_STRING([--moo2-datadir],
+ [location of original MOO2 data files
+ (default: \${datadir}/moo2-data)], [17])],
+ [moo2_datadir=$at_optarg], [moo2_datadir=$datadir/moo2-data])
+
+m4_divert_push([PREPARE_TESTS])dnl
+# Compute MD5 hash of standard input.
+test_md5sum () {
+ set x `md5sum </dev/null`
+ case $2 in
+ d41d8cd98f00b204e9800998ecf8427e) set x `md5sum && echo $?` ;;
+ *) return 77 ;;
+ esac
+ echo $2
+ eval "return \$$#"
+}
+m4_divert_pop([PREPARE_TESTS])
+
+dnl TEST_REQUIRE_MOO2_DATA(file ...)
+dnl
+dnl Copy (or link) one or more MOO2 data files from the MOO2 installation
+dnl directory into the current test case directory. Installed filenames are
+dnl matched case-insensitively and copied to the name specified.
+dnl
+dnl The test group will be skipped if any requested file does not exist.
+m4_define([TEST_REQUIRE_MOO2_DATA_CASEWRAP],
+ [@<:@m4_toupper([$1])m4_tolower([$1])@:>@])
+m4_define([TEST_REQUIRE_MOO2_DATA], [AT_KEYWORDS([$1])dnl
+m4_foreach_w([DATAFILE], [$1],
+ [m4_pushdef([PATTERN],
+ [$][1/]m4_dquote(m4_map([$0_CASEWRAP],
+ m4_cdr(m4_bpatsubst(m4_defn([DATAFILE]), [.], [,[[\&]]])))))dnl
+test -f DATAFILE || for f in m4_join([ ],
+ PATTERN(["$moo2_datadir"]),
+ PATTERN([/usr/share/moo2-data]))
+do
+ test -f "$f" && { $LN_S "$f" DATAFILE || cp "$f" DATAFILE; } && break
+done
+AT_SKIP_IF([test ! -f "$f"])
+m4_popdef([PATTERN])])])
+
+dnl TEST_UNPACK_MOO2_DATA(file ...)
+dnl
+dnl Wrapper around TEST_REQUIRE_MOO2_DATA that unpacks each file (which should
+dnl be archives).
+m4_define([TEST_UNPACK_MOO2_DATA],
+[TEST_REQUIRE_MOO2_DATA([$1])dnl
+m4_map_args_w([$1], [AT_CHECK([lbxtool -xf ]], [)], [
+])])
+
+dnl TEST_CHECK_PAM_MD5(file, expected_md5, [header = value] ...)
+dnl
+dnl Compute and validate the MD5 hash over the plane data from a PAM image.
+dnl Additional arguments specify PAM header fields that should be checked.
+m4_define([TEST_CHECK_PAM_MD5],
+[exec 3<$1; AT_CHECK([pam_check_header <&3 \
+ m4_map_args_sep([m4_apply([m4_car], m4_split(], [))], [ ], m4_shift2($@))
+status=$?
+echo $pam_TUPLTYPE >$1.tt
+exit $?], [0],[m4_map_args([m4_n], m4_shift2($@))])
+AT_CHECK([test_md5sum <&3 >$1.md5])
+exec 3<&-
+
+# For reliable verification of images with transparency, we must have a known
+# constant colour value for transparent pixels. We can use netpbm tools to
+# zero out those pixels. For affected image formats, if we cannot normalize
+# the transparent pixels we have to skip the test if verification would fail.
+
+md5_reliable=true
+read pam_TUPLTYPE <$1.tt
+AS_CASE([$pam_TUPLTYPE],
+ [GRAYSCALE_ALPHA], [alpha=1],
+ [RGB_ALPHA], [alpha=3],
+ [alpha=0])
+AS_IF([test "$alpha" -gt 0],
+[$PAMCHANNEL "$alpha" <$1 >$1.msk &&
+ $PAMARITH -and $1 $1.msk >$1.fix &&
+ { pam_read_header && test_md5sum; } <$1.fix >$1.tmp &&
+ mv -f $1.tmp $1.md5 ||
+ md5_reliable=false
+AT_CHECK([$md5_reliable || { read x <$1.md5; test x"$x" = x"$2" || exit 77; }])
+])
+AT_CHECK([cat $1.md5], [0], [m4_n([$2])])])
+
+# Image with transparency and embedded palette
+AT_SETUP([logo.lbx.000])
+
+TEST_UNPACK_MOO2_DATA([logo.lbx])
+AT_CHECK([lbximg -F pam -df logo.lbx.000])
+TEST_CHECK_PAM_MD5([out.000.pam],
+ [e51c564aa638dc62dd1fd79e6f6cc375],
+ [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB_ALPHA])
+
+AT_CLEANUP
+
+# Animation with embedded palette
+AT_SETUP([logo.lbx.001])
+
+TEST_UNPACK_MOO2_DATA([logo.lbx])
+AT_CHECK([lbximg -F pam -df logo.lbx.001])
+TEST_CHECK_PAM_MD5([out.000.pam],
+ [13a60ede277eebe8fec69f03c5cb5843],
+ [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
+TEST_CHECK_PAM_MD5([out.030.pam],
+ [c687fc35b940d0bfdaea5b6d51aa03c4],
+ [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
+TEST_CHECK_PAM_MD5([out.063.pam],
+ [7c694409997fe15272abe71f3fea2759],
+ [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
+
+AT_CLEANUP
+
+# Animation with external palette
+AT_SETUP([mainmenu.lbx.000])
+
+TEST_UNPACK_MOO2_DATA([fonts.lbx mainmenu.lbx])
+AT_CHECK([lbximg -F pam -df mainmenu.lbx.000 -p fonts.lbx.006])
+TEST_CHECK_PAM_MD5([out.000.pam],
+ [7c3b347e03d42cd7bd1597f9dd58594e],
+ [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
+TEST_CHECK_PAM_MD5([out.015.pam],
+ [2a66f4c30ca315cc061606b27cef4adf],
+ [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
+TEST_CHECK_PAM_MD5([out.049.pam],
+ [848e33a0addc6e9acdc4fee6cbd56639],
+ [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
+
+AT_CLEANUP
+
+# Image with external palette
+AT_SETUP([mainmenu.lbx.007])
+
+TEST_UNPACK_MOO2_DATA([fonts.lbx mainmenu.lbx])
+AT_CHECK([lbximg -F pam -df mainmenu.lbx.007 -p fonts.lbx.006])
+TEST_CHECK_PAM_MD5([out.000.pam],
+ [f301ffcc1a2faa3a0aa68514784012ec],
+ [WIDTH = 153], [HEIGHT = 22], [TUPLTYPE = RGB])
+
+AT_CLEANUP
+
+# Image with embedded palette
+AT_SETUP([mainmenu.lbx.021])
+
+TEST_UNPACK_MOO2_DATA([mainmenu.lbx])
+AT_CHECK([lbximg -F pam -df mainmenu.lbx.021])
+TEST_CHECK_PAM_MD5([out.000.pam],
+ [848e33a0addc6e9acdc4fee6cbd56639],
+ [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
+
+AT_CLEANUP
+
+# Animation with transparency, override palette and non-zero chunk size
+AT_SETUP([monster.lbx.007])
+
+TEST_UNPACK_MOO2_DATA([fonts.lbx monster.lbx])
+AT_CHECK(
+ [lbximg -F pam -df monster.lbx.007 -p fonts.lbx.004 -O monster.lbx.014])
+TEST_CHECK_PAM_MD5([out.000.pam],
+ [35d32459bfce6b19df14cafd2faf398b],
+ [WIDTH = 59], [HEIGHT = 62], [TUPLTYPE = RGB_ALPHA])
+TEST_CHECK_PAM_MD5([out.005.pam],
+ [924fafdc83e0414331e0c627c3f9b3c7],
+ [WIDTH = 59], [HEIGHT = 62], [TUPLTYPE = RGB_ALPHA])
+TEST_CHECK_PAM_MD5([out.019.pam],
+ [272ca2d13132a1b0497e47225ee680e2],
+ [WIDTH = 59], [HEIGHT = 62], [TUPLTYPE = RGB_ALPHA])
+
+AT_CLEANUP
+
+# Image with transparency, external and override palettes
+AT_SETUP([ships.lbx.042])
+
+TEST_UNPACK_MOO2_DATA([fonts.lbx ships.lbx])
+AT_CHECK([lbximg -F pam -df ships.lbx.042 -p fonts.lbx.012 -O ships.lbx.049])
+TEST_CHECK_PAM_MD5([out.000.pam], [4ababc13ae860494d4f512f8ebeca834],
+ [WIDTH = 52], [HEIGHT = 52], [TUPLTYPE = RGB_ALPHA])
+
+AT_CLEANUP
+
+# Image with raw frame format
+AT_SETUP([starbg.lbx.009])
+
+TEST_UNPACK_MOO2_DATA([fonts.lbx starbg.lbx])
+AT_CHECK([lbximg -F pam -df starbg.lbx.009 -p fonts.lbx.005])
+TEST_CHECK_PAM_MD5([out.000.pam],
+ [3b6ccbe3fc46e13c1fa80edf611d7a62],
+ [WIDTH = 61], [HEIGHT = 56], [TUPLTYPE = RGB])
+
+AT_CLEANUP
+++ /dev/null
-#!/bin/sh
-#
-# 2ooM: The Master of Orion II Reverse Engineering Project
-# Test that the PAM writer emits the smallest output format.
-# 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
-# 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
-
-dx_create_testdir
-plan_ 8
-
-check_image() {
- dx_pam_header "$1" > "$1.sh" || return
- ( . "./$1.sh" || exit
-
- test x"$WIDTH" = x"1" || exit
- test x"$HEIGHT" = x"1" || exit
- test x"$DEPTH" = x"$2" || exit
-
- 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
+++ /dev/null
-/test-defs.sh
+++ /dev/null
-#! /bin/sh
-# Copyright (C) 2011-2013 Free Software Foundation, Inc.
-#
-# 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 2, 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/>.
-
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-# This file is maintained in Automake, please report
-# bugs to <bug-automake@gnu.org> or send patches to
-# <automake-patches@gnu.org>.
-
-scriptversion=2011-12-27.17; # UTC
-
-# Make unconditional expansion of undefined variables an error. This
-# helps a lot in preventing typo-related bugs.
-set -u
-
-me=tap-driver.sh
-
-fatal ()
-{
- echo "$me: fatal: $*" >&2
- exit 1
-}
-
-usage_error ()
-{
- echo "$me: $*" >&2
- print_usage >&2
- exit 2
-}
-
-print_usage ()
-{
- cat <<END
-Usage:
- tap-driver.sh --test-name=NAME --log-file=PATH --trs-file=PATH
- [--expect-failure={yes|no}] [--color-tests={yes|no}]
- [--enable-hard-errors={yes|no}] [--ignore-exit]
- [--diagnostic-string=STRING] [--merge|--no-merge]
- [--comments|--no-comments] [--] TEST-COMMAND
-The \`--test-name', \`--log-file' and \`--trs-file' options are mandatory.
-END
-}
-
-# TODO: better error handling in option parsing (in particular, ensure
-# TODO: $log_file, $trs_file and $test_name are defined).
-test_name= # Used for reporting.
-log_file= # Where to save the result and output of the test script.
-trs_file= # Where to save the metadata of the test run.
-expect_failure=0
-color_tests=0
-merge=0
-ignore_exit=0
-comments=0
-diag_string='#'
-while test $# -gt 0; do
- case $1 in
- --help) print_usage; exit $?;;
- --version) echo "$me $scriptversion"; exit $?;;
- --test-name) test_name=$2; shift;;
- --log-file) log_file=$2; shift;;
- --trs-file) trs_file=$2; shift;;
- --color-tests) color_tests=$2; shift;;
- --expect-failure) expect_failure=$2; shift;;
- --enable-hard-errors) shift;; # No-op.
- --merge) merge=1;;
- --no-merge) merge=0;;
- --ignore-exit) ignore_exit=1;;
- --comments) comments=1;;
- --no-comments) comments=0;;
- --diagnostic-string) diag_string=$2; shift;;
- --) shift; break;;
- -*) usage_error "invalid option: '$1'";;
- esac
- shift
-done
-
-test $# -gt 0 || usage_error "missing test command"
-
-case $expect_failure in
- yes) expect_failure=1;;
- *) expect_failure=0;;
-esac
-
-if test $color_tests = yes; then
- init_colors='
- color_map["red"]="\e[0;31m" # Red.
- color_map["grn"]="\e[0;32m" # Green.
- color_map["lgn"]="\e[1;32m" # Light green.
- color_map["blu"]="\e[1;34m" # Blue.
- color_map["mgn"]="\e[0;35m" # Magenta.
- color_map["std"]="\e[m" # No color.
- color_for_result["ERROR"] = "mgn"
- color_for_result["PASS"] = "grn"
- color_for_result["XPASS"] = "red"
- color_for_result["FAIL"] = "red"
- color_for_result["XFAIL"] = "lgn"
- color_for_result["SKIP"] = "blu"'
-else
- init_colors=''
-fi
-
-# :; is there to work around a bug in bash 3.2 (and earlier) which
-# does not always set '$?' properly on redirection failure.
-# See the Autoconf manual for more details.
-:;{
- (
- # Ignore common signals (in this subshell only!), to avoid potential
- # problems with Korn shells. Some Korn shells are known to propagate
- # to themselves signals that have killed a child process they were
- # waiting for; this is done at least for SIGINT (and usually only for
- # it, in truth). Without the `trap' below, such a behaviour could
- # cause a premature exit in the current subshell, e.g., in case the
- # test command it runs gets terminated by a SIGINT. Thus, the awk
- # script we are piping into would never seen the exit status it
- # expects on its last input line (which is displayed below by the
- # last `echo $?' statement), and would thus die reporting an internal
- # error.
- # For more information, see the Autoconf manual and the threads:
- # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
- # <http://mail.opensolaris.org/pipermail/ksh93-integration-discuss/2009-February/004121.html>
- trap : 1 3 2 13 15
- if test $merge -gt 0; then
- exec 2>&1
- else
- exec 2>&3
- fi
- "$@"
- echo $?
- ) | LC_ALL=C ${AM_TAP_AWK-awk} \
- -v me="$me" \
- -v test_script_name="$test_name" \
- -v log_file="$log_file" \
- -v trs_file="$trs_file" \
- -v expect_failure="$expect_failure" \
- -v merge="$merge" \
- -v ignore_exit="$ignore_exit" \
- -v comments="$comments" \
- -v diag_string="$diag_string" \
-'
-# FIXME: the usages of "cat >&3" below could be optimized when using
-# FIXME: GNU awk, and/on on systems that supports /dev/fd/.
-
-# Implementation note: in what follows, `result_obj` will be an
-# associative array that (partly) simulates a TAP result object
-# from the `TAP::Parser` perl module.
-
-## ----------- ##
-## FUNCTIONS ##
-## ----------- ##
-
-function fatal(msg)
-{
- print me ": " msg | "cat >&2"
- exit 1
-}
-
-function abort(where)
-{
- fatal("internal error " where)
-}
-
-# Convert a boolean to a "yes"/"no" string.
-function yn(bool)
-{
- return bool ? "yes" : "no";
-}
-
-function add_test_result(result)
-{
- if (!test_results_index)
- test_results_index = 0
- test_results_list[test_results_index] = result
- test_results_index += 1
- test_results_seen[result] = 1;
-}
-
-# Whether the test script should be re-run by "make recheck".
-function must_recheck()
-{
- for (k in test_results_seen)
- if (k != "XFAIL" && k != "PASS" && k != "SKIP")
- return 1
- return 0
-}
-
-# Whether the content of the log file associated to this test should
-# be copied into the "global" test-suite.log.
-function copy_in_global_log()
-{
- for (k in test_results_seen)
- if (k != "PASS")
- return 1
- return 0
-}
-
-# FIXME: this can certainly be improved ...
-function get_global_test_result()
-{
- if ("ERROR" in test_results_seen)
- return "ERROR"
- if ("FAIL" in test_results_seen || "XPASS" in test_results_seen)
- return "FAIL"
- all_skipped = 1
- for (k in test_results_seen)
- if (k != "SKIP")
- all_skipped = 0
- if (all_skipped)
- return "SKIP"
- return "PASS";
-}
-
-function stringify_result_obj(result_obj)
-{
- if (result_obj["is_unplanned"] || result_obj["number"] != testno)
- return "ERROR"
-
- if (plan_seen == LATE_PLAN)
- return "ERROR"
-
- if (result_obj["directive"] == "TODO")
- return result_obj["is_ok"] ? "XPASS" : "XFAIL"
-
- if (result_obj["directive"] == "SKIP")
- return result_obj["is_ok"] ? "SKIP" : COOKED_FAIL;
-
- if (length(result_obj["directive"]))
- abort("in function stringify_result_obj()")
-
- return result_obj["is_ok"] ? COOKED_PASS : COOKED_FAIL
-}
-
-function decorate_result(result)
-{
- color_name = color_for_result[result]
- if (color_name)
- return color_map[color_name] "" result "" color_map["std"]
- # If we are not using colorized output, or if we do not know how
- # to colorize the given result, we should return it unchanged.
- return result
-}
-
-function report(result, details)
-{
- if (result ~ /^(X?(PASS|FAIL)|SKIP|ERROR)/)
- {
- msg = ": " test_script_name
- add_test_result(result)
- }
- else if (result == "#")
- {
- msg = " " test_script_name ":"
- }
- else
- {
- abort("in function report()")
- }
- if (length(details))
- msg = msg " " details
- # Output on console might be colorized.
- print decorate_result(result) msg
- # Log the result in the log file too, to help debugging (this is
- # especially true when said result is a TAP error or "Bail out!").
- print result msg | "cat >&3";
-}
-
-function testsuite_error(error_message)
-{
- report("ERROR", "- " error_message)
-}
-
-function handle_tap_result()
-{
- details = result_obj["number"];
- if (length(result_obj["description"]))
- details = details " " result_obj["description"]
-
- if (plan_seen == LATE_PLAN)
- {
- details = details " # AFTER LATE PLAN";
- }
- else if (result_obj["is_unplanned"])
- {
- details = details " # UNPLANNED";
- }
- else if (result_obj["number"] != testno)
- {
- details = sprintf("%s # OUT-OF-ORDER (expecting %d)",
- details, testno);
- }
- else if (result_obj["directive"])
- {
- details = details " # " result_obj["directive"];
- if (length(result_obj["explanation"]))
- details = details " " result_obj["explanation"]
- }
-
- report(stringify_result_obj(result_obj), details)
-}
-
-# `skip_reason` should be empty whenever planned > 0.
-function handle_tap_plan(planned, skip_reason)
-{
- planned += 0 # Avoid getting confused if, say, `planned` is "00"
- if (length(skip_reason) && planned > 0)
- abort("in function handle_tap_plan()")
- if (plan_seen)
- {
- # Error, only one plan per stream is acceptable.
- testsuite_error("multiple test plans")
- return;
- }
- planned_tests = planned
- # The TAP plan can come before or after *all* the TAP results; we speak
- # respectively of an "early" or a "late" plan. If we see the plan line
- # after at least one TAP result has been seen, assume we have a late
- # plan; in this case, any further test result seen after the plan will
- # be flagged as an error.
- plan_seen = (testno >= 1 ? LATE_PLAN : EARLY_PLAN)
- # If testno > 0, we have an error ("too many tests run") that will be
- # automatically dealt with later, so do not worry about it here. If
- # $plan_seen is true, we have an error due to a repeated plan, and that
- # has already been dealt with above. Otherwise, we have a valid "plan
- # with SKIP" specification, and should report it as a particular kind
- # of SKIP result.
- if (planned == 0 && testno == 0)
- {
- if (length(skip_reason))
- skip_reason = "- " skip_reason;
- report("SKIP", skip_reason);
- }
-}
-
-function extract_tap_comment(line)
-{
- if (index(line, diag_string) == 1)
- {
- # Strip leading `diag_string` from `line`.
- line = substr(line, length(diag_string) + 1)
- # And strip any leading and trailing whitespace left.
- sub("^[ \t]*", "", line)
- sub("[ \t]*$", "", line)
- # Return what is left (if any).
- return line;
- }
- return "";
-}
-
-# When this function is called, we know that line is a TAP result line,
-# so that it matches the (perl) RE "^(not )?ok\b".
-function setup_result_obj(line)
-{
- # Get the result, and remove it from the line.
- result_obj["is_ok"] = (substr(line, 1, 2) == "ok" ? 1 : 0)
- sub("^(not )?ok[ \t]*", "", line)
-
- # If the result has an explicit number, get it and strip it; otherwise,
- # automatically assing the next progresive number to it.
- if (line ~ /^[0-9]+$/ || line ~ /^[0-9]+[^a-zA-Z0-9_]/)
- {
- match(line, "^[0-9]+")
- # The final `+ 0` is to normalize numbers with leading zeros.
- result_obj["number"] = substr(line, 1, RLENGTH) + 0
- line = substr(line, RLENGTH + 1)
- }
- else
- {
- result_obj["number"] = testno
- }
-
- if (plan_seen == LATE_PLAN)
- # No further test results are acceptable after a "late" TAP plan
- # has been seen.
- result_obj["is_unplanned"] = 1
- else if (plan_seen && testno > planned_tests)
- result_obj["is_unplanned"] = 1
- else
- result_obj["is_unplanned"] = 0
-
- # Strip trailing and leading whitespace.
- sub("^[ \t]*", "", line)
- sub("[ \t]*$", "", line)
-
- # This will have to be corrected if we have a "TODO"/"SKIP" directive.
- result_obj["description"] = line
- result_obj["directive"] = ""
- result_obj["explanation"] = ""
-
- if (index(line, "#") == 0)
- return # No possible directive, nothing more to do.
-
- # Directives are case-insensitive.
- rx = "[ \t]*#[ \t]*([tT][oO][dD][oO]|[sS][kK][iI][pP])[ \t]*"
-
- # See whether we have the directive, and if yes, where.
- pos = match(line, rx "$")
- if (!pos)
- pos = match(line, rx "[^a-zA-Z0-9_]")
-
- # If there was no TAP directive, we have nothing more to do.
- if (!pos)
- return
-
- # Let`s now see if the TAP directive has been escaped. For example:
- # escaped: ok \# SKIP
- # not escaped: ok \\# SKIP
- # escaped: ok \\\\\# SKIP
- # not escaped: ok \ # SKIP
- if (substr(line, pos, 1) == "#")
- {
- bslash_count = 0
- for (i = pos; i > 1 && substr(line, i - 1, 1) == "\\"; i--)
- bslash_count += 1
- if (bslash_count % 2)
- return # Directive was escaped.
- }
-
- # Strip the directive and its explanation (if any) from the test
- # description.
- result_obj["description"] = substr(line, 1, pos - 1)
- # Now remove the test description from the line, that has been dealt
- # with already.
- line = substr(line, pos)
- # Strip the directive, and save its value (normalized to upper case).
- sub("^[ \t]*#[ \t]*", "", line)
- result_obj["directive"] = toupper(substr(line, 1, 4))
- line = substr(line, 5)
- # Now get the explanation for the directive (if any), with leading
- # and trailing whitespace removed.
- sub("^[ \t]*", "", line)
- sub("[ \t]*$", "", line)
- result_obj["explanation"] = line
-}
-
-function get_test_exit_message(status)
-{
- if (status == 0)
- return ""
- if (status !~ /^[1-9][0-9]*$/)
- abort("getting exit status")
- if (status < 127)
- exit_details = ""
- else if (status == 127)
- exit_details = " (command not found?)"
- else if (status >= 128 && status <= 255)
- exit_details = sprintf(" (terminated by signal %d?)", status - 128)
- else if (status > 256 && status <= 384)
- # We used to report an "abnormal termination" here, but some Korn
- # shells, when a child process die due to signal number n, can leave
- # in $? an exit status of 256+n instead of the more standard 128+n.
- # Apparently, both behaviours are allowed by POSIX (2008), so be
- # prepared to handle them both. See also Austing Group report ID
- # 0000051 <http://www.austingroupbugs.net/view.php?id=51>
- exit_details = sprintf(" (terminated by signal %d?)", status - 256)
- else
- # Never seen in practice.
- exit_details = " (abnormal termination)"
- return sprintf("exited with status %d%s", status, exit_details)
-}
-
-function write_test_results()
-{
- print ":global-test-result: " get_global_test_result() > trs_file
- print ":recheck: " yn(must_recheck()) > trs_file
- print ":copy-in-global-log: " yn(copy_in_global_log()) > trs_file
- for (i = 0; i < test_results_index; i += 1)
- print ":test-result: " test_results_list[i] > trs_file
- close(trs_file);
-}
-
-BEGIN {
-
-## ------- ##
-## SETUP ##
-## ------- ##
-
-'"$init_colors"'
-
-# Properly initialized once the TAP plan is seen.
-planned_tests = 0
-
-COOKED_PASS = expect_failure ? "XPASS": "PASS";
-COOKED_FAIL = expect_failure ? "XFAIL": "FAIL";
-
-# Enumeration-like constants to remember which kind of plan (if any)
-# has been seen. It is important that NO_PLAN evaluates "false" as
-# a boolean.
-NO_PLAN = 0
-EARLY_PLAN = 1
-LATE_PLAN = 2
-
-testno = 0 # Number of test results seen so far.
-bailed_out = 0 # Whether a "Bail out!" directive has been seen.
-
-# Whether the TAP plan has been seen or not, and if yes, which kind
-# it is ("early" is seen before any test result, "late" otherwise).
-plan_seen = NO_PLAN
-
-## --------- ##
-## PARSING ##
-## --------- ##
-
-is_first_read = 1
-
-while (1)
- {
- # Involutions required so that we are able to read the exit status
- # from the last input line.
- st = getline
- if (st < 0) # I/O error.
- fatal("I/O error while reading from input stream")
- else if (st == 0) # End-of-input
- {
- if (is_first_read)
- abort("in input loop: only one input line")
- break
- }
- if (is_first_read)
- {
- is_first_read = 0
- nextline = $0
- continue
- }
- else
- {
- curline = nextline
- nextline = $0
- $0 = curline
- }
- # Copy any input line verbatim into the log file.
- print | "cat >&3"
- # Parsing of TAP input should stop after a "Bail out!" directive.
- if (bailed_out)
- continue
-
- # TAP test result.
- if ($0 ~ /^(not )?ok$/ || $0 ~ /^(not )?ok[^a-zA-Z0-9_]/)
- {
- testno += 1
- setup_result_obj($0)
- handle_tap_result()
- }
- # TAP plan (normal or "SKIP" without explanation).
- else if ($0 ~ /^1\.\.[0-9]+[ \t]*$/)
- {
- # The next two lines will put the number of planned tests in $0.
- sub("^1\\.\\.", "")
- sub("[^0-9]*$", "")
- handle_tap_plan($0, "")
- continue
- }
- # TAP "SKIP" plan, with an explanation.
- else if ($0 ~ /^1\.\.0+[ \t]*#/)
- {
- # The next lines will put the skip explanation in $0, stripping
- # any leading and trailing whitespace. This is a little more
- # tricky in truth, since we want to also strip a potential leading
- # "SKIP" string from the message.
- sub("^[^#]*#[ \t]*(SKIP[: \t][ \t]*)?", "")
- sub("[ \t]*$", "");
- handle_tap_plan(0, $0)
- }
- # "Bail out!" magic.
- # Older versions of prove and TAP::Harness (e.g., 3.17) did not
- # recognize a "Bail out!" directive when preceded by leading
- # whitespace, but more modern versions (e.g., 3.23) do. So we
- # emulate the latter, "more modern" behaviour.
- else if ($0 ~ /^[ \t]*Bail out!/)
- {
- bailed_out = 1
- # Get the bailout message (if any), with leading and trailing
- # whitespace stripped. The message remains stored in `$0`.
- sub("^[ \t]*Bail out![ \t]*", "");
- sub("[ \t]*$", "");
- # Format the error message for the
- bailout_message = "Bail out!"
- if (length($0))
- bailout_message = bailout_message " " $0
- testsuite_error(bailout_message)
- }
- # Maybe we have too look for dianogtic comments too.
- else if (comments != 0)
- {
- comment = extract_tap_comment($0);
- if (length(comment))
- report("#", comment);
- }
- }
-
-## -------- ##
-## FINISH ##
-## -------- ##
-
-# A "Bail out!" directive should cause us to ignore any following TAP
-# error, as well as a non-zero exit status from the TAP producer.
-if (!bailed_out)
- {
- if (!plan_seen)
- {
- testsuite_error("missing test plan")
- }
- else if (planned_tests != testno)
- {
- bad_amount = testno > planned_tests ? "many" : "few"
- testsuite_error(sprintf("too %s tests run (expected %d, got %d)",
- bad_amount, planned_tests, testno))
- }
- if (!ignore_exit)
- {
- # Fetch exit status from the last line.
- exit_message = get_test_exit_message(nextline)
- if (exit_message)
- testsuite_error(exit_message)
- }
- }
-
-write_test_results()
-
-exit 0
-
-} # End of "BEGIN" block.
-'
-
-# TODO: document that we consume the file descriptor 3 :-(
-} 3>"$log_file"
-
-test $? -eq 0 || fatal "I/O or internal error"
-
-# Local Variables:
-# mode: shell-script
-# sh-indentation: 2
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "scriptversion="
-# time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
-# time-stamp-end: "; # UTC"
-# End:
+++ /dev/null
-# -*- shell-script -*-
-#
-# Copyright (C) 2011-2013 Free Software Foundation, Inc.
-#
-# 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 2, 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/>.
-
-# Helper functions used by TAP-producing tests of the Automake testsuite.
-
-#
-# IMPORTANT: All the functions defined in this file can *not* be used
-# from within a subshell, unless explicitly noted otherwise.
-#
-
-# The counts of the TAP test results seen so far: total count and
-# per-result counts.
-tap_count_=0
-tap_pass_count_=0
-tap_skip_count_=0
-tap_fail_count_=0
-tap_xfail_count_=0
-tap_xpass_count_=0
-
-# not COMMAND [ARGS...]
-# ---------------------
-# Run the given command and invert its exit status.
-not () { ! "$@"; }
-
-# plan_ [unknown|later|lazy|now|NUMBER-OF-PLANNED-TESTS]
-# ------------------------------------------------------
-# Print a TAP plan for the given number of tests. This must be called
-# before reporting any test result. If called with the special argument
-# "unknown" or "later", it will do nothing, expecting the calling script
-# to declare the plan later. If called with the special argument "lazy"
-# or "now", it will print a TAP plan that accounts for the number of tests
-# seen so far.
-plan_ ()
-{
- if test $# -eq 0; then
- bailout_ "plan_: missing argument"
- elif test $# -ge 2; then
- bailout_ "plan_: too many arguments"
- elif test x"$planned_" != x"none" && test x"$planned_" != x"later"; then
- bailout_ "plan_: called to many times"
- elif test x"$1" = x"unknown" || test x"$1" = x"later"; then
- # This means we want to get back later to declaring the TAP plan.
- planned_=later
- return 0
- elif test x"$1" = x"lazy" || test x"$1" = x"now"; then
- planned_=$tap_count_ # Number of test results seen so far.
- elif test $1 -ge 0; then
- planned_=$1
- else
- bailout_ "plan_: invalid argument '$1'"
- fi
- echo "1..$planned_"
-}
-planned_=none
-
-# diag_ [EXPLANATION]
-# ------------------
-# Report the given text as TAP diagnostic. Assumes the string denoting
-# TAP diagnostic lines is stored in the '$diag_string_' variable; this is
-# done to allow better interplay with TAP drivers that allow such a string
-# to be configured.
-diag_ ()
-{
- test $# -eq 0 || echo "$diag_string_ $*"
-}
-
-# Used by the 'diag_' function above. User-overridable.
-diag_string_="#"
-
-# warn_ [EXPLANATION]
-# ------------------
-# Give a warning (using TAP diagnostic).
-warn_ ()
-{
- case $# in
- 0) diag_ "WARNING: (unknown warning)";;
- *) diag_ "WARNING: $*";;
- esac
-}
-
-# result_ RESULT [-D DIRECTIVE] [-r REASON] [--] [DESCRIPTION...]
-# ---------------------------------------------------------------
-# Report a test case with the given RESULT (valid values are "ok" and
-# "not ok") and the given DESCRIPTION (if any). If DIRECTIVE is given
-# and non-empty (valid values being "TODO" and "SKIP"), it will be
-# reported too, with the REASON (if given) appended.
-result_ ()
-{
- set +x # Don't pollute the log files.
- test $# -gt 0 || bailout_ "result_: missing argument"
- tap_result_=$1; shift
- case $tap_result_ in
- "ok"|"not ok") ;;
- *) bailout_ "result_: invalid result '$tap_result'" ;;
- esac
- tap_directive_= tap_reason_=
- while test $# -gt 0; do
- case $1 in
- -D|--directive) tap_directive_=$2; shift;;
- -r|--reason) tap_reason_=$2; shift;;
- --) shift; break;;
- -*) bailout_ "result_: invalid option '$1'";;
- *) break;;
- esac
- shift
- done
- case $tap_directive_ in
- ""|TODO|SKIP) ;;
- *) bailout_ "result_: invalid directive '$directive_'" ;;
- esac
- tap_count_=$(($tap_count_ + 1))
- case $tap_result_,$tap_directive_ in
- ok,) # Passed.
- tap_pass_count_=$(($tap_pass_count_ + 1)) ;;
- not\ ok,TODO) # Expected failure.
- tap_xfail_count_=$(($tap_xfail_count_ + 1)) ;;
- not\ ok,*) # Failed.
- tap_fail_count_=$(($tap_fail_count_ + 1)) ;;
- ok,TODO) # Unexpected pass.
- tap_xpass_count_=$(($tap_xpass_count_ + 1)) ;;
- ok,SKIP) # Skipped.
- tap_skip_count_=$(($tap_skip_count_ + 1)) ;;
- *) # Can't happen.
- bailout_ "internal error in 'result_'" ;;
- esac
- tap_text_="$tap_result_ $tap_count_"
- if test x"$*" != x; then
- tap_text_="$tap_text_ - $*"
- fi
- if test x"$tap_directive_" != x; then
- tap_text_="$tap_text_ # $tap_directive_"${tap_reason_:+" $tap_reason_"}
- fi
- printf '%s\n' "$tap_text_"
- set -x # Restore shell xtraces.
-}
-
-# Shorthands for common usages of 'result_'.
-ok_ () { result_ 'ok' ${1+"$@"}; }
-not_ok_ () { result_ 'not ok' ${1+"$@"}; }
-skip_ () { result_ 'ok' -D SKIP ${1+"$@"}; }
-
-# skip_row_ COUNT [-r REASON] [--] [DESCRIPTION...]
-# -------------------------------------------------
-# Report a COUNT of skipped test, with the given reason and descriptions
-# (if any). Useful to avoid cascade failures in case a fair number of
-# tests depend on an earlier one that failed.
-skip_row_ ()
-{
- skip_count_=$1; shift
- for i_ in $(seq_ $skip_count_); do skip_ ${1+"$@"}; done
-}
-
-# skip_all_ [REASON ...]
-# ----------------------
-# Skip all the tests in a test script. Must be used before calling 'plan_'
-# or reporting any test result. Can't be used from within a subshell.
-skip_all_ ()
-{
- echo "1..0 # SKIP" ${1+"$@"}
- planned_=0
- exit 0
-}
-
-# bailout_ [REASON ...]
-# ---------------------
-# Stop the execution of the current test suite right now, due to an
-# unrecoverable error. Can be called at any point, but cannot be used
-# from within a subshell.
-bailout_ ()
-{
- echo 'Bail out!' ${1+"$@"}
- exit 99
-}
-
-# fatal_ [REASON ...]
-# -------------------
-# Same as 'bailout_'; for compatibility with 'plain-functions.sh'.
-fatal_ ()
-{
- bailout_ ${1+"$@"}
-}
-
-# framework_failure_ [REASON ...]
-# -------------------------------
-# Stop the execution of the current test suite right now, due to an
-# unrecoverable error in the set-up of the test case. Can be called
-# at any point, but cannot be used from within a subshell.
-framework_failure_ ()
-{
- bailout_ "set-up failure"${1+": $*"}
-}
-
-# command_ok_ TEST-DESCRIPTION [OPTIONS..] [--] CMD [ARGS...]
-# -----------------------------------------------------------
-# Helper subroutine for when a TAP result must be determined by the
-# outcome of a command.
-command_ok_ ()
-{
- tap_directive_= tap_reason_=
- test $# -gt 0 || bailout_ "command_ok_: missing argument"
- tap_description_=$1; shift
- while test $# -gt 0; do
- case $1 in
- -D|--directive) tap_directive_=$2; shift;;
- -r|--reason) tap_reason_=$2; shift;;
- --) shift; break;;
- -*) bailout_ "command_ok_: invalid option '$1'";;
- *) break;;
- esac
- shift
- done
- tap_result_="ok"; "$@" || tap_result_="not ok"
- result_ "$tap_result_" -D "$tap_directive_" -r "$tap_reason_" \
- -- "$tap_description_"
-}
-
-:
+++ /dev/null
-# Since we want to chdir in test scripts, set srcdir and builddir
-# to absolute versions for convenience.
-srcdir='@abs_top_srcdir@'
-builddir='@abs_top_builddir@'
-
-MKDIR_P='@MKDIR_P@'
-HAVE_MD5SUM='@HAVE_MD5SUM@'
-MD5SUM='@MD5SUM@'
-
-PAMCHANNEL='@PAMCHANNEL@'
-PAMARITH='@PAMARITH@'
-
-EXEEXT='@EXEEXT@'
+++ /dev/null
-# 2ooM: The Master of Orion II Reverse Engineering Project
-# Common test suite initialization functions.
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This file incorporates work covered by the following copyright and
-# permission notice:
-#
-# Copyright (C) 1996-2013 Free Software Foundation, Inc.
-#
-# 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 2, 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/>.
-
-test ${test_lib_sourced-no} = yes && return 0
-test_lib_sourced=yes
-
-# CDPATH is evil if used in non-interactive scripts (and even more
-# evil if exported in the environment).
-CDPATH=; unset CDPATH
-
-# Be more Bourne compatible.
-# (Snippet inspired to configure's initialization in Autoconf 2.64)
-DUALCASE=1; export DUALCASE # for MKS sh
-if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
- emulate sh
- NULLCMD=:
- setopt NO_GLOB_SUBST
- # If Zsh is not started directly in POSIX-compatibility mode, it has
- # some incompatibilities in the handling of $0 that conflict with our
- # usage; i.e., $0 inside a file sourced with the '.' builtin is
- # temporarily set to the name of the sourced file. Work around that.
- # Note that a bug in some versions of Zsh prevents us from resetting $0
- # in a sourced script, so the use of $argv0. For more info see:
- # <http://www.zsh.org/mla/workers/2009/msg01140.html>
- # The apparently useless 'eval' here is needed by at least dash 0.5.2,
- # to prevent it from bailing out with an error like:
- # "Syntax error: Bad substitution".
- eval 'argv0=${functrace[-1]%:*}' && test -f "$argv0" || {
- echo "Cannot determine the path of running test script." >&2
- echo "Your Zsh (version $ZSH_VERSION) is probably too old." >&2
- exit 99
- }
-else
- argv0=$0
- # Ignore command substitution failure, for it might cause problems
- # with "set -e" on some shells.
- am_shell_opts=$(set -o) || :
- case $am_shell_opts in *posix*) set -o posix;; esac
- unset am_shell_opts
-fi
-
-# A single whitespace character.
-sp=' '
-# A tabulation character.
-tab=' '
-# A newline character.
-nl='
-'
-
-# As autoconf-generated configure scripts do, ensure that IFS
-# is defined initially, so that saving and restoring $IFS works.
-IFS=$sp$tab$nl
-
-. "$srcdir/tests/util/tap-functions.sh"
-. "$srcdir/tests/util/test-defs.sh"
-
-testdata=$srcdir/tests/testdata
-
-# We need a scratch directory for most tests, so set that up now.
-dx_testname=`expr x"$argv0" : x'.*/\(.*\)\.'`
-dx_testdir=tests/$dx_testname.dir
-
-dx_cleanup_testdir() {
- exitstatus=$1
-
- cd "$builddir" || return
- if test "$exitstatus" -eq 0 &&
- test $tap_pass_count_ -eq $tap_count_
- then
- rm -rf "$dx_testdir"
- fi
-}
-
-dx_create_testdir_() {
- $MKDIR_P "$dx_testdir" || return
- trap 'dx_cleanup_testdir $?' 0
- cd "$dx_testdir"
-}
-
-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 }
- /^ENDHDR$/ { print $1"="NR+1; exit }
- 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}"
-
-dx_test_wrapper="$builddir/libtool --mode=execute${TESTWRAPPER:+ }$TESTWRAPPER"
-LBXTOOL="$dx_test_wrapper $LBXTOOL"
-LBXIMG="$dx_test_wrapper $LBXIMG"
-
-set -x
-#!/bin/sh
-#
-# 2ooM: The Master of Orion II Reverse Engineering Project
-# Test decoding of empty (0x0) images
-# Copyright © 2013 Nick Bowler
+AT_COPYRIGHT([Copyright © 2021 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
# 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/>.
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
-. "$srcdir/tests/util/test-init.sh" || exit 99
+AT_INIT
+AT_COLOR_TESTS
-plan_ 2
-dx_create_testdir
+AT_TESTED([lbxtool lbximg])
-command_ok_ "decoding image-0x0" $LBXIMG -F pbm -dnf "$testdata/image-0x0"
+m4_divert_push([PREPARE_TESTS])dnl
+: "${ASAN_OPTIONS=detect_leaks=0}"
+export ASAN_OPTIONS
+: "${testdata=$top_srcdir/tests/testdata}"
+m4_divert_pop([PREPARE_TESTS])
-check_output() {
- diff out.000.pbm - 1>&2 <<'EOF'
-P1
-0 0
-EOF
-}
-command_ok_ "empty (0x0) image output" check_output
+m4_include([tests/archives.at])
+m4_include([tests/images.at])
+m4_include([tests/moo2data.at])