summaryrefslogtreecommitdiffstats
path: root/test/dotest
blob: eded0e05d66e1e83e52f0bebc3deb14b1a7cb499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
#! /bin/bash

# Regression test for Xcftools
#
# This file was written by Henning Makholm <henning@makholm.net>
# It is hereby in the public domain.
# 
# In jurisdictions that do not recognise grants of copyright to the
# public domain: I, the author and (presumably, in those jurisdictions)
# copyright holder, hereby permit anyone to distribute and use this code,
# in source code or binary form, with or without modifications. This
# permission is world-wide and irrevocable.
#
# Of course, I will not be liable for any errors or shortcomings in the
# code, since I give it away without asking any compenstations.
#
# If you use or distribute this code, I would appreciate receiving
# credit for writing it, in whichever way you find proper and customary.

export LC_CTYPE=C
export LC_MESSAGES=C
export LC_ALL=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 <<EOF
The image contains features not understood by this program:
 'AntiErase' layer mode
EOF
errtest 123 xcf2pnm $S/modetest.xcf.gz A B --mode AntiErase

echo > expected:stderr \
    "Flattened image has partially transparent pixels"
errtest 102 xcf2pnm $S/modetest.xcf.gz -G

cat > expected:stderr <<EOF
Corrupted or malformed XCF file:
 Not an XCF file at all (magic not recognized)
EOF
errtest 125 xcfinfo answer/modeA.png

rm expected:stderr
cat > expected.stderr <<EOF
Warning: XCF version 345 not supported (trying anyway...)
${XCFTOOLS_PREFIX}xcf2png: Corrupted or truncated XCF file
 (0x1C7 bytes): Overlong property at 82
EOF
errtest 125 xcf2png $S/truncated.xcf

echo > 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 <<EOF > enoent.c
#include <errno.h>
#include <stdio.h>
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 <<EOF > 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 <<EOF > 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 <<EOF > 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 <<EOF > 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 <<EOF > 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 <<EOF > 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'

#   Regression test for bugs fixed in 1.0.6

testpnm o:masknoalpha-r masknoalpha -b "#FF0000"
testpnm o:masknoalpha-g masknoalpha -b "#888888"
testpnm o:masknoalpha-b masknoalpha -b "#000000"
testpnm o:masknoalpha-w masknoalpha -b "#FFFFFF"

#############################################################################
#############################################################################
#
#   Tests of xcf2png
#

#
#   Basic functionality
#

testpng tiletest tiletest
cat <<EOF > pngtype.want
64x64x8
color+alpha
z0 f0 i0
EOF
testpng modeA modetest A

#############################################################################
#
#   Output color-format selection
#

cat <<EOF > 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 <<EOF > 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 <<EOF > pngtype.want
161x161x1
gray
z0 f0 i0
EOF
testpng mono tiletest Background 'Straight loop' -f

cat <<EOF > 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 <<EOF > pngtype.want
161x161x8
color+alpha
z0 f0 i0
EOF
testpng A:-pgm tiletest tiletest -A

# RGS+artificial alpha, compressed
cat <<EOF > pngtype.want
161x161x8
color
z0 f0 i0
tRNS(6)
 00 06 00 06 00 06
EOF
testpng tiletest tiletest -A -f

# RGB+alpha
cat <<EOF > 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 <<EOF > 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 <<EOF > 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 <<EOF > 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 <<EOF > 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 <<EOF > 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 <<EOF > 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