summaryrefslogtreecommitdiff
path: root/src/cups/test-rastertogutenprint.in
blob: a8bb6d881dbb2afc7b393f1d4db0c9b650cbfc93 (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
#!@SHELL@

retval=0

if [ -z "$srcdir" -o "$srcdir" = "." ] ; then
    sdir=`pwd`
elif [ -n "`echo $srcdir |grep '^/'`" ] ; then
    sdir="$srcdir"
else
    sdir="`pwd`/$srcdir"
fi

if [ -z "$STP_DATA_PATH" ] ; then
    STP_DATA_PATH="$sdir/../xml"
    export STP_DATA_PATH
fi

if [ -z "$STP_MODULE_PATH" ] ; then
    STP_MODULE_PATH="$sdir/../main:$sdir/../main/.libs"
    export STP_MODULE_PATH
fi

single=''
all_models=''
verbose=''
valgrind=0
make_ppds=1
md5dir=''
outdir=''
cupsargs=''
postscript=''
npages=3
enable_static='@ENABLE_STATIC@'
enable_shared='@ENABLE_SHARED@'

if [ -r "$sdir/../../src/cups/gutenprint-users-manual.pdf" ] ; then
    testfile="$sdir/../../src/cups/gutenprint-users-manual.pdf"
else
    testfile="$sdir/../../doc/gutenprint-users-manual.pdf"
fi

usage() {
    echo "Usage: test-rastertogutenprint [-s] [-v|--valgrind]"
    exit 0;
}

set_args() {
    while true ; do
	case "$1" in
	    -s) single=1 ;;
	    -h*|--h*) usage ;;
	    -v|--valgrind) valopts='--tool=memcheck' ; valgrind=$((valgrind + 1)) ;;
	    -c|--cachegrind) valopts='--tool=cachegrind'; valgrind=4 ;;
	    -g|--gdb-attach) valopts='--gdb-attach=yes' ;;
	    -V|--verbose) verbose=1 ;;
	    -n|--no-make-ppds) make_ppds='' ;;
	    -O|--output) shift; outdir="$1" ;;
	    -o|--option) shift; cupsargs="$cupsargs $1" ;;
	    -m|--md5dir) shift; md5dir="$1" ;;
	    -p|--pages) shift; npages="$1" ;;
	    -P|--postscript) shift; postscript=1 ;;
	    --) shift; args="$@"; return ;;
	    *) return ;;
	esac
    shift
    done
}

set_args `getopt hvcgsVnO:m:o:p: "$@"`

if [ "$valgrind" -gt 0 -a "$enable_shared" != "no" ] ; then
    echo 'Valgrind is not compatible with --enable-shared in tree.' 1>&2
    echo 'Please use autogen.sh --disable-shared.' 1>&2
    exit 1
fi

if [ -n "$outdir" -a ! -d "$outdir" ] ; then
    mkdir -p "$outdir"
fi
if [ -n "$md5dir" -a ! -d "$md5dir" ] ; then
    mkdir -p "$md5dir"
fi

version="5.2";
cupsdir="/usr/lib/cups/filter"
if [ -x "$cupsdir/pstoraster" -o -x "$cupsdir/gstoraster" -o -x "$cupsdir/cgpdftoraster" ] ; then
    pages="24-`expr 24 + $npages - 1`"
    if [ -n "$postscript" ] ; then
	pages="page-ranges=$pages"
    fi
else
    pages=''
fi

if [ ! -x "$cupsdir/cgpdftoraster" -a ! -x "$cupsdir/pdftops" -a ! -x "$cupsdir/gstoraster" ] ; then
    echo 'CUPS does not appear to be installed, skipping test'
    exit 0
fi

cleanup() {
    if [ -f "$tfile" ] ; then
	rm -f $tfile
    fi
    exit 1
}

pdfjam="`which pdfjam`"
if [ -z "$pdfjam" ] ; then
    postscript=1
fi

if [ -n "$postscript" ] ; then
    pdftops="`type -p pdftops`"

    if [ ! -n "$pdftops" -o ! -x "$pdftops" ] ; then
	pdftops="`whence pdftops`"
    fi

    if [ -n "$pdftops" -a ! -x "$cupsdir/cgpdftoraster" ] ; then
	tfile=`mktemp`
	trap cleanup 1 2 3 6 14 15 30
	"$pdftops" -f 24 -l `expr 24 + $npages - 1` "$testfile" $tfile
    fi
else
    tfile=`mktemp`
    trap cleanup 1 2 3 6 14 15 30
    "$pdfjam" -q "$testfile" "$pages" -o $tfile
fi    

if [ -z "$verbose" ] ; then
    STP_SUPPRESS_MESSAGES=1
    export STP_SUPPRESS_MESSAGES
fi

is_duplicate() {
    model=`gunzip -c "$1" | grep '^.StpDriverModelFamily' | awk '{print $2}'`
    for m in $all_models; do
	if [ "$model" = "$m" ] ; then
	    skip=1
	fi
    done
    all_models="$model $all_models"
}

# Note that using CUPS arguments may trigger valgrind memory leaks in
# CUPS.
#cupsargs='PageSize=Custom.400.00x500.00'
#cupsargs='PageSize=Custom.324x495 Resolution=180dpi'
#cupsargs='PageSize=w324h495 Resolution=180dpi'
#cupsargs='PageSize=A8'

run_rastertogp() {
    case "$valgrind" in
	1) valgrind $valopts -q --log-fd=3 --num-callers=50 --leak-check=yes --error-limit=no ./rastertogutenprint.$version 1 1 1 1 "$cupsargs" ;;
	2) valgrind $valopts --log-fd=3 --num-callers=50 --leak-resolution=high --leak-check=yes --error-limit=no ./rastertogutenprint.$version 1 1 1 1 "$cupsargs" ;;
	3) valgrind $valopts --log-fd=3 --error-limit=no --num-callers=50 --show-reachable=yes --leak-resolution=high --leak-check=yes ./rastertogutenprint.$version 1 1 1 1 "$cupsargs" ;;
	4) valgrind $valopts --log-fd=3 ./rastertogutenprint.$version 1 1 1 1 "$cupsargs" ;;
	5) cat ;;
	*) ./rastertogutenprint.$version 1 1 1 1 "$cupsargs" ;;
    esac
    if [ $? -ne 0 ] ; then
	retval=1
    fi
    exit $retval
}

get_ppds() {
    args="$@"
    if [ -n "$args" ] ; then
	for f in "$@" ; do
	    if [ -r "$f" ] ; then
		echo $f
	    elif [ -r "ppd/C/$f" ] ; then
		echo "ppd/C/$f"
	    elif [ -f "ppd/C/${f}.ppd" ] ; then
		echo "ppd/C/${f}.ppd"
	    elif [ -f "ppd/C/${f}.ppd.gz" ] ; then
		echo "ppd/C/${f}.ppd.gz"
	    elif [ -f "ppd/C/${f}.ppd.GZ" ] ; then
		echo "ppd/C/${f}.ppd.GZ"
	    elif [ -f "ppd/C/${f}.ppd.bz2" ] ; then
		echo "ppd/C/${f}.ppd.bz2"
	    elif [ -f "ppd/C/${f}.ppd.BZ2" ] ; then
		echo "ppd/C/${f}.ppd.BZ2"
	    elif [ -f "ppd/C/${f}.ppd.z" ] ; then
		echo "ppd/C/${f}.ppd.z"
	    elif [ -f "ppd/C/${f}.ppd.Z" ] ; then
		echo "ppd/C/${f}.ppd.Z"
	    elif [ -f "ppd/C/stp-${f}.ppd" ] ; then
		echo "ppd/C/stp-${f}.ppd"
	    elif [ -f "ppd/C/stp-${f}.ppd.gz" ] ; then
		echo "ppd/C/stp-${f}.ppd.gz"
	    elif [ -f "ppd/C/stp-${f}.ppd.GZ" ] ; then
		echo "ppd/C/stp-${f}.ppd.GZ"
	    elif [ -f "ppd/C/stp-${f}.ppd.bz2" ] ; then
		echo "ppd/C/stp-${f}.ppd.bz2"
	    elif [ -f "ppd/C/stp-${f}.ppd.BZ2" ] ; then
		echo "ppd/C/stp-${f}.ppd.BZ2"
	    elif [ -f "ppd/C/stp-${f}.ppd.z" ] ; then
		echo "ppd/C/stp-${f}.ppd.z"
	    elif [ -f "ppd/C/stp-${f}.ppd.Z" ] ; then
		echo "ppd/C/stp-${f}.ppd.Z"
	    elif [ -f "ppd/C/stp-${f}.${version}.ppd" ] ; then
		echo "ppd/C/stp-${f}.${version}.ppd"
	    elif [ -f "ppd/C/stp-${f}.${version}.ppd.gz" ] ; then
		echo "ppd/C/stp-${f}.${version}.ppd.gz"
	    elif [ -f "ppd/C/stp-${f}.${version}.ppd.GZ" ] ; then
		echo "ppd/C/stp-${f}.${version}.ppd.GZ"
	    elif [ -f "ppd/C/stp-${f}.${version}.ppd.bz2" ] ; then
		echo "ppd/C/stp-${f}.${version}.ppd.bz2"
	    elif [ -f "ppd/C/stp-${f}.${version}.ppd.BZ2" ] ; then
		echo "ppd/C/stp-${f}.${version}.ppd.BZ2"
	    elif [ -f "ppd/C/stp-${f}.${version}.ppd.z" ] ; then
		echo "ppd/C/stp-${f}.${version}.ppd.z"
	    elif [ -f "ppd/C/stp-${f}.${version}.ppd.Z" ] ; then
		echo "ppd/C/stp-${f}.${version}.ppd.Z"
	    fi
	done
    else
	echo ppd/C/*.ppd*
    fi
}

if [ -n "$make_ppds" -o ! -d ppd/C ] ; then
    make ppd-nonls
## Not all systems can work with gzipped PPDs
    find ppd/C -name '*.ppd.gz' | xargs gunzip -f
fi

do_output() {
    if [ -n "`echo "$PPD" |grep '\.gz$'`" ] ; then
	driver=`gunzip -c "$PPD" | grep '^\*StpDriverName:' |awk '{print $2}' | sed 's/"//g'`
    else
	driver=`grep '^\*StpDriverName:' "$PPD" |awk '{print $2}' | sed 's/"//g'`
    fi
    if [ -n "$outdir" ] ; then
	cat > "$outdir/$driver.prn"
	if [ -n "$md5dir" ] ; then
	    (cd "$outdir"; cat "$driver.prn") | md5sum | sed "s/-/\*$driver/" > "$md5dir/$driver.md5"
	fi
    elif [ -n "$md5dir" ] ; then
	cat | md5sum | sed "s/-/\*$driver/" > "$md5dir/$driver.md5"
    else
	cat > /dev/null
    fi
}

if [ -d ppd/C ] ; then
    for f in `get_ppds $args` ; do
	skip=''
	if [ -n "$single" ] ; then
	    is_duplicate $f
	fi
	if [ -z "$skip" ] ; then
	    echo -n "`basename $f |sed -e 's/stp-//' -e 's/@GUTENPRINT_RELEASE_VERSION@.ppd.*$//'`... "
	    PPD=$f
	    export PPD
	    if [ -x "$cupsdir/cgpdftoraster" ] ; then
		output="`($cupsdir/cgpdftoraster 1 1 1 1 $pages < "$testfile" 2>/dev/null | run_rastertogp | do_output) 2>&1 3>&2 `"
	    elif [ -f "$tfile" -a -x "$cupsdir/gstoraster" ] ; then
		output="`($cupsdir/gstoraster 1 1 1 1 \"$cupsargs\" < "$testfile" 2>/dev/null | run_rastertogp | do_output) 2>&1 3>&2 `"
	    elif [ -f "$tfile" ] ; then
		output="`($cupsdir/pstops 1 1 1 1 \"$cupsargs\" < "$testfile" 2>/dev/null | $cupsdir/pstoraster 2>/dev/null | run_rastertogp | do_output) 2>&1 3>&2 `"
	    elif [ -x "$cupsdir/pstoraster" ] ; then
		output="`($cupsdir/pdftops 1 1 1 1 \"$pages$cupsargs\" < "$testfile" 2>/dev/null | $cupsdir/pstops 1 1 1 1 \"$pages$cupsargs\" 2>/dev/null | $cupsdir/pstoraster 2>/dev/null | run_rastertogp | do_output) 2>&1 3>&2 `"
	    elif [ -x "$cupsdir/gstoraster" ] ; then
		output="`($cupsdir/pdftops 1 1 1 1 \"$pages$cupsargs\" < "$testfile" 2>/dev/null | $cupsdir/gstoraster 1 1 1 1 \"$pages$cupsargs\" 2>/dev/null | run_rastertogp | do_output) 2>&1 3>&2 `"
	    else
		output="`($cupsdir/imagetoraster 1 1 1 1 \"$pages$cupsargs\" < calibrate.ppm 2>/dev/null | run_rastertogp | do_output) 2>&1 3>&2`"
	    fi
	    if [ $? -ne 0 ] ; then
		retval=1
	    fi
	    echo "$output"
	    echo "$output" |grep ERROR
	    if [ $? -eq 0 ] ; then
		retval=1
	    fi
	fi
    done
fi
if [ -f "$tfile" ] ; then
    rm -f $tfile
fi
exit $retval