Skip to content

Commit 1db6ff7

Browse files
author
giraffedata
committed
Factor out 'test invalid' checks
git-svn-id: https://svn.code.sf.net/p/netpbm/code/trunk@4837 9d0c8265-081b-0410-96cb-a4ca84ce46f8
1 parent f1dc6eb commit 1db6ff7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+506
-1832
lines changed

test/Execute-Tests

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ esac
5050
# invoke, the list of tests to run ('Test-Order'), and *.ok files that
5151
# indicate the expected results of tests.
5252

53-
srcdir=$(dirname $0)
53+
export srcdir=$(dirname $0)
5454

5555
# Set tmpdir, which is used in some of the test scripts. By default
5656
# this is created by mktemp. The user can override and specify tmpdir,

test/pamarith.test

+54-204
Original file line numberDiff line numberDiff line change
@@ -116,142 +116,68 @@ for image in maze.pbm ${input1_ppm}
116116

117117
rm ${input1_ppm}
118118

119-
echo "Invalid command-line argument combinations." 1>&2
120-
echo "Error messages should appear below the line." 1>&2
121-
echo "-----------------------------------------------------------" 1>&2
122-
123119
echo "Test Invalid"
124120

125-
test_out=${tmpdir}/test_out
121+
. ${srcdir}/test-invalid.inc
126122

127123
# multiple functions
128124

129-
pamarith -add -subtract testimg.ppm testimg.ppm > ${test_out} || \
130-
printf "Expected failure 1 "
131-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
132-
rm -f ${test_out}
133-
134-
pamarith -multiply -divide testimg.ppm testimg.ppm > ${test_out} || \
135-
printf "Expected failure 2 "
136-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
137-
rm -f ${test_out}
138-
139-
pamarith -difference -minimum testimg.ppm testimg.ppm > ${test_out} || \
140-
printf "Expected failure 3 "
141-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
142-
rm -f ${test_out}
143-
144-
pamarith -maximum -mean testimg.ppm testimg.ppm > ${test_out} || \
145-
printf "Expected failure 4 "
146-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
147-
rm -f ${test_out}
148-
149-
pamarith -compare -and testimg.ppm testimg.ppm > ${test_out} || \
150-
printf "Expected failure 5 "
151-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
152-
rm -f ${test_out}
153-
154-
pamarith -compare -equal testimg.ppm testimg.ppm > ${test_out} || \
155-
printf "Expected failure 6 "
156-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
157-
rm -f ${test_out}
158-
159-
pamarith -or -nand testimg.ppm testimg.ppm > ${test_out} || \
160-
printf "Expected failure 7 "
161-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
162-
rm -f ${test_out}
163-
164-
pamarith -nor -xor testimg.ppm testimg.ppm > ${test_out} || \
165-
printf "Expected failure 8 "
166-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
167-
rm -f ${test_out}
168-
169-
pamarith -shiftleft -shiftright testimg.ppm testimg.ppm > ${test_out} || \
170-
printf "Expected failure 9 "
171-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
172-
rm -f ${test_out}
125+
invCmd "pamarith -add -subtract testimg.ppm testimg.ppm"
126+
invCmd "pamarith -multiply -divide testimg.ppm testimg.ppm"
127+
invCmd "pamarith -difference -minimum testimg.ppm testimg.ppm"
128+
invCmd "pamarith -maximum -mean testimg.ppm testimg.ppm"
129+
invCmd "pamarith -compare -and testimg.ppm testimg.ppm"
130+
invCmd "pamarith -compare -equal testimg.ppm testimg.ppm"
131+
invCmd "pamarith -or -nand testimg.ppm testimg.ppm"
132+
invCmd "pamarith -nor -xor testimg.ppm testimg.ppm"
133+
invCmd "pamarith -shiftleft -shiftright testimg.ppm testimg.ppm"
173134

174135
# -add does not take a value
175136

176-
pamarith -add=1 testimg.ppm testimg.ppm > ${test_out} || \
177-
printf "Expected failure 10 "
178-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
179-
rm -f ${test_out}
137+
invCmd "pamarith -add=1 testimg.ppm testimg.ppm"
180138

181139
# No function
182140

183-
pamarith -plain testimg.ppm testimg.ppm > ${test_out} || \
184-
printf "Expected failure 11 "
185-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
186-
rm -f ${test_out}
187-
188-
pamarith testimg.ppm testimg.ppm > ${test_out} || \
189-
printf "Expected failure 12 "
190-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
191-
rm -f ${test_out}
141+
invCmd "pamarith -plain testimg.ppm testimg.ppm"
142+
invCmd "pamarith testimg.ppm testimg.ppm"
192143

193144
# Just one input image file
194145

195-
pamarith -add testimg.ppm > ${test_out} || \
196-
printf "Expected failure 13 "
197-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
198-
rm -f ${test_out}
146+
invCmd "pamarith -add testimg.ppm"
199147

200148
# No input image file
201149

202-
pamarith -add > ${test_out} || \
203-
printf "Expected failure 14 "
204-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
205-
rm -f ${test_out}
150+
invCmd "pamarith -add"
206151

207152
# Input images with different depth (number of planes)
208153

209-
pamchannel -infile testimg.ppm 0 1 | \
210-
pamarith -add testimg.ppm - > ${test_out} || \
211-
printf "Expected failure 15 "
212-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
213-
rm -f ${test_out}
154+
input1_pam=${tmpdir}/input1.pam
214155

215-
# Input images with different x/y dimensions
156+
pamchannel -infile testimg.ppm 0 1 > ${input1_pam}
157+
invCmd "pamarith -add testimg.ppm ${input1_pam}"
158+
rm ${input1_pam}
216159

217-
pamarith -add testimg.ppm testgrid.pbm > ${test_out} || \
218-
printf "Expected failure 16 "
219-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
220-
rm -f ${test_out}
221-
222-
pamenlarge -xscale=2 testgrid.pbm | \
223-
pamarith -add testgrid.pbm - > ${test_out} || \
224-
printf "Expected failure 17 "
225-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
226-
rm -f ${test_out}
160+
# Input images with different x/y dimensions
227161

228-
pamenlarge -yscale=3 testgrid.pbm | \
229-
pamarith -add testgrid.pbm - > ${test_out} || \
230-
printf "Expected failure 18 "
231-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
232-
rm -f ${test_out}
162+
invCmd "pamarith -add testimg.ppm testgrid.pbm"
233163

234-
# Invalid usage of -closeness
164+
input1_pbm=${tmpdir}/input1.pbm
165+
input2_pbm=${tmpdir}/input2.pbm
235166

236-
pamarith -equal -closeness=100.1 testgrid.pbm > ${test_out} || \
237-
printf "Expected failure 19 "
238-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
239-
rm -f ${test_out}
167+
pamenlarge -xscale=2 testgrid.pbm > ${input1_pbm}
168+
invCmd "pamarith -add testgrid.pbm ${input1_pbm}"
169+
rm ${input1_pbm}
240170

241-
pamarith -equal -closeness=-10 testgrid.pbm > ${test_out} || \
242-
printf "Expected failure 20 "
243-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
244-
rm -f ${test_out}
171+
pamenlarge -yscale=3 testgrid.pbm > ${input2_pbm}
172+
invCmd "pamarith -add testgrid.pbm ${input2_pbm}"
173+
rm ${input2_pbm}
245174

246-
pamarith -closeness -equal testgrid.pbm > ${test_out} || \
247-
printf "Expected failure 21 "
248-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
249-
rm -f ${test_out}
175+
# Invalid usage of -closeness
250176

251-
pamarith -compare -closeness=10 testgrid.pbm > ${test_out} || \
252-
printf "Expected failure 22 "
253-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
254-
rm -f ${test_out}
177+
invCmd "pamarith -equal -closeness=100.1 testgrid.pbm"
178+
invCmd "pamarith -equal -closeness=-10 testgrid.pbm"
179+
invCmd "pamarith -closeness -equal testgrid.pbm"
180+
invCmd "pamarith -compare -closeness=10 testgrid.pbm"
255181

256182
# Bit string functions
257183
# Create PGM test input
@@ -266,113 +192,37 @@ pgmmake -maxval=8191 1.0 3 1 > ${input5_pgm}
266192

267193
# Bit string functions - Maxval must match
268194

269-
pamarith -and ${input3_pgm} ${input5_pgm} > ${test_out} || \
270-
printf "Expected failure 23 "
271-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
272-
rm -f ${test_out}
273-
274-
pamarith -or ${input3_pgm} ${input5_pgm} > ${test_out} || \
275-
printf "Expected failure 24 "
276-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
277-
rm -f ${test_out}
278-
279-
pamarith -nand ${input3_pgm} ${input5_pgm} > ${test_out} || \
280-
printf "Expected failure 25 "
281-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
282-
rm -f ${test_out}
283-
284-
pamarith -nor ${input3_pgm} ${input5_pgm} > ${test_out} || \
285-
printf "Expected failure 26 "
286-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
287-
rm -f ${test_out}
288-
289-
pamarith -xor ${input3_pgm} ${input5_pgm} > ${test_out} || \
290-
printf "Expected failure 27 "
291-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
292-
rm -f ${test_out}
195+
invCmd "pamarith -and ${input3_pgm} ${input5_pgm}"
196+
invCmd "pamarith -or ${input3_pgm} ${input5_pgm}"
197+
invCmd "pamarith -nand ${input3_pgm} ${input5_pgm}"
198+
invCmd "pamarith -nor ${input3_pgm} ${input5_pgm}"
199+
invCmd "pamarith -xor ${input3_pgm} ${input5_pgm}"
293200

294201
# Bit string functions - Maxval must be 2^n -1
295202

296-
pamarith -and ${input4_pgm} ${input4_pgm} > ${test_out} || \
297-
printf "Expected failure 28 "
298-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
299-
rm -f ${test_out}
300-
301-
pamarith -or ${input4_pgm} ${input4_pgm} > ${test_out} || \
302-
printf "Expected failure 29 "
303-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
304-
rm -f ${test_out}
305-
306-
pamarith -nand ${input4_pgm} ${input4_pgm} > ${test_out} || \
307-
printf "Expected failure 30 "
308-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
309-
rm -f ${test_out}
310-
311-
pamarith -nor ${input4_pgm} ${input4_pgm} > ${test_out} || \
312-
printf "Expected failure 31 "
313-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
314-
rm -f ${test_out}
315-
316-
pamarith -xor ${input4_pgm} ${input4_pgm} > ${test_out} || \
317-
printf "Expected failure 32 "
318-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
319-
rm -f ${test_out}
320-
321-
pamarith -shiftleft ${input4_pgm} ${input4_pgm} > ${test_out} || \
322-
printf "Expected failure 33 "
323-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
324-
rm -f ${test_out}
325-
326-
pamarith -shiftright ${input4_pgm} ${input4_pgm} > ${test_out} || \
327-
printf "Expected failure 34 "
328-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
329-
rm -f ${test_out}
203+
invCmd "pamarith -and ${input4_pgm} ${input4_pgm}"
204+
invCmd "pamarith -or ${input4_pgm} ${input4_pgm}"
205+
invCmd "pamarith -nand ${input4_pgm} ${input4_pgm}"
206+
invCmd "pamarith -nor ${input4_pgm} ${input4_pgm}"
207+
invCmd "pamarith -xor ${input4_pgm} ${input4_pgm}"
208+
invCmd "pamarith -shiftleft ${input4_pgm} ${input4_pgm}"
209+
invCmd "pamarith -shiftright ${input4_pgm} ${input4_pgm}"
330210

331211
rm ${input3_pgm} ${input4_pgm} ${input5_pgm}
332212

333213
# Functions that do not allow more than two input images.
334214
# Only the functions that are commutative and associative allow
335215
# three or more inputs.
336216

337-
pamarith -subtract testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
338-
printf "Expected failure 35 "
339-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
340-
rm -f ${test_out}
341-
342-
pamarith -divide testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
343-
printf "Expected failure 36 "
344-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
345-
rm -f ${test_out}
346-
347-
pamarith -compare testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
348-
printf "Expected failure 37 "
349-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
350-
rm -f ${test_out}
351-
352-
pamarith -difference testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
353-
printf "Expected failure 38 "
354-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
355-
rm -f ${test_out}
356-
357-
pamarith -shiftleft testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
358-
printf "Expected failure 39 "
359-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
360-
rm -f ${test_out}
361-
362-
pamarith -shiftright testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
363-
printf "Expected failure 40 "
364-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
365-
rm -f ${test_out}
217+
invCmd "pamarith -subtract testimg.ppm testimg.ppm testimg.ppm"
218+
invCmd "pamarith -divide testimg.ppm testimg.ppm testimg.ppm"
219+
invCmd "pamarith -compare testimg.ppm testimg.ppm testimg.ppm"
220+
invCmd "pamarith -difference testimg.ppm testimg.ppm testimg.ppm"
221+
invCmd "pamarith -shiftleft testimg.ppm testimg.ppm testimg.ppm"
222+
invCmd "pamarith -shiftright testimg.ppm testimg.ppm testimg.ppm"
366223

367224
# Currently -equal and -mean do not allow more than two input images.
368225
# These two cases should be removed once improvements are made.
369226

370-
pamarith -equal testgrid.pbm testgrid.pbm testgrid.pbm > ${test_out} || \
371-
printf "Expected failure 41 "
372-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
373-
rm -f ${test_out}
374-
375-
pamarith -mean testgrid.pbm testgrid.pbm testgrid.pbm > ${test_out} || \
376-
printf "Expected failure 42 "
377-
test -s ${test_out} && echo "unexpected output" || echo "(no output)"
378-
rm -f ${test_out}
227+
invCmd "pamarith -equal testgrid.pbm testgrid.pbm testgrid.pbm"
228+
invCmd "pamarith -mean testgrid.pbm testgrid.pbm testgrid.pbm"

test/pambrighten.ok

+8-16
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,11 @@ Test 4: Should print 3990234518 268 six times
7878
3990234518 268
7979
3990234518 268
8080
3990234518 268
81-
Test Error: Should print 1 six times
82-
1
83-
1
84-
1
85-
1
86-
1
87-
1
88-
Test Error: Should print 99 followed by 1, four times
89-
99
90-
1
91-
99
92-
1
93-
99
94-
1
95-
99
96-
1
81+
Test Invalid
82+
Expected failure 1 (no output)
83+
Expected failure 2 (no output)
84+
Expected failure 3 (no output)
85+
Expected failure 4 (no output)
86+
Expected failure 5 (no output)
87+
Expected failure 6 (no output)
88+
Expected failure 7 (no output)

0 commit comments

Comments
 (0)