File indexing completed on 2024-12-22 04:04:06

0001 #! /bin/sh
0002 
0003 # Copyright (C) 2001-2019 Peter Selinger.
0004 # This file is part of Potrace. It is free software and it is covered
0005 # by the GNU General Public License. See the file COPYING for details.
0006 
0007 # If ghostscript is present, we attempt to render the PDF
0008 # output and check it for accuracy.
0009 
0010 if test -z "$srcdir"; then
0011     srcdir=.
0012 fi
0013 
0014 . "$srcdir/missing.sh"
0015 
0016 GS=`my_which ghostscript`
0017 if test -z "$GS"; then
0018     GS=`my_which gs`
0019 fi
0020 if test -z "$GS"; then
0021     echo "Don't have ghostscript, skipping PDF test." >& 2
0022     exit 77
0023 fi
0024 
0025 echo "Checking PDF output..." >& 2
0026 
0027 NAME=`basename "$0"`
0028 
0029 POTRACE="${CHECK_POTRACE:-../src/potrace$EXEEXT --progress}"
0030 DATADIR="$srcdir/data"
0031 PGMDIFF="./pgmdiff$EXEEXT"
0032 TMPDIR="${TEMPDIR:-/tmp}"
0033 TMP1=`mktemp "$TMPDIR/$NAME-1.XXXXXX"`
0034 TMP2=`mktemp "$TMPDIR/$NAME-2.XXXXXX"`
0035 DATA="$DATADIR/data1.pbm"
0036 REFDATA="$DATADIR/data1.pbm.gs"
0037 REFDATAROT="$DATADIR/data1.pbm.rot"
0038 
0039 # run the command, expecting return value 0
0040 action () {
0041     "$@"
0042     if test $? -ne 0; then
0043         echo "$NAME: test failed" >& 2
0044         echo "Failed command: $LINE: $@" >& 2
0045         exit 1
0046     fi
0047 }
0048 
0049 actiondiff () {
0050     D=`action "$PGMDIFF" "$1" "$2"`
0051     # check return value because subshell can't exit
0052     if test $? -ne 0; then 
0053         exit 1; 
0054     fi
0055     echo "Difference: $D" >& 2
0056     if test "$D" -gt "$3"; then
0057         echo "$NAME: test failed" >& 2
0058         echo "Failed command: $LINE: $PGMDIFF $1 $2" >& 2
0059         exit 1;
0060     fi
0061 }
0062 
0063 # keep track of line numbers
0064 alias action="LINE=\$LINENO; action"
0065 alias actiondiff="LINE=\$LINENO; actiondiff"
0066 
0067 action rm -f "$TMP2"
0068 
0069 action $POTRACE -r50 -p -L 0 -B 0 -b pdf -o "$TMP1" "$DATA"
0070 "$GS" -q -dNOPAUSE -sDEVICE=pbmraw -g460x394 -r100x100 -sOutputFile="$TMP2" -- "$TMP1"
0071 if test $? -ne 0 -o ! -f "$TMP2"; then
0072     echo "GS does not understand PDF; skipping this test" >& 2
0073     exit 77
0074 fi 
0075 actiondiff "$TMP2" "$REFDATA" 2000
0076 
0077 action $POTRACE -r50 -p -L 0 -B 0 --opaque -b pdf -o "$TMP1" "$DATA"
0078 action "$GS" -q -dNOPAUSE -sDEVICE=pbmraw -g460x394 -r100x100 -sOutputFile="$TMP2" -- "$TMP1"
0079 actiondiff "$TMP2" "$REFDATA" 2000
0080 
0081 action $POTRACE -r50 -p -L 0 -B 0 -A 160 -b pdf -o "$TMP1" "$DATA"
0082 action "$GS" -q -dNOPAUSE -sDEVICE=pbmraw -g568x528 -r100x100 -sOutputFile="$TMP2" -- "$TMP1"
0083 actiondiff "$TMP2" "$REFDATAROT" 2000
0084 
0085 action rm -f "$TMP1"
0086 action rm -f "$TMP2"
0087 
0088 echo "$NAME: test succeeded" >& 2
0089 exit 0