#! /bin/bash # Regression test for Xcftools # Copyright (C) 2006 Henning Makholm # # This test script is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General Public # License as published by the Free Software Foundation. # # 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, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA export LC_CTYPE=C export LC_MESSAGES=C : ${XCFTOOLS_PREFIX=../} totaltests=0 failedtests=0 lastfailed=0 keepgoing=0 if [ x"$1" = x"-k" ] then keepgoing=1 fi failed() { if (( lastfailed != totaltests )) then echo FAILED (( lastfailed = totaltests )) (( failedtests++ )) fi (( keepgoing )) || exit 1 } testrun() { if [ x$1 = x--exit ] then want=$2 ; shift ; shift ; else want=0 ; fi (( totaltests++ )) if [ x$2 = x--pipe ] then pgm="$1" pipe="$3" ; shift ; shift ; shift ; echo "===>" $pipe "|" $pgm "$@" $pipe | $pgm "$@" > stdout.txt 2> stderr.txt else echo "===>" "$@" "$@" > stdout.txt 2> stderr.txt fi got=$? if [ $want = $got ] then diff -u expected.stdout stdout.txt || failed diff -u expected.stderr stderr.txt || failed else echo ===STDOUT=== cat stdout.txt echo ===STDERR=== cat stderr.txt echo ===EXIT STATUS=== echo $got failed fi } errtest() { expect=$1 shift program=${XCFTOOLS_PREFIX}$1 shift [ -f expected:stderr ] && \ (sed "1s!^!$program: !" expected:stderr > expected.stderr) testrun --exit $expect $program "$@" } testinfo() { testrun ${XCFTOOLS_PREFIX}xcfinfo "$@" } testpnm() { oanswer='' aanswer='' ofilter=cat afilter=cat oext=pnm while true do arg="`echo $1 | cut -c 3-`" case $arg in -pgm) arg="pnmdepth 255" ;; -ppm) arg="pgmtoppm 1,1,1" ;; esac case $1 in o:*) oanswer="$arg" ;; a:*) aanswer="$arg" ;; O:*) ofilter="$arg" ;; A:*) afilter="$arg" ;; x:*) oext="$arg" ;; *) break ;; esac shift done rm -f o.* a.* [ "$oanswer" ] && pngtopnm answer/$oanswer.png | $ofilter > o.want [ "$aanswer" ] && pngtopnm -alpha answer/$aanswer.png | $afilter > a.want aopt= if [ -n "$aanswer" ] ; then aopt="-aa.pnm" fi source="$1" shift testrun ${XCFTOOLS_PREFIX}xcf2pnm \ -@ -oo.$oext $aopt source/$source.xcf.gz "$@" [ -z "$oanswer" ] || cmp o.want o.$oext || failed [ -z "$aanswer" ] || cmp a.want a.pnm || failed } testpng() { ofilter=cat afilter=cat oargs="" aargs="" while true do arg="`echo $1 | cut -c 3-`" case $arg in -pgm) arg="pnmdepth 255" ;; -ppm) arg="pgmtoppm 1,1,1" ;; esac case $1 in O:*) ofilter="$arg" ;; A:*) afilter="$arg" ;; b:*) oargs="-background $arg -mix" ;; B:*) aargs="-background $arg -mix" ;; *) answer="$1" ; shift ; break ;; esac shift done rm -f o.* a.* [ -s pngtype.want ] || perl pngtype.pl < answer/$answer.png > pngtype.want pngtopnm $aargs answer/$answer.png | $ofilter > o.want pngtopnm -alpha answer/$answer.png | $afilter > a.want source="$1" shift testrun ${XCFTOOLS_PREFIX}xcf2png -oo.png source/$source.xcf.gz "$@" perl pngtype.pl < o.png > pngtype diff -u pngtype.want pngtype || failed pngtopnm $oargs o.png > o.pnm cmp o.want o.pnm || failed if [ "$afilter" != : ] ; then pngtopnm -alpha o.png > a.pnm cmp a.want a.pnm || failed fi rm pngtype.want } rm -f pngtype.want S=source cp /dev/null expected.stdout ############################################################################# # # Test for discovery of error conditions. # echo > expected:stderr \ "The --mode option must follow a layer name on the command line" errtest 20 xcf2pnm $S/modetest.xcf.gz --mode Addition A B echo > expected:stderr \ "The --percent option must follow a layer name on the command line" errtest 20 xcf2png $S/tiletest.xcf.gz --percent 33 Mid echo > expected:stderr \ "The image has no layer called 'MID'" errtest 22 xcf2pnm $S/tiletest.xcf.gz -z Background MID -o foo.pnm # This also tests reading from stdin echo > expected:stderr \ "Layer 'Vert' has no layer mask to enable" errtest 22 xcf2pnm --pipe "zcat $S/tiletest.xcf.gz" \ - Background Vert --mask Horiz --nomask echo > expected:stderr \ "Grayscale output selected, but colored pixel(s) found" errtest 103 xcf2pnm -o o.pgm $S/tiletest.xcf.gz Background errtest 103 xcf2png -o o.png -g $S/tiletest.xcf.gz Background rm -rf o.pgm o.png errtest 103 xcf2pnm -o o.pgm $S/tiletest.xcf.gz Background -f if [ -f o.pgm ] ; then echo o.pgm exists ; failed ; fi errtest 103 xcf2png -o o.png -g $S/tiletest.xcf.gz Background -f if [ -f o.png ] ; then echo o.png exists ; failed ; fi echo > expected:stderr \ "Monochrome output selected, but not all pixels are black or white" errtest 103 xcf2pnm -o o.pbm $S/tiletest.xcf.gz Background errtest 103 xcf2pnm -o o.pbm $S/tiletest.xcf.gz Background \ 'Straight loop' 'Long and low' rm -rf o.pbm errtest 103 xcf2pnm -o o.pbm $S/tiletest.xcf.gz Background -f if [ -f o.pbm ] ; then echo o.pbm exists ; failed ; fi errtest 103 xcf2pnm -o o.pbm $S/tiletest.xcf.gz Background -f \ 'Straight loop' 'Long and low' if [ -f o.pbm ] ; then echo o.pbm exists ; failed ; fi cat > expected:stderr < expected:stderr \ "Flattened image has partially transparent pixels" errtest 102 xcf2pnm $S/modetest.xcf.gz -G cat > expected:stderr < expected.stderr < expected:stderr \ "Transparency found, but -a option not given" errtest 100 xcf2pnm $S/modetest.xcf.gz -o o.pnm echo > expected:stderr \ "The -a option was given, but the image has no transparency" errtest 101 xcf2pnm $S/modetest.xcf.gz -b white -a a.pgm errtest 101 xcf2pnm $S/tiletest.xcf.gz -a a.pgm echo > expected:stderr \ "Only one XCF file per command line, please" errtest 20 xcfinfo $S/tiletest.xcf.gz Background 'Long and low' rm expected:stderr ( for a in /etc/X11/rgb.txt /usr/share/X11/rgb.txt /usr/lib/X11/rgb.txt /-/ ; do [ -f $a ] && break ; [ $a = /-/ ] && echo "Could not find X11 color database" ; done ) > expected.stderr echo "${XCFTOOLS_PREFIX}xcf2pnm: Unknown background color 'Plaid'" \ >> expected.stderr errtest 20 xcf2pnm $S/tiletest.xcf.gz -b Plaid echo > expected:stderr \ "-S option must have an argument of the form wxh" errtest 20 xcf2pnm $S/tiletest.xcf.gz -S 10x errtest 20 xcf2pnm $S/tiletest.xcf.gz -S 10x20x30 echo > expected:stderr \ "-O option must have an argument of the form x,y" errtest 20 xcf2pnm $S/tiletest.xcf.gz -S 10x10 -O 2x4 echo > expected:stderr \ "Layer mode 'GammaShift' is unknown" errtest 20 xcf2png $S/modetest.xcf.gz B A --mode GammaShift echo > expected:stderr \ "The argument to --percent is not a percentage" errtest 20 xcf2pnm $S/tiletest.xcf.gz Background Mid --percent -3 errtest 20 xcf2pnm $S/tiletest.xcf.gz Background Mid --percent 20.2 errtest 20 xcf2pnm $S/tiletest.xcf.gz Background Mid --percent 101 echo > expected:stderr \ "The argument to --opacity is not a number between 0 and 255" errtest 20 xcf2pnm $S/tiletest.xcf.gz Background Mid --opacity -3 errtest 20 xcf2pnm $S/tiletest.xcf.gz Background Mid --opacity 220.2 errtest 20 xcf2pnm $S/tiletest.xcf.gz Background Mid --opacity 256 ####################################################### # # Error tests for io-unix.c # # XXX: if another I/O module is added later, these tests should # be conditionally enabled # cat < enoent.c #include #include int main(int argc,char **argv) { errno = ENOENT; if( argv[1][0] == '!' ) { errno = EACCES; argv++; } perror(argv[1]); return 0; } EOF cp /dev/null expected.stderr testrun cc enoent.c ./a.out $S/nonexist.xcf 2> expected:stderr errtest 21 xcfinfo $S/nonexist.xcf rm expected:stderr ./a.out "Cannot execute source/nonexist.xcf" 2> expected.stderr errtest 126 xcf2png -Z $S/nonexist.xcf $S/tiletest.xcf.gz cp /dev/null expected.stderr command false errtest $? xcf2png -Z false $S/tiletest.xcf.gz ./a.out ! "Cannot execute answer/modeA.png" 2> expected.stderr errtest 126 xcf2pnm -Z answer/modeA.png $S/comptest.xcf.gz rm -f expected:stderr ############################################################################# # # Use all of the example XCF inputs as checks of xcfinfo # cp /dev/null expected.stderr cat < expected.stdout Version 0, 256x256 Grayscale, 2 layers, compressed RLE + 256x256+0+0 Grayscale-alpha Normal Partially transparent + 256x256+0+0 Grayscale Normal Background EOF testinfo $S/comptest.xcf.gz cat < expected.stdout Version 0, 64x64 RGB color, 4 layers, compressed RLE - 10x10+27+27 RGB-alpha Normal AE=AE + 64x64+0+0 RGB-alpha Subtract B + 64x64+0+0 RGB-alpha Addition A - 64x64+0+0 RGB Normal Background EOF testinfo $S/modetest.xcf.gz cat < expected.stdout Version 1, 64x64 Indexed color, 3 layers, compressed RLE + 64x64+0+0 Indexed-alpha Subtract/mask B + 64x64+0+0 Indexed-alpha Addition/mask A - 64x64+0+0 Indexed Normal Background EOF testinfo $S/indextest.xcf.gz testinfo $S/badindexed0.xcf.gz cat < expected.stdout Version 0, 161x161 RGB color, 10 layers, compressed RLE + 122x13+19+74 RGB-alpha Normal Long and low + 13x122+74+19 RGB-alpha Difference Tall and narrow + 118x118+38+47 RGB-alpha Normal/65% Displaced loop - 144x141+4+18 RGB-alpha Normal Doodle + 161x161+0+0 RGB-alpha Normal Straight loop + 50x50+100+105 RGB-alpha Normal/mask Crossed + 50x50+8+8 RGB-alpha Normal Mid + 50x50+8+102 RGB-alpha Normal/83%/mask Horiz + 50x50+101+7 RGB-alpha Normal Vert + 161x161+0+0 RGB Normal Background EOF testinfo $S/tiletest.xcf.gz cat < expected.stdout Version 1, 64x64 Indexed color, 1 layers, compressed RLE + 64x64+0+0 Indexed Normal Background EOF testinfo $S/i256.xcf.gz testinfo $S/i255.xcf.gz cat < expected.stdout Version 0, 32x40 RGB color, 2 layers, compressed RLE + 32x40+0+0 RGB-alpha Hue Hue + 32x40+0+0 RGB Normal Background EOF testinfo $S/huetest.xcf.gz cp /dev/null expected.stdout ############################################################################# ############################################################################# ############################################################################# # # comptest.xcf.gz tests primarily that the scaling tables used during # flattening are internally consistent, such that two pixels of the # same color always composite to that color no matter what the # alpha of the upper one is. testpnm o:comptest comptest testpnm o:comptest comptest Background ############################################################################# # # modetest.xcf.gz is the primary test of the various compositing modes. # testpnm o:Subtract a:modeA modetest testpnm o:Addition a:modeB modetest B A -f for mode in Multiply Screen Overlay Difference DarkenOnly \ LightenOnly Divide Dodge Burn GrainExtract GrainMerge \ Hardlight Hue Saturation Value Color do testpnm o:$mode a:modeA modetest A B --mode $mode done testpnm o:Overlay a:modeA modetest AE=AE A --mode Normal B --mode Softlight # huetest.xcf.gz is an auxiliary test that makes sure that all of the # six hue hexants have matching implementations in RGB->HSV and HSV->RGB testpnm o:huetest huetest ############################################################################# # # tiletest.xcf.gz tests various ways a layer can interact with the # tile boundaries, as well as layer selection, masks, global opacity. # testpnm o:tiletest tiletest testpnm o:tiletest tiletest-128 -O-128,-128 -S 161x161 testpnm o:tiletest tiletest-61 -O-61,-61 testpnm o:gray tiletest-128 Background 'Straight loop' 'Long and low' -C -f testpnm o:gray tiletest-61 Background 'Straight loop' 'Long and low' -C -f ############################################################################# # # Test output format selection for xcf2pnm with and without -f # testpnm o:mono O:-ppm tiletest Background 'Straight loop' testpnm o:mono O:-ppm tiletest Background 'Straight loop' -c testpnm o:mono O:-pgm tiletest Background 'Straight loop' -g testpnm o:mono tiletest Background 'Straight loop' -m testpnm x:ppm o:mono O:-ppm tiletest Background 'Straight loop' testpnm x:pgm o:mono O:-pgm tiletest Background 'Straight loop' testpnm x:pbm o:mono tiletest Background 'Straight loop' testpnm x:pbm o:mono O:-ppm tiletest Background 'Straight loop' -c testpnm o:gray O:-ppm tiletest Background 'Straight loop' 'Long and low' testpnm o:gray tiletest Background 'Straight loop' 'Long and low' -g testpnm o:mono tiletest Background 'Straight loop' -f testpnm o:mono O:-ppm tiletest Background 'Straight loop' -f -c testpnm o:gray tiletest Background 'Straight loop' 'Long and low' -f # Test -A flag testpnm o:mid tiletest -O17,17 -S32x32 Mid testpnm o:mid a:mid A:-pgm tiletest -O17,17 -S32x32 Mid testpnm o:mid tiletest -O17,17 -S32x32 Mid -f testpnm o:mid a:mid tiletest -O17,17 -S32x32 -A testpnm o:mid a:mid A:-pgm tiletest -O17,17 -S32x32 Mid testpnm o:mid a:mid tiletest -O17,17 -S32x32 -Af testpnm o:mid a:mid tiletest -O17,17 -S32x32 Mid -Af ############################################################################# # # Test indexed images # testpnm o:indextest a:indextest indextest testpnm o:indextest a:indextest badindexed0 testpnm o:Subtract a:modeA indextest -T testpnm o:index4 indextest Background testpnm o:index256 i256 ############################################################################# # # Various tests of xcf2pnm # testpnm o:burmid tiletest Mid -S 27x25 -O 5,5 -b '#963' ############################################################################# ############################################################################# # # Tests of xcf2png # # # Basic functionality # testpng tiletest tiletest cat < pngtype.want 64x64x8 color+alpha z0 f0 i0 EOF testpng modeA modetest A ############################################################################# # # Output color-format selection # cat < common 161x161x8 color z0 f0 i0 EOF cp common pngtype.want testpng O:-ppm mono tiletest Background 'Straight loop' cp common pngtype.want testpng O:-ppm mono tiletest Background 'Straight loop' -c cp common pngtype.want testpng O:-ppm mono tiletest Background 'Straight loop' -f -c cp common pngtype.want testpng O:-ppm gray tiletest Background 'Straight loop' 'Long and low' cat < common 161x161x8 gray z0 f0 i0 EOF cp common pngtype.want testpng O:-pgm mono tiletest Background 'Straight loop' -g cp common pngtype.want testpng gray tiletest Background 'Straight loop' 'Long and low' -g cat < pngtype.want 161x161x1 gray z0 f0 i0 EOF testpng mono tiletest Background 'Straight loop' -f cat < pngtype.want 161x161x8 color+index z0 f0 i0 PLTE(60) FF FF FF 00 00 00 B6 B6 B6 A1 A1 A1 81 81 81 51 51 51 2E 2E 2E 80 80 80 E2 E2 E2 41 41 41 30 30 30 12 12 12 0E 0E 0E 0B 0B 0B 13 13 13 2D 2D 2D 7F 7F 7F 40 40 40 50 50 50 6A 6A 6A EOF testpng gray tiletest Background 'Straight loop' 'Long and low' -f ############################################################################# # # Try all combinations of alpha and color modes # # gray testpng gray tiletest Background 'Straight loop' 'Long and low' -g testpng comptest comptest # RGB: The tiletest runs above test this # gray+alpha testpng comptestB comptest 'Partially transparent' -f # RGB+artificial alpha cat < pngtype.want 161x161x8 color+alpha z0 f0 i0 EOF testpng A:-pgm tiletest tiletest -A # RGS+artificial alpha, compressed cat < pngtype.want 161x161x8 color z0 f0 i0 tRNS(6) 00 06 00 06 00 06 EOF testpng tiletest tiletest -A -f # RGB+alpha cat < pngtype.want 16x20x8 color+alpha z0 f0 i0 EOF testpng A:-pgm b:0,0,0 crisp1 modetest -S16x20 -O48,46 -c # gray, one transparent color testpng crisp2 comptest -S25x250 -O235,0 -f -g # RGB, one transparent color cat < pngtype.want 16x20x8 color z0 f0 i0 tRNS(6) 00 01 00 01 00 01 EOF testpng "b:0,0,0" crisp1 modetest -S16x20 -O48,46 -c -f # index, no transparency: palette selection tests test this # index, one transparent color testpng crisp1 modetest -S16x20 -O48,46 -f # index, various transparent colors testpng modeA modetest A -f ############################################################################# # # Special tests for palette selection # # monochrome testpng mono tiletest Background 'Straight loop' -f # monochrome with black and white first met in the opposite order. testpng mono1 tiletest Background -S65x64 -O63,64 -f # 1 color plus transparency testpng doodle tiletest Doodle -f # 2 colors cat < pngtype.want 161x161x1 color+index z0 f0 i0 PLTE(6) FF 00 00 EE 6F 00 EOF testpng A:: B:1,0,0 doodle tiletest Doodle -b '#f00' -f # 2 colors plus transparency testpng odoodle tiletest Doodle 'Straight loop' -f -S5x5 -C # 3 colors cat < pngtype.want 161x161x2 color+index z0 f0 i0 PLTE(9) 00 00 FF EE 6F 00 FF FF FF EOF testpng A:: B:0,0,1 odoodle tiletest Doodle 'Straight loop' -fb '#00F' -O0,0 -C # 4 colors cat < pngtype.want 64x64x2 color+index z0 f0 i0 PLTE(12) DC 98 85 FF 00 77 10 36 38 FF B4 23 EOF testpng index4 indextest Background -f # 4 colors, artificial transparency cat < pngtype.want 64x64x2 color+index z0 f0 i0 PLTE(12) DC 98 85 FF 00 77 10 36 38 FF B4 23 tRNS(4) FF FF FF FF EOF testpng index4 indextest Background -f -A # 16 colors, no transparency testpng mid tiletest -O17,17 -S32x32 -f # 17 colors, including a background testpng burmid tiletest Mid -O5,5 -S27x25 -b '#963' -f # 38 colors, original colormap testpng index4 indextest Background # 255 colors, original colormap testpng index255 i255 # 255 colors plus transparency testpng i255t i255 -O0,2 testpng i255t i255 -O0,2 -f testpng i255tt i255 -O2,0 -f perl pngtype.pl < answer/index256.png > pngtype.want testpng A:"tr '\377' '\0'" B:"#F4F4F4" i255t i255 -O0,2 -b "#F4F4F4" # 255 colors, background already in palette perl pngtype.pl < answer/index255.png > pngtype.want testpng A:"tr '\3' '\0'" B:"#66CC33" i255tt i255 -O2,0 -b "#6c3" # 256 colors, original colormap testpng index256 i256 # 256 colors, no room for transparency cat < pngtype.want 64x64x8 color+alpha z0 f0 i0 EOF testpng A:-pgm index256 i256 -A ############################################################################# # # Various tests for regression of bugs that slipped through the # systematic testing. # # Exotic modes with an opaque layer testpnm o:misc1 a:misc1 tiletest Mid Crossed \ Background --mode LightenOnly 'Straight loop' -f ############################################################################# # # Report the final status echo ======================================================= if (( failedtests )) then echo $failedtests of $totaltests tests FAILED echo ======================================================= exit 1 else echo All $totaltests tests PASSED echo ======================================================= exit 0 fi # End