xref: /potrace-1.14/check/postscript-check.sh (revision b3fce824)
1#! /bin/sh
2
3# Copyright (C) 2001-2017 Peter Selinger.
4# This file is part of Potrace. It is free software and it is covered
5# by the GNU General Public License. See the file COPYING for details.
6
7# If ghostscript is present, we attempt to render the postscript
8# output and check it for accuracy.
9
10if test -z "$srcdir"; then
11    srcdir=.
12fi
13
14. "$srcdir/missing.sh"
15
16GS=`my_which ghostscript`
17if test -z "$GS"; then
18    GS=`my_which gs`
19fi
20if test -z "$GS"; then
21    echo "Don't have ghostscript, skipping PostScript test." >& 2
22    exit 77
23fi
24
25echo "Checking PostScript output..." >& 2
26
27NAME=`basename "$0"`
28
29POTRACE="${CHECK_POTRACE:-../src/potrace$EXEEXT --progress}"
30DATADIR="$srcdir/data"
31PGMDIFF="./pgmdiff$EXEEXT"
32TMPDIR="${TEMPDIR:-/tmp}"
33TMP1=`mktemp "$TMPDIR/$NAME-1.XXXXXX"`
34TMP2=`mktemp "$TMPDIR/$NAME-2.XXXXXX"`
35DATA="$DATADIR/data1.pbm"
36REFDATA="$DATADIR/data1.pbm.gs"
37REFDATAROT="$DATADIR/data1.pbm.rot"
38
39# run the command, expecting return value 0
40action () {
41    "$@"
42    if test $? -ne 0; then
43	echo "$NAME: test failed" >& 2
44	echo "Failed command: $LINE: $@" >& 2
45	exit 1
46    fi
47}
48
49actiondiff () {
50    D=`action "$PGMDIFF" "$1" "$2"`
51    # check return value because subshell can't exit
52    if test $? -ne 0; then
53	exit 1;
54    fi
55    echo "Difference: $D" >& 2
56    if test "$D" -gt "$3"; then
57	echo "$NAME: test failed" >& 2
58	echo "Failed command: $LINE: $PGMDIFF $1 $2" >& 2
59	exit 1;
60    fi
61}
62
63# keep track of line numbers
64alias action="LINE=\$LINENO; action"
65alias actiondiff="LINE=\$LINENO; actiondiff"
66
67action $POTRACE -r50 -p -L 0 -B 0 -o "$TMP1" "$DATA"
68"$GS" -q -dNOPAUSE -sDEVICE=pbmraw -g460x394 -r100x100 -sOutputFile="$TMP2" -- "$TMP1"
69if test $? -ne 0; then
70    echo "Something is wrong with $GS; skipping this test" >& 2
71    exit 77
72fi
73actiondiff "$TMP2" "$REFDATA" 1000
74
75action $POTRACE -r50 -p -L 0 -B 0 --opaque -o "$TMP1" "$DATA"
76action "$GS" -q -dNOPAUSE -sDEVICE=pbmraw -g460x394 -r100x100 -sOutputFile="$TMP2" -- "$TMP1"
77actiondiff "$TMP2" "$REFDATA" 1200
78
79action $POTRACE -r50 -p -L 0 -B 0 -A 160 -o "$TMP1" "$DATA"
80action "$GS" -q -dNOPAUSE -sDEVICE=pbmraw -g568x528 -r100x100 -sOutputFile="$TMP2" -- "$TMP1"
81actiondiff "$TMP2" "$REFDATAROT" 1200
82
83action rm -f "$TMP1"
84action rm -f "$TMP2"
85
86echo "$NAME: test succeeded" >& 2
87exit 0
88