]> git.draconx.ca Git - liblbx.git/blob - tests/moo2data.at
Trivial manual fixes.
[liblbx.git] / tests / moo2data.at
1 # Copyright © 2013, 2021 Nick Bowler
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16 AT_BANNER([Original data file tests])
17
18 AT_ARG_OPTION_ARG([moo2-datadir],
19   [AS_HELP_STRING([--moo2-datadir],
20     [location of original MOO2 data files
21      (default: \${datadir}/moo2-data)], [17])],
22   [moo2_datadir=$at_optarg], [moo2_datadir=$datadir/moo2-data])
23
24 m4_divert_push([PREPARE_TESTS])dnl
25 # Compute MD5 hash of standard input.
26 test_md5sum () {
27   set x `$MD5 </dev/null 2>/dev/null`
28   for md5_pos in 2 $#; do
29     AS_VAR_COPY([md5_digest], [$md5_pos])
30     case $md5_digest in
31     d41d8cd98f00b204e9800998ecf8427e)
32       set x `$MD5 && echo $?`
33       eval "echo \$$md5_pos; return \$$#"
34     esac
35   done
36   return 77
37 }
38 m4_divert_pop([PREPARE_TESTS])
39
40 dnl TEST_REQUIRE_MOO2_DATA(file ...)
41 dnl
42 dnl Copy (or link) one or more MOO2 data files from the MOO2 installation
43 dnl directory into the current test case directory.  Installed filenames are
44 dnl matched case-insensitively and copied to the name specified.
45 dnl
46 dnl The test group will be skipped if any requested file does not exist.
47 m4_define([TEST_REQUIRE_MOO2_DATA_CASEWRAP],
48   [@<:@m4_toupper([$1])m4_tolower([$1])@:>@])
49 m4_define([TEST_REQUIRE_MOO2_DATA], [AT_KEYWORDS([$1])dnl
50 m4_foreach_w([DATAFILE], [$1],
51   [m4_pushdef([PATTERN],
52     [$][1/]m4_dquote(m4_map([$0_CASEWRAP],
53       m4_cdr(m4_bpatsubst(m4_defn([DATAFILE]), [.], [,[[\&]]])))))dnl
54 test -f DATAFILE || for f in m4_join([ ],
55   PATTERN(["$moo2_datadir"]),
56   PATTERN([/usr/share/moo2-data]))
57 do
58   test -f "$f" && { $LN_S "$f" DATAFILE || cp "$f" DATAFILE; } && break
59 done
60 AT_SKIP_IF([test ! -f "$f"])
61 m4_popdef([PATTERN])])])
62
63 dnl TEST_UNPACK_MOO2_DATA(file ...)
64 dnl
65 dnl Wrapper around TEST_REQUIRE_MOO2_DATA that unpacks each file (which should
66 dnl be archives).
67 m4_define([TEST_UNPACK_MOO2_DATA],
68 [TEST_REQUIRE_MOO2_DATA([$1])dnl
69 m4_map_args_w([$1], [AT_CHECK([lbxtool -xf ]], [)], [
70 ])])
71
72 dnl TEST_CHECK_PAM_MD5(file, expected_md5, [header = value] ...)
73 dnl
74 dnl Compute and validate the MD5 hash over the plane data from a PAM image.
75 dnl Additional arguments specify PAM header fields that should be checked.
76 m4_define([TEST_CHECK_PAM_MD5],
77 [AT_CHECK([:; { pam_check_header m4_map_args_sep(
78   [m4_apply([m4_car], m4_split(], [))], [ ], m4_shift2($@)) &&
79   echo $pam_TUPLTYPE >$1.tt &&
80   test_md5sum >$1.md5; } <$1], [0], [m4_map_args([m4_n], m4_shift2($@))])
81 dnl AT_CHECK([test_md5sum <&3 >$1.md5])
82 dnl exec 3<&-
83
84 dnl For reliable verification of images with transparency, we must have a known
85 dnl constant colour value for transparent pixels.  We can use netpbm tools to
86 dnl zero out those pixels.  For affected image formats, if we cannot normalize
87 dnl the transparent pixels we have to skip the test if verification would fail.
88 md5_reliable=true
89 read pam_TUPLTYPE <$1.tt
90 AS_CASE([$pam_TUPLTYPE],
91   [GRAYSCALE_ALPHA], [alpha=1],
92   [RGB_ALPHA], [alpha=3],
93   [alpha=0])
94 AS_IF([test "$alpha" -gt 0],
95 [$PAMCHANNEL "$alpha" <$1 >$1.msk &&
96   $PAMARITH -and $1 $1.msk >$1.fix &&
97   { pam_read_header && test_md5sum; } <$1.fix >$1.tmp &&
98   mv -f $1.tmp $1.md5 ||
99   md5_reliable=false
100 AT_CHECK([$md5_reliable || { read x <$1.md5; test x"$x" = x"$2" || exit 77; }])
101 ])
102 AT_CHECK([cat $1.md5], [0], [m4_n([$2])])])
103
104 # Image with transparency and embedded palette
105 AT_SETUP([logo.lbx.000])
106
107 TEST_UNPACK_MOO2_DATA([logo.lbx])
108 AT_CHECK([lbximg -F pam -df logo.lbx.000])
109 TEST_CHECK_PAM_MD5([out.000.pam],
110   [e51c564aa638dc62dd1fd79e6f6cc375],
111   [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB_ALPHA])
112
113 AT_CLEANUP
114
115 # Animation with embedded palette
116 AT_SETUP([logo.lbx.001])
117
118 TEST_UNPACK_MOO2_DATA([logo.lbx])
119 AT_CHECK([lbximg -F pam -df logo.lbx.001])
120 TEST_CHECK_PAM_MD5([out.000.pam],
121   [13a60ede277eebe8fec69f03c5cb5843],
122   [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
123 TEST_CHECK_PAM_MD5([out.030.pam],
124   [c687fc35b940d0bfdaea5b6d51aa03c4],
125   [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
126 TEST_CHECK_PAM_MD5([out.063.pam],
127   [7c694409997fe15272abe71f3fea2759],
128   [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
129
130 AT_CLEANUP
131
132 # Animation with external palette
133 AT_SETUP([mainmenu.lbx.000])
134
135 TEST_UNPACK_MOO2_DATA([fonts.lbx mainmenu.lbx])
136 AT_CHECK([lbximg -F pam -df mainmenu.lbx.000 -p fonts.lbx.006])
137 TEST_CHECK_PAM_MD5([out.000.pam],
138   [7c3b347e03d42cd7bd1597f9dd58594e],
139   [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
140 TEST_CHECK_PAM_MD5([out.015.pam],
141   [2a66f4c30ca315cc061606b27cef4adf],
142   [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
143 TEST_CHECK_PAM_MD5([out.049.pam],
144   [848e33a0addc6e9acdc4fee6cbd56639],
145   [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
146
147 AT_CLEANUP
148
149 # Image with external palette
150 AT_SETUP([mainmenu.lbx.007])
151
152 TEST_UNPACK_MOO2_DATA([fonts.lbx mainmenu.lbx])
153 AT_CHECK([lbximg -F pam -df mainmenu.lbx.007 -p fonts.lbx.006])
154 TEST_CHECK_PAM_MD5([out.000.pam],
155   [f301ffcc1a2faa3a0aa68514784012ec],
156   [WIDTH = 153], [HEIGHT = 22], [TUPLTYPE = RGB])
157
158 AT_CLEANUP
159
160 # Image with embedded palette
161 AT_SETUP([mainmenu.lbx.021])
162
163 TEST_UNPACK_MOO2_DATA([mainmenu.lbx])
164 AT_CHECK([lbximg -F pam -df mainmenu.lbx.021])
165 TEST_CHECK_PAM_MD5([out.000.pam],
166   [848e33a0addc6e9acdc4fee6cbd56639],
167   [WIDTH = 640], [HEIGHT = 480], [TUPLTYPE = RGB])
168
169 AT_CLEANUP
170
171 # Animation with transparency, override palette and non-zero chunk size
172 AT_SETUP([monster.lbx.007])
173
174 TEST_UNPACK_MOO2_DATA([fonts.lbx monster.lbx])
175 AT_CHECK(
176   [lbximg -F pam -df monster.lbx.007 -p fonts.lbx.004 -O monster.lbx.014])
177 TEST_CHECK_PAM_MD5([out.000.pam],
178   [35d32459bfce6b19df14cafd2faf398b],
179   [WIDTH = 59], [HEIGHT = 62], [TUPLTYPE = RGB_ALPHA])
180 TEST_CHECK_PAM_MD5([out.005.pam],
181   [924fafdc83e0414331e0c627c3f9b3c7],
182   [WIDTH = 59], [HEIGHT = 62], [TUPLTYPE = RGB_ALPHA])
183 TEST_CHECK_PAM_MD5([out.019.pam],
184   [272ca2d13132a1b0497e47225ee680e2],
185   [WIDTH = 59], [HEIGHT = 62], [TUPLTYPE = RGB_ALPHA])
186
187 AT_CLEANUP
188
189 # Image with transparency, external and override palettes
190 AT_SETUP([ships.lbx.042])
191
192 TEST_UNPACK_MOO2_DATA([fonts.lbx ships.lbx])
193 AT_CHECK([lbximg -F pam -df ships.lbx.042 -p fonts.lbx.012 -O ships.lbx.049])
194 TEST_CHECK_PAM_MD5([out.000.pam], [4ababc13ae860494d4f512f8ebeca834],
195   [WIDTH = 52], [HEIGHT = 52], [TUPLTYPE = RGB_ALPHA])
196
197 AT_CLEANUP
198
199 # Image with raw frame format
200 AT_SETUP([starbg.lbx.009])
201
202 TEST_UNPACK_MOO2_DATA([fonts.lbx starbg.lbx])
203 AT_CHECK([lbximg -F pam -df starbg.lbx.009 -p fonts.lbx.005])
204 TEST_CHECK_PAM_MD5([out.000.pam],
205   [3b6ccbe3fc46e13c1fa80edf611d7a62],
206   [WIDTH = 61], [HEIGHT = 56], [TUPLTYPE = RGB])
207
208 AT_CLEANUP