about summary refs log tree commit diff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Test-Order10
-rwxr-xr-xtest/pamtosvg.test2
-rwxr-xr-xtest/pbmtext-iso88591.test11
-rwxr-xr-xtest/pbmtext-utf8.test10
-rwxr-xr-xtest/pgmnoise.test2
-rw-r--r--test/pnmindex.ok28
-rwxr-xr-xtest/pnmindex.test60
-rw-r--r--test/pnmpad-color.ok222
-rwxr-xr-xtest/pnmpad-color.test446
-rw-r--r--test/pnmpad-extend-enlarge.ok163
-rwxr-xr-xtest/pnmpad-extend-enlarge.test177
-rw-r--r--test/pnmpad-flip.ok64
-rwxr-xr-xtest/pnmpad-flip.test62
-rw-r--r--test/pnmpad-format.ok135
-rwxr-xr-xtest/pnmpad-format.test245
-rw-r--r--test/pnmpad-pnmmargin.ok15
-rwxr-xr-xtest/pnmpad-pnmmargin.test79
-rw-r--r--test/pnmpad-reportonly.ok8
-rwxr-xr-xtest/pnmpad-reportonly.test31
-rw-r--r--test/pnmquantall.ok9
-rwxr-xr-xtest/pnmquantall.test44
-rw-r--r--test/ppmforge.ok2
-rwxr-xr-xtest/ppmforge.test40
-rwxr-xr-xtest/ppmpat-random.test6
-rwxr-xr-xtest/random-generator.test3
-rwxr-xr-xtest/stdin-pnm1.test2
26 files changed, 1818 insertions, 58 deletions
diff --git a/test/Test-Order b/test/Test-Order
index 05742ac0..6c21c759 100644
--- a/test/Test-Order
+++ b/test/Test-Order
@@ -89,8 +89,13 @@ pnminvert.test
 pamchannel.test
 ppmchange.test
 pambackground.test
+
 pnmpad-reportonly.test
-pnmpaste-pbm.test
+pnmpad-flip.test
+pnmpad-extend-enlarge.test
+pnmpad-pnmmargin.test
+pnmpad-format.test
+pnmpad-color.test
 
 pamrestack.test
 pamshuffle.test
@@ -113,6 +118,8 @@ ppmdim.test
 pnmshear.test
 pgmbentley.test
 
+pnmindex.test
+
 pamfunc.test
 pamarith.test
 pamarith-compare-equal.test
@@ -275,3 +282,4 @@ jpeg-roundtrip.test
 lps-roundtrip.test
 tiffcmyk-roundtrip.test
 yuv-roundtrip.test
+
diff --git a/test/pamtosvg.test b/test/pamtosvg.test
index 332040ea..4acf1fd9 100755
--- a/test/pamtosvg.test
+++ b/test/pamtosvg.test
@@ -40,6 +40,6 @@ EOF
 
 echo "Test 2.  Should print match"
 
-pamtosvg testgrid.pbm | tee /tmp/a2 |\
+pamtosvg testgrid.pbm |\
     cmp -s ${testgrid_svg} - && echo "match" || echo "no match"
 rm ${testgrid_svg}
diff --git a/test/pbmtext-iso88591.test b/test/pbmtext-iso88591.test
index e8dec8d2..1472b89e 100755
--- a/test/pbmtext-iso88591.test
+++ b/test/pbmtext-iso88591.test
@@ -13,14 +13,15 @@ tmpdir=${tmpdir:-/tmp}
 iso88591_locale_list=${tmpdir}/iso88591_locale_list
 
 locale_to_test="en_US.iso88591"  # Initial value; this
-# does not have to be present in
-# Edit the above value if necessary
+# does not have to be actually available.
+# Edit the above value if you have a preferred locale.
 
-# Make a list of available locales which end in "iso88591"
+# Make a list of available locales which end in "iso88591" etc.
 # If none are found, abort test
 
-locale -a | grep "\.iso88591$" > ${iso88591_locale_list} ||\
-    locale_to_test=""
+locale -a |\
+    grep -e "\.iso88591$" -e "\.iso-8859-1$" -e "\.ISO-8859-1$" \
+	 > ${iso88591_locale_list} || locale_to_test=""
 
 # Hunt for a valid iso-8859-1 locale
 # Submit each candidate to a trial pbmtext run until one that works is
diff --git a/test/pbmtext-utf8.test b/test/pbmtext-utf8.test
index a10b3d33..551cfe29 100755
--- a/test/pbmtext-utf8.test
+++ b/test/pbmtext-utf8.test
@@ -20,14 +20,14 @@ tmpdir=${tmpdir:-/tmp}
 utf_locale_list=${tmpdir}/utf_locale_list
 
 locale_to_test="en_US.utf8"  # Initial value; this
-# does not have to be present in  following list
-# Edit the above value if necessary
+# does not have to be actually available.
+# Edit the above value if you have a preferred locale.
 
-# Make a list of available locales which end in "utf8"
+# Make a list of available locales which end in "utf8" etc.
 # If none are found, abort test
 
-locale -a | grep "\.utf8$" > ${utf_locale_list} ||\
-    locale_to_test=""
+locale -a | grep -e "\.utf8$" -e "\.utf-8$" -e "\.UTF-8$" \
+    > ${utf_locale_list} || locale_to_test=""
 
 # Hunt for a valid utf8 locale
 # Submit each candidate to a trial pbmtext run until one that works is
diff --git a/test/pgmnoise.test b/test/pgmnoise.test
index ed41622f..36f16ab0 100755
--- a/test/pgmnoise.test
+++ b/test/pgmnoise.test
@@ -4,8 +4,6 @@
 
 echo "Test 1."
 echo "Should print: 2132901423 10015" # (Mersenne Twister)
-#                   1663614689 10015 (Glibc rand())
-#                   3516404574 10015 (MAC OS rand())
 pgmnoise --randomseed=0 100 100 | cksum
 
 
diff --git a/test/pnmindex.ok b/test/pnmindex.ok
new file mode 100644
index 00000000..15d01639
--- /dev/null
+++ b/test/pnmindex.ok
@@ -0,0 +1,28 @@
+Test 1. Should print 3391481002 889
+3391481002 889
+Test 2. Should print 1998876959 5290 twice
+1998876959 5290
+1998876959 5290
+Test 3. Should print 3099638253 5290
+3099638253 5290
+Test 4. Should print 1397700642 3160
+1397700642 3160
+Test 5. Should print 2303488589 28514
+2303488589 28514
+Test 6. Should print 1706277976 100455
+1706277976 100455
+Test 7. Should print 801388440 100455
+801388440 100455
+Test Invalid
+Expected failure 1 (no output)
+Expected failure 2 (no output)
+Expected failure 3 (no output)
+Expected failure 4 (no output)
+Expected failure 5 (no output)
+Expected failure 6 (no output)
+Expected failure 7 (no output)
+Expected failure 8 (no output)
+Expected failure 9 (no output)
+Expected failure 10 (no output)
+Expected failure 11 (no output)
+Expected failure 12 (no output)
diff --git a/test/pnmindex.test b/test/pnmindex.test
new file mode 100755
index 00000000..51e61532
--- /dev/null
+++ b/test/pnmindex.test
@@ -0,0 +1,60 @@
+#! /bin/sh
+# This script tests: pnmindex
+# Also requires: pamcat pamscale pbmtext pnmcolormap pnmindex
+# Also requires: pnminvert pnmquant pnmremap 
+
+echo "Test 1. Should print 3391481002 889"
+pnmindex maze.pbm | cksum
+
+echo "Test 2. Should print 1998876959 5290 twice"
+pnmindex maze.pbm maze.pbm maze.pbm maze.pbm maze.pbm maze.pbm | cksum
+pnmindex -noquant maze.pbm maze.pbm maze.pbm maze.pbm maze.pbm maze.pbm | cksum
+
+echo "Test 3. Should print 3099638253 5290"
+pnmindex -black maze.pbm maze.pbm maze.pbm maze.pbm maze.pbm maze.pbm | cksum
+
+echo "Test 4. Should print 1397700642 3160"
+pnmindex -size 20 -across=3 testgrid.pbm testgrid.pbm testgrid.pbm \
+         testgrid.pbm testgrid.pbm testgrid.pbm | cksum
+
+echo "Test 5. Should print 2303488589 28514"
+pnmindex testimg.ppm | cksum
+
+echo "Test 6. Should print 1706277976 100455"
+pnmindex -size 50 -across=2 testimg.ppm testimg.ppm testimg.ppm \
+         testimg.ppm testimg.ppm testimg.ppm | cksum
+
+echo "Test 7. Should print 801388440 100455"
+pnmindex -size 50 -across=2 -noquant testimg.ppm testimg.ppm testimg.ppm \
+         testimg.ppm testimg.ppm testimg.ppm | cksum
+
+
+echo "Test Invalid"
+
+test_out=${tmpdir}/test_out
+n=1
+
+# define function
+invalidCmd () { $1 > ${test_out} && printf "Unexpected success $n " || \
+  printf "Expected failure $n "
+  test -s ${test_out} && echo "(unexpected output)" || echo "(no output)"
+  rm -f ${test_out}
+  n=$(($n + 1)); }
+
+echo 1>&2
+echo "Invalid command-line arguments." 1>&2
+echo "Error messages should appear below the line." 1>&2
+echo "-----------------------------------------------------------" 1>&2
+
+invalidCmd "pnmindex -size -1 testgrid.pbm"
+invalidCmd "pnmindex -size  0 testgrid.pbm"
+invalidCmd "pnmindex -size    testgrid.pbm"
+invalidCmd "pnmindex -across -1 testgrid.pbm"
+invalidCmd "pnmindex -across  0 testgrid.pbm"
+invalidCmd "pnmindex -across    testgrid.pbm"
+invalidCmd "pnmindex -colors -1 testgrid.pbm"
+invalidCmd "pnmindex -colors  0 testgrid.pbm"
+invalidCmd "pnmindex -colors    testgrid.pbm"
+invalidCmd "pnmindex -quant -noquant testgrid.pbm"
+invalidCmd "pnmindex -colors 100 -noquant testgrid.pbm"
+invalidCmd "pnmindex"
diff --git a/test/pnmpad-color.ok b/test/pnmpad-color.ok
new file mode 100644
index 00000000..91e3b264
--- /dev/null
+++ b/test/pnmpad-color.ok
@@ -0,0 +1,222 @@
+Test 1. PBM white infile
+Should print match seven times
+match
+match
+match
+match
+match
+match
+match
+Should print match seven times
+match
+match
+match
+match
+match
+match
+match
+Should print match once
+match
+Should print match once
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match once
+match
+Should print match twice
+match
+match
+
+Test 2. PBM black infile
+Should print match nine times
+match
+match
+match
+match
+match
+match
+match
+match
+match
+Should print match five times
+match
+match
+match
+match
+match
+
+Test 3. PGM maxval 127 infile
+Should print match five times
+match
+match
+match
+match
+match
+Should print match four times
+match
+match
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match once
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match once
+match
+Should print match twice
+match
+match
+
+Test 4. PGM maxval 255 infile
+Should print match five times
+match
+match
+match
+match
+match
+Should print match four times
+match
+match
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match once
+match
+Should print match four times
+match
+match
+match
+match
+Should print match four times
+match
+match
+match
+match
+Should print match three times
+match
+match
+match
+
+Test 5. PGM maxval 511 infile
+Should print match five times
+match
+match
+match
+match
+match
+Should print match four times
+match
+match
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match once
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match three times
+match
+match
+match
+
+Test 6. PPM maxval 127 infile
+Should print match five times
+match
+match
+match
+match
+match
+Should print match four times
+match
+match
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match once
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+
+Test 7. PPM maxval 511 infile
+Should print match five times
+match
+match
+match
+match
+match
+Should print match four times
+match
+match
+match
+match
+Should print match six times
+match
+match
+match
+match
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
+Should print match twice
+match
+match
diff --git a/test/pnmpad-color.test b/test/pnmpad-color.test
new file mode 100755
index 00000000..05e8acca
--- /dev/null
+++ b/test/pnmpad-color.test
@@ -0,0 +1,446 @@
+#! /bin/sh
+# This script tests: pnmpad
+# Also requires: pbmmake pgmmake ppmmake pamcut ppmtopgm
+
+tmpdir=${tmpdir:-/tmp}
+
+white_pbm=${tmpdir}/white.pbm
+black_pbm=${tmpdir}/black.pbm
+test127_pgm=${tmpdir}/testimg1.pgm
+test255_pgm=${tmpdir}/testimg2.pgm
+test511_pgm=${tmpdir}/testimg3.pgm
+test127_ppm=${tmpdir}/testimg1.ppm
+test255_ppm=${tmpdir}/testimg2.ppm
+test511_ppm=${tmpdir}/testimg3.ppm
+target_pnm=${tmpdir}/target.pnm
+
+BLACK="rgbi:0.0/0.0/0.0"
+WHITE="rgbi:1.0/1.0/1.0"
+LIGHTGRAY="rgbi:0.6/0.6/0.6"
+LIGHTGRAYv=0.6
+DARKGRAY="rgbi:0.01/0.01/0.01"
+DARKGRAYv=0.01
+PURPLE="rgb:A0/20/F0"
+YELLOW="rgb:F0/F0/00"
+
+pbmmake -w 1 1 > ${white_pbm}
+pbmmake -b 1 1 > ${black_pbm}
+pgmmake 0.25 1 1 -maxval 127 > ${test127_pgm}
+pgmmake 0.25 1 1 -maxval 255 > ${test255_pgm}
+pgmmake 0.25 1 1 -maxval 511 > ${test511_pgm}
+ppmmake ${YELLOW} 1 1 -maxval 127 > ${test127_ppm}
+ppmmake ${YELLOW} 1 1 -maxval 255 > ${test255_ppm}
+ppmmake ${YELLOW} 1 1 -maxval 511 > ${test511_ppm}
+
+ptop="-top 1"
+
+# define function
+cmptarget () { pamcut -top 0 -left 0 -height 1 -width 1 $@ |\
+                cmp -s ${target_ppm} - && echo "match" || echo "failure";  }
+
+echo "Test 1. PBM white infile"
+
+infile=${white_pbm}
+
+echo "Should print match seven times"
+
+pbmmake -w 1 1 > ${target_pnm}
+pnmpad ${ptop} -white ${infile} | cmptarget
+pnmpad ${ptop} -extend-edge ${infile} | cmptarget
+pnmpad ${ptop} -detect-background ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote format ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY}  -promote none   ${infile} | cmptarget
+
+echo "Should print match seven times"
+
+pbmmake -b 1 1 > ${target_pnm}
+pnmpad ${ptop} ${infile} | cmptarget
+pnmpad ${ptop} -black ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote format ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE}   -promote none ${infile} | cmptarget
+
+echo "Should print match once"
+
+pgmmake -maxval 1 ${LIGHTGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match once"
+
+pgmmake -maxval 1 ${DARKGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 255 ${LIGHTGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY} ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote all ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 255 ${DARKGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY} ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote all ${infile} | cmptarget
+
+echo "Should print match once"
+
+ppmmake -maxval 1 ${PURPLE} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${PURPLE} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 255 ${PURPLE} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${PURPLE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE} -promote all ${infile} | cmptarget
+
+echo
+echo "Test 2. PBM black infile"
+
+infile=${black_pbm}
+
+echo "Should print match nine times"
+
+pbmmake -b 1 1 > ${target_pnm}
+pnmpad ${ptop} ${infile} | cmptarget
+pnmpad ${ptop} -black ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote format ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE}   -promote none ${infile} | cmptarget
+pnmpad ${ptop} -extend-edge ${infile} | cmptarget
+pnmpad ${ptop} -detect-background ${infile} | cmptarget
+
+echo "Should print match five times"
+
+pbmmake -w 1 1 > ${target_pnm}
+pnmpad ${ptop} -white ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote format ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote none ${infile} | cmptarget
+
+echo
+echo "Test 3. PGM maxval 127 infile"
+
+infile=${test127_pgm}
+
+echo "Should print match five times"
+
+pgmmake -maxval 127 0.0 1 1 > ${target_pnm}
+pnmpad ${ptop} ${infile} | cmptarget
+pnmpad ${ptop} -black ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote format ${infile} | cmptarget
+
+echo "Should print match four times"
+
+pgmmake -maxval 127 1.0 1 1 > ${target_pnm}
+pnmpad ${ptop} -white ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pamcut -t 0 -h 1 -w 1 ${infile} > ${target_pnm}
+pnmpad ${ptop} -extend-edge ${infile} | cmptarget
+pnmpad ${ptop} -detect-background ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 127 ${LIGHTGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 127 ${DARKGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match once"
+
+ppmmake -maxval 127 ${PURPLE} 1 1 | ppmtopgm > ${target_pnm} 
+pnmpad ${ptop} -color ${PURPLE}   -promote none ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 255 ${LIGHTGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY}              ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote all ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 255 ${DARKGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY}              ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote all ${infile} | cmptarget
+
+echo "Should print match once"
+
+ppmmake -maxval 127 ${PURPLE} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${PURPLE} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 255 ${PURPLE} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${PURPLE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE} -promote all    ${infile} | cmptarget
+
+
+echo
+echo "Test 4. PGM maxval 255 infile"
+
+infile=${test255_pgm}
+
+echo "Should print match five times"
+
+pgmmake -maxval 255 0.0 1 1 > ${target_pnm}
+pnmpad ${ptop} ${infile} | cmptarget
+pnmpad ${ptop} -black ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote format ${infile} | cmptarget
+
+echo "Should print match four times"
+
+pgmmake -maxval 255 1.0 1 1 > ${target_pnm}
+pnmpad ${ptop} -white ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pamcut -t 0 -h 1 -w 1 ${infile} > ${target_pnm}
+pnmpad ${ptop} -extend-edge ${infile} | cmptarget
+pnmpad ${ptop} -detect-background ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 255 ${LIGHTGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 255 ${DARKGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match once"
+
+ppmmake -maxval 255  ${PURPLE} 1 1 | ppmtopgm > ${target_pnm}
+pnmpad ${ptop} -color ${PURPLE}   -promote none ${infile} | cmptarget
+
+echo "Should print match four times"
+
+pgmmake -maxval 255 ${LIGHTGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY}                 ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote format ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote all    ${infile} | cmptarget
+
+echo "Should print match four times"
+
+pgmmake -maxval 255 ${DARKGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY}                 ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote format ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote all    ${infile} | cmptarget
+
+echo "Should print match three times"
+
+ppmmake -maxval 255 ${PURPLE} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${PURPLE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE} -promote format ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE} -promote all    ${infile} | cmptarget
+
+echo
+echo "Test 5. PGM maxval 511 infile"
+
+infile=${test511_pgm}
+
+echo "Should print match five times"
+
+pgmmake -maxval 511 0.0 1 1 > ${target_pnm}
+pnmpad ${ptop} ${infile} | cmptarget
+pnmpad ${ptop} -black ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote format ${infile} | cmptarget
+
+echo "Should print match four times"
+
+pgmmake -maxval 511 1.0 1 1 > ${target_pnm}
+pnmpad ${ptop} -white ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pamcut -t 0 -h 1 -w 1 ${infile} > ${target_pnm}
+pnmpad ${ptop} -extend-edge ${infile} | cmptarget
+pnmpad ${ptop} -detect-background ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 511 ${LIGHTGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 511 ${DARKGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match once"
+
+ppmmake -maxval 511 ${PURPLE} 1 1 | ppmtopgm > ${target_pnm}
+pnmpad ${ptop} -color ${PURPLE} -promote none ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 511 ${LIGHTGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY}              ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote all ${infile} | cmptarget
+
+echo "Should print match twice"
+
+pgmmake -maxval 511 ${DARKGRAYv} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY}              ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote all ${infile} | cmptarget
+
+echo "Should print match three times"
+
+ppmmake -maxval 511 ${PURPLE} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${PURPLE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE} -promote format ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE} -promote all    ${infile} | cmptarget
+
+
+echo
+echo "Test 6. PPM maxval 127 infile"
+
+infile=${test127_ppm}
+
+echo "Should print match five times"
+
+ppmmake -maxval 127 ${BLACK} 1 1 > ${target_pnm}
+pnmpad ${ptop} ${infile} | cmptarget
+pnmpad ${ptop} -black ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote format ${infile} | cmptarget
+
+echo "Should print match four times"
+
+ppmmake -maxval 127 ${WHITE} 1 1 > ${target_pnm}
+pnmpad ${ptop} -white ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 127 ${PURPLE} 1 1 > ${target_pnm}
+ppmmake -maxval 127 ${PURPLE} 1 2 | pnmpad ${ptop} -extend-edge | cmptarget
+ppmmake -maxval 127 ${PURPLE} 1 2 | pnmpad ${ptop} -detect-background | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 127 ${LIGHTGRAY} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 127 ${DARKGRAY} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match once"
+
+ppmmake -maxval 127 ${PURPLE} 1 1 > ${target_pnm} 
+pnmpad ${ptop} -color ${PURPLE} -promote none ${infile} | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 255 ${LIGHTGRAY} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY}                  ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY}     -promote all ${infile} | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 255 ${DARKGRAY} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY}              ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote all ${infile} | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 255 ${PURPLE} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${PURPLE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE} -promote all ${infile} | cmptarget
+
+echo
+echo "Test 7. PPM maxval 511 infile"
+
+infile=${test511_ppm}
+
+echo "Should print match five times"
+
+ppmmake -maxval 511 ${BLACK} 1 1 > ${target_pnm}
+pnmpad ${ptop} ${infile} | cmptarget
+pnmpad ${ptop} -black ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${BLACK} -promote format ${infile} | cmptarget
+
+echo "Should print match four times"
+
+ppmmake -maxval 511 ${WHITE} 1 1 > ${target_pnm}
+pnmpad ${ptop} -white ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote none   ${infile} | cmptarget
+pnmpad ${ptop} -color ${WHITE} -promote format ${infile} | cmptarget
+
+echo "Should print match six times"
+
+ppmmake -maxval 511 ${PURPLE} 1 1 > ${target_pnm}
+ppmmake -maxval 511 ${PURPLE} 1 5 | pnmpad ${ptop} -extend-edge | cmptarget
+ppmmake -maxval 511 ${PURPLE} 1 5 | pnmpad ${ptop} -detect-background | cmptarget
+pnmpad ${ptop} -color ${PURPLE} ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE} -promote format ${infile} | cmptarget
+pnmpad ${ptop} -color ${PURPLE} -promote all    ${infile} | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 511 ${LIGHTGRAY} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 511 ${DARKGRAY} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY} -promote none ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote format ${infile} | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 511 ${LIGHTGRAY} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${LIGHTGRAY}                  ${infile} | cmptarget
+pnmpad ${ptop} -color ${LIGHTGRAY}     -promote all ${infile} | cmptarget
+
+echo "Should print match twice"
+
+ppmmake -maxval 511 ${DARKGRAY} 1 1 > ${target_pnm}
+pnmpad ${ptop} -color ${DARKGRAY}              ${infile} | cmptarget
+pnmpad ${ptop} -color ${DARKGRAY} -promote all ${infile} | cmptarget
diff --git a/test/pnmpad-extend-enlarge.ok b/test/pnmpad-extend-enlarge.ok
new file mode 100644
index 00000000..d1539022
--- /dev/null
+++ b/test/pnmpad-extend-enlarge.ok
@@ -0,0 +1,163 @@
+Test 1.  Should print match forty-eight (24x2) times
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+Test 2.  Should print match thirty-six (18x2) times
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+Test 3.  Should print match twenty-four (4x6) times
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+Test 4.  Should print match eighteen (3x6) times
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+Test 5.  Should print match thirty-two (8x4) times
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
diff --git a/test/pnmpad-extend-enlarge.test b/test/pnmpad-extend-enlarge.test
new file mode 100755
index 00000000..fde609a6
--- /dev/null
+++ b/test/pnmpad-extend-enlarge.test
@@ -0,0 +1,177 @@
+#! /bin/sh
+# This script tests: pnmpad pamenlarge
+# Also requires: pamcat pamcut pamenlarge pbmmake pbmnoise pgmmake pgmnoise
+# Also requires: ppmmake ppmpat
+
+# If the padding function for -extend-edge is altered, make sure to run this
+# test in a more thorough form.  Replace "for leftpad in 0 1 7 9 16"
+# with "for leftpad in `seq 0 16`".
+
+tmpdir=${tmpdir:-/tmp}
+test_pnm=${tmpdir}/test.pnm
+
+padded_pnm=${tmpdir}/padded.pnm
+#middle_pnm=${tmpdir}/middle.pnm
+left_pnm=${tmpdir}/left.pnm
+right_pnm=${tmpdir}/right.pnm
+top_pnm=${tmpdir}/top.pnm
+bottom_pnm=${tmpdir}/bottom.pnm
+
+echo "Test 1.  Should print match forty-eight (24x2) times"
+
+for generator in "pbmnoise -randomseed=100 17 17" \
+                 "ppmpat -tartan -randomseed=100 11 11"          
+    do
+    ${generator} > ${test_pnm}
+    for leftpad in 0 1 7 9 16
+    do
+        for rightpad in  0 1 8
+        do
+            pnmpad -extend-edge -l=${leftpad} -r=${rightpad} ${test_pnm} > ${padded_pnm}
+            pamcut -left=0 -width=1 ${test_pnm} |\
+                pamenlarge -xscale=$(( ${leftpad} + 1 )) > ${left_pnm}
+            pamcut -right=-1 -width=1  ${test_pnm} |\
+                pamenlarge -xscale=$(( ${rightpad} + 1 )) > ${right_pnm}
+            pamcut -cropleft=1 -cropright=1 ${test_pnm} |\
+                pamcat -lr ${left_pnm} - ${right_pnm} |\
+                cmp -s - ${padded_pnm} && echo "match" ||\
+                    echo "no match: lr ${generator} ${leftpad} ${rightpad}";
+            rm ${left_pnm} ${right_pnm} ${padded_pnm}
+        done
+    done
+    
+    for toppad in 0 2 5
+    do
+        for bottompad in  0 1 10
+        do
+            pnmpad -extend-edge -t=${toppad} -b=${bottompad} ${test_pnm} > ${padded_pnm}
+            pamcut -top=0 -height=1 ${test_pnm} |\
+                pamenlarge -yscale=$(( ${toppad} + 1 )) > ${top_pnm}
+            pamcut -bottom=-1 -height=1  ${test_pnm} |\
+                pamenlarge -yscale=$(( ${bottompad} + 1 )) > ${bottom_pnm}
+            pamcut -croptop=1 -cropbottom=1 ${test_pnm} |\
+            pamcat -tb ${top_pnm} - ${bottom_pnm} |\
+                cmp -s - ${padded_pnm} && echo "match" ||\
+                    echo "no match: tb ${generator} ${toppad} ${bottompad}";
+            rm ${top_pnm} ${bottom_pnm} ${padded_pnm}
+        done
+    done
+    rm ${test_pnm}
+done
+
+
+echo "Test 2.  Should print match thirty-six (18x2) times"
+
+for generator in "pbmnoise -randomseed=100 17 17" \
+                 "ppmpat -tartan -randomseed=100 11 11"
+    do
+    ${generator} > ${test_pnm}
+    for leftpad in 0 1 2
+    do
+        for rightpad in  0 1 3
+        do
+            pnmpad -extend-edge -l=${leftpad} -r=${rightpad} ${test_pnm} > ${padded_pnm}
+            pamcut -left=0 -width=1 ${test_pnm} |\
+                pamenlarge -xscale=$(( ${leftpad} + 1 )) > ${left_pnm}
+            pamcut -right=-1 -width=1  ${test_pnm} |\
+                pamenlarge -xscale=$(( ${rightpad} + 1 )) > ${right_pnm}
+            pamcut -cropleft=1 -cropright=1 ${test_pnm} |\
+                pamcat -lr ${left_pnm} - ${right_pnm} |\
+                cmp -s - ${padded_pnm} && echo "match" ||\
+                    echo "no match: lr ${generator} ${leftpad} ${rightpad}";
+            rm ${left_pnm} ${right_pnm} ${padded_pnm}
+        done
+    done
+    
+    for toppad in 0 1 12
+    do
+        for bottompad in 0 1 5
+        do
+            pnmpad -extend-edge -t=${toppad} -b=${bottompad} ${test_pnm} > ${padded_pnm}
+            pamcut -top=0 -height=1 ${test_pnm} |\
+                pamenlarge -yscale=$(( ${toppad} + 1 )) > ${top_pnm}
+            pamcut -bottom=-1 -height=1  ${test_pnm} |\
+                pamenlarge -yscale=$(( ${bottompad} + 1 )) > ${bottom_pnm}
+            pamcut -croptop=1 -cropbottom=1 ${test_pnm} |\
+                pamcat -tb ${top_pnm} - ${bottom_pnm} |\
+                cmp -s - ${padded_pnm} && echo "match" ||\
+                    echo "no match: tb ${generator} ${toppad} ${bottompad}";
+            rm ${top_pnm} ${bottom_pnm} ${padded_pnm}
+        done
+    done
+    rm ${test_pnm}
+done
+
+
+echo "Test 3.  Should print match twenty-four (4x6) times"
+
+stretch_pnm=${tmpdir}/stretch.pnm
+
+for generator in "pbmmake -b 1 1" \
+                 "pbmmake -b 1 11" \
+                 "pbmmake -w 1 1" \
+                 "pbmmake -w 1 8" \
+                 "pbmnoise -randomseed=100 1 17" \
+                 "pgmnoise -randomseed=100 1 12"                 
+    do
+        ${generator} > ${test_pnm}
+     pamenlarge -xscale=17 ${test_pnm} > ${stretch_pnm} 
+        
+    for leftpad in 0 1 7 16
+    do
+        pnmpad -extend-edge -l=${leftpad} -r=$((16 - ${leftpad})) ${test_pnm} |\
+                cmp -s - ${stretch_pnm} && echo "match" ||\
+                    echo "no match: ${generator} ${leftpad}";
+    done
+    rm ${stretch_pnm} ${test_pnm}
+done
+
+
+echo "Test 4.  Should print match eighteen (3x6) times"
+
+stretch_pnm=${tmpdir}/stretch.pnm
+
+for generator in "pbmmake -b 1 1" \
+                 "pbmmake -b 8 1" \
+                 "pbmmake -w 1 1" \
+                 "pbmmake -w 3 1" \
+                 "pbmnoise -randomseed=100 17 1" \
+                 "pgmnoise -randomseed=100 8 1"          
+    do
+        ${generator} > ${test_pnm}
+     pamenlarge -yscale=15 ${test_pnm} > ${stretch_pnm} 
+        
+    for toppad in  0 1 14
+    do
+        pnmpad -extend-edge -t=${toppad} -b=$((14 - ${toppad})) ${test_pnm} |\
+                cmp -s - ${stretch_pnm} && echo "match" ||\
+                    echo "no match: ${generator} ${toppad}";
+    done
+    rm ${stretch_pnm} ${test_pnm}
+done
+
+
+echo "Test 5.  Should print match thirty-two (8x4) times"
+
+stretch_pnm=${tmpdir}/stretch.pnm
+
+for generator in "pbmmake -b 1 1" \
+                 "pbmmake -w 1 1" \
+                 "pgmmake 0.3 1 1" \
+                 "ppmmake rgbi:0.5/0.3/0.8 1 1"
+    do
+        ${generator} > ${test_pnm}
+        pamenlarge -xscale=66 -yscale=10 ${test_pnm} > ${stretch_pnm}
+        
+    for toppad in  0 8
+    do
+    for leftpad in  0 1 15 64
+    do
+        pnmpad -extend-edge -t=${toppad} -b=$((9 - ${toppad})) \
+         -l=${leftpad} -r=$((65 - ${leftpad})) ${test_pnm} |\
+                cmp -s - ${stretch_pnm} && echo "match" ||\
+                echo "no match: ${generator} ${toppad} ${leftpad}"
+    done
+    done
+    rm ${stretch_pnm} ${test_pnm}
+done
diff --git a/test/pnmpad-flip.ok b/test/pnmpad-flip.ok
new file mode 100644
index 00000000..af596ad3
--- /dev/null
+++ b/test/pnmpad-flip.ok
@@ -0,0 +1,64 @@
+Test 1.  Should print match sixteen (8x2) times
+(pbmnoise -randomseed=100 11 16)
+match
+match
+match
+match
+match
+match
+match
+match
+(pgmnoise -randomseed=100 31 41)
+match
+match
+match
+match
+match
+match
+match
+match
+Test 2.  Should print match forty (10x4) times
+(pbmmake -b 1 1)
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+(pbmmake -w 1 1)
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+(pbmmake -g 17 11)
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
+(ppmpat -argyle1 -randomseed=100 7 8)
+match
+match
+match
+match
+match
+match
+match
+match
+match
+match
diff --git a/test/pnmpad-flip.test b/test/pnmpad-flip.test
new file mode 100755
index 00000000..2013874c
--- /dev/null
+++ b/test/pnmpad-flip.test
@@ -0,0 +1,62 @@
+#! /bin/sh
+# This script tests: pnmpad
+# Also requires: pamflip pbmmake pbmnoise pgmnoise ppmpat
+
+# If any of the padding functions is altered, make sure to run this
+# test in a more thorough form.  Try more input images and more
+# values of d0, d1, d2, d3.
+
+tmpdir=${tmpdir:-/tmp}
+test_pnm=${tmpdir}/test.pnm
+padded_pnm=${tmpdir}/padded.pnm
+
+echo "Test 1.  Should print match sixteen (8x2) times"
+
+d0=1; d1=11; d2=10; d3=5;
+
+for generator in "pbmnoise -randomseed=100 11 16" \
+                 "pgmnoise -randomseed=100 31 41"
+    do
+    ${generator} > ${test_pnm}
+    echo "("${generator}")"
+    for method in "-black" "-white" "-color rgb:20/30/e0" "-extend-edge"
+    do
+      pnmpad ${method} -t ${d0} -r ${d1} -b ${d2} -l ${d3} ${test_pnm} > ${padded_pnm}
+
+      pamflip -lr ${test_pnm} |\
+        pnmpad ${method} -t ${d0} -l ${d1} -b ${d2} -r ${d3} | pamflip -lr |\
+        cmp -s ${padded_pnm} - && echo "match" || echo "no match"
+
+      pamflip -r90 ${test_pnm} |\
+         pnmpad ${method} -l ${d0} -t ${d1} -r ${d2} -b ${d3} | pamflip -r270 |\
+         cmp -s ${padded_pnm} - && echo "match" || echo "no match"
+
+    done
+done
+
+echo "Test 2.  Should print match forty (10x4) times"
+
+# Test images with all corners with the same colors
+
+for generator in "pbmmake -b 1 1" \
+                 "pbmmake -w 1 1" \
+                 "pbmmake -g 17 11" \
+                 "ppmpat -argyle1 -randomseed=100 7 8"
+    do
+    ${generator} > ${test_pnm}
+    echo "("${generator}")"
+    for method in "-black" "-white" "-color rgb:20/30/e0 -promote none" \
+                  "-detect-background" "-extend-edge"
+    do
+      pnmpad ${method} -t ${d0} -r ${d1} -b ${d2} -l ${d3} ${test_pnm} > ${padded_pnm}
+
+      pamflip -lr ${test_pnm} |\
+        pnmpad ${method} -t ${d0} -l ${d1} -b ${d2} -r ${d3} | pamflip -lr |\
+        cmp -s ${padded_pnm} - && echo "match" || echo "no match"
+
+      pamflip -r90 ${test_pnm} |\
+         pnmpad ${method} -l ${d0} -t ${d1} -r ${d2} -b ${d3} | pamflip -r270 |\
+         cmp -s ${padded_pnm} - && echo "match" || echo "no match"
+
+    done
+done
diff --git a/test/pnmpad-format.ok b/test/pnmpad-format.ok
new file mode 100644
index 00000000..9938a170
--- /dev/null
+++ b/test/pnmpad-format.ok
@@ -0,0 +1,135 @@
+Test 1. PBM infile
+Should print: PBM raw, 8 by 1 fourteen times
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+stdin:	PBM raw, 8 by 1
+Should print: PGM raw, 8 by 1  maxval 1 twice
+stdin:	PGM raw, 8 by 1  maxval 1
+stdin:	PGM raw, 8 by 1  maxval 1
+Should print: PGM raw, 8 by 1  maxval 255 twice
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+Should print: PPM raw, 8 by 1  maxval 1 once
+stdin:	PPM raw, 8 by 1  maxval 1
+Should print: PPM raw, 8 by 1  maxval 255 twice
+stdin:	PPM raw, 8 by 1  maxval 255
+stdin:	PPM raw, 8 by 1  maxval 255
+
+Test 2. PGM maxval 127 infile
+Should print: PGM raw, 8 by 1  maxval 127 sixteen times
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+stdin:	PGM raw, 8 by 1  maxval 127
+Should print: PGM raw, 8 by 1  maxval 255 four times
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+Should print: PPM raw, 8 by 1  maxval 127 once
+stdin:	PPM raw, 8 by 1  maxval 127
+Should print: PPM raw, 8 by 1  maxval 255 twice
+stdin:	PPM raw, 8 by 1  maxval 255
+stdin:	PPM raw, 8 by 1  maxval 255
+
+Test 3. PGM maxval 255 infile
+Should print: PGM raw, 8 by 1  maxval 255 eighteen times
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+stdin:	PGM raw, 8 by 1  maxval 255
+Should print: PPM raw, 8 by 1  maxval 255 three times
+stdin:	PPM raw, 8 by 1  maxval 255
+stdin:	PPM raw, 8 by 1  maxval 255
+stdin:	PPM raw, 8 by 1  maxval 255
+
+Test 4. PPM maxval 127 infile
+Should print: PPM raw, 8 by 1  maxval 127 seventeen times
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+stdin:	PPM raw, 8 by 1  maxval 127
+Should print: PPM raw, 8 by 1  maxval 255 five times
+stdin:	PPM raw, 8 by 1  maxval 255
+stdin:	PPM raw, 8 by 1  maxval 255
+stdin:	PPM raw, 8 by 1  maxval 255
+stdin:	PPM raw, 8 by 1  maxval 255
+stdin:	PPM raw, 8 by 1  maxval 255
+
+Test 5. PPM maxval 511 infile
+Should print: PPM raw, 8 by 1  maxval 511 twenty-five times
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
+stdin:	PPM raw, 8 by 1  maxval 511
diff --git a/test/pnmpad-format.test b/test/pnmpad-format.test
new file mode 100755
index 00000000..73ea6d2b
--- /dev/null
+++ b/test/pnmpad-format.test
@@ -0,0 +1,245 @@
+#! /bin/sh
+# This script tests: pnmpad
+# Also requires: pbmmake pgmmake ppmmake pamfile
+
+tmpdir=${tmpdir:-/tmp}
+
+white_pbm=${tmpdir}/white.pbm
+#black_pbm=${tmpdir}/black.pbm
+test127_pgm=${tmpdir}/testimg1.pgm
+test255_pgm=${tmpdir}/testimg2.pgm
+test511_pgm=${tmpdir}/testimg3.pgm
+test127_ppm=${tmpdir}/testimg1.ppm
+test255_ppm=${tmpdir}/testimg2.ppm
+test511_ppm=${tmpdir}/testimg3.ppm
+
+BLACK="rgbi:0.0/0.0/0.0"
+WHITE="rgbi:1.0/1.0/1.0"
+LIGHTGRAY="rgbi:0.6/0.6/0.6"
+LIGHTGRAYv=0.6
+DARKGRAY="rgbi:0.01/0.01/0.01"
+DARKGRAYv=0.01
+PURPLE="rgb:A0/20/F0"
+YELLOW="rgb:FF/FF/00"
+
+pbmmake -w 3 1 > ${white_pbm}
+#pbmmake -b 3 1 > ${black_pbm}
+pgmmake 0.2 3 1 -maxval 127 > ${test127_pgm}
+pgmmake 0.2 3 1 -maxval 255 > ${test255_pgm}
+ppmmake ${YELLOW} 3 1 -maxval 127 > ${test127_ppm}
+ppmmake ${YELLOW} 3 1 -maxval 511 > ${test511_ppm}
+
+# define function
+ckfmt() { pamfile || echo "failure"; }
+
+size="-width 8"
+
+echo "Test 1. PBM infile"
+
+infile=${white_pbm}
+
+echo "Should print: PBM raw, 8 by 1 fourteen times"
+
+pnmpad ${size} ${infile} | ckfmt
+pnmpad ${size} -black ${infile} | ckfmt
+pnmpad ${size} -white ${infile} | ckfmt
+pnmpad ${size} -extend-edge ${infile} | ckfmt
+pnmpad ${size} -detect-background ${infile} | ckfmt
+
+pnmpad ${size} -color ${BLACK} ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote format ${infile} | ckfmt
+
+pnmpad ${size} -color ${WHITE} ${infile} | ckfmt
+pnmpad ${size} -color ${WHITE} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${WHITE} -promote format ${infile} | ckfmt
+
+pnmpad ${size} -color ${LIGHTGRAY} -promote none ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} -promote none ${infile} | ckfmt
+pnmpad ${size} -color ${PURPLE}   -promote none ${infile} | ckfmt
+
+echo "Should print: PGM raw, 8 by 1  maxval 1 twice"
+
+pnmpad ${size} -color ${LIGHTGRAY} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} -promote format ${infile} | ckfmt
+
+echo "Should print: PGM raw, 8 by 1  maxval 255 twice"
+
+pnmpad ${size} -color ${LIGHTGRAY} ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} ${infile} | ckfmt
+
+echo "Should print: PPM raw, 8 by 1  maxval 1 once"
+
+pnmpad ${size} -color ${PURPLE} -promote format ${infile} | ckfmt
+
+echo "Should print: PPM raw, 8 by 1  maxval 255 twice"
+
+pnmpad ${size} -color ${PURPLE} ${infile} | ckfmt
+pnmpad ${size} -color ${PURPLE} -promote all ${infile} | ckfmt
+
+rm ${infile}
+
+echo
+echo "Test 2. PGM maxval 127 infile"
+
+infile=${test127_pgm}
+
+echo "Should print: PGM raw, 8 by 1  maxval 127 sixteen times"
+
+pnmpad ${size} ${infile} | ckfmt
+pnmpad ${size} -black ${infile} | ckfmt
+pnmpad ${size} -white ${infile} | ckfmt
+pnmpad ${size} -extend-edge ${infile} | ckfmt
+pnmpad ${size} -detect-background ${infile} | ckfmt
+
+pnmpad ${size} -color ${BLACK} ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote format ${infile} | ckfmt
+
+pnmpad ${size} -color ${WHITE} ${infile} | ckfmt
+pnmpad ${size} -color ${WHITE} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${WHITE} -promote format ${infile} | ckfmt
+
+pnmpad ${size} -color ${LIGHTGRAY} -promote none ${infile} | ckfmt
+pnmpad ${size} -color ${LIGHTGRAY} -promote format ${infile} | ckfmt
+
+pnmpad ${size} -color ${DARKGRAY} -promote none ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} -promote format ${infile} | ckfmt
+
+pnmpad ${size} -color ${PURPLE}   -promote none ${infile} | ckfmt
+
+echo "Should print: PGM raw, 8 by 1  maxval 255 four times"
+
+pnmpad ${size} -color ${LIGHTGRAY}              ${infile} | ckfmt
+pnmpad ${size} -color ${LIGHTGRAY} -promote all ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY}               ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY}  -promote all ${infile} | ckfmt
+
+echo "Should print: PPM raw, 8 by 1  maxval 127 once"
+
+pnmpad ${size} -color ${PURPLE} -promote format ${infile} | ckfmt
+
+echo "Should print: PPM raw, 8 by 1  maxval 255 twice"
+
+pnmpad ${size} -color ${PURPLE} ${infile} | ckfmt
+pnmpad ${size} -color ${PURPLE} -promote all ${infile} | ckfmt
+
+rm ${infile}
+
+echo
+echo "Test 3. PGM maxval 255 infile"
+
+infile=${test255_pgm}
+
+echo "Should print: PGM raw, 8 by 1  maxval 255 eighteen times"
+
+pnmpad ${size} ${infile} | ckfmt
+pnmpad ${size} -black ${infile} | ckfmt
+pnmpad ${size} -white ${infile} | ckfmt
+pnmpad ${size} -extend-edge ${infile} | ckfmt
+pnmpad ${size} -detect-background ${infile} | ckfmt
+
+pnmpad ${size} -color ${BLACK} ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote all    ${infile} | ckfmt
+
+pnmpad ${size} -color ${LIGHTGRAY} ${infile} | ckfmt
+pnmpad ${size} -color ${LIGHTGRAY} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${LIGHTGRAY} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${LIGHTGRAY} -promote all    ${infile} | ckfmt
+
+
+pnmpad ${size} -color ${DARKGRAY} ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} -promote all    ${infile} | ckfmt
+
+pnmpad ${size} -color ${PURPLE}   -promote none   ${infile} | ckfmt
+
+echo "Should print: PPM raw, 8 by 1  maxval 255 three times"
+
+pnmpad ${size} -color ${PURPLE} ${infile} | ckfmt
+
+pnmpad ${size} -color ${PURPLE} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${PURPLE} -promote all    ${infile} | ckfmt
+
+rm ${infile}
+
+echo
+echo "Test 4. PPM maxval 127 infile"
+
+infile=${test127_ppm}
+
+echo "Should print: PPM raw, 8 by 1  maxval 127 seventeen times"
+
+pnmpad ${size} ${infile} | ckfmt
+pnmpad ${size} -black ${infile} | ckfmt
+pnmpad ${size} -white ${infile} | ckfmt
+pnmpad ${size} -extend-edge ${infile} | ckfmt
+pnmpad ${size} -detect-background ${infile} | ckfmt
+
+pnmpad ${size} -color ${BLACK} ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${WHITE} ${infile} | ckfmt
+pnmpad ${size} -color ${WHITE} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${WHITE} -promote format ${infile} | ckfmt
+
+pnmpad ${size} -color ${LIGHTGRAY} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${LIGHTGRAY} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} -promote format ${infile} | ckfmt
+
+pnmpad ${size} -color ${PURPLE} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${PURPLE} -promote format ${infile} | ckfmt
+
+echo "Should print: PPM raw, 8 by 1  maxval 255 five times"
+
+pnmpad ${size} -color ${LIGHTGRAY} ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY}  ${infile} | ckfmt
+pnmpad ${size} -color ${PURPLE}    ${infile} | ckfmt
+pnmpad ${size} -color ${LIGHTGRAY} -promote all ${infile} | ckfmt
+pnmpad ${size} -color ${PURPLE}    -promote all ${infile} | ckfmt
+
+rm ${infile}
+
+echo
+echo "Test 5. PPM maxval 511 infile"
+
+infile=${test511_ppm}
+
+echo "Should print: PPM raw, 8 by 1  maxval 511 twenty-five times"
+
+pnmpad ${size} ${infile} | ckfmt
+pnmpad ${size} -black ${infile} | ckfmt
+pnmpad ${size} -white ${infile} | ckfmt
+pnmpad ${size} -extend-edge ${infile} | ckfmt
+pnmpad ${size} -detect-background ${infile} | ckfmt
+
+pnmpad ${size} -color ${BLACK} ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${BLACK} -promote all    ${infile} | ckfmt
+
+pnmpad ${size} -color ${WHITE} ${infile} | ckfmt
+pnmpad ${size} -color ${WHITE} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${WHITE} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${WHITE} -promote all    ${infile} | ckfmt
+
+pnmpad ${size} -color ${LIGHTGRAY} ${infile} | ckfmt
+pnmpad ${size} -color ${LIGHTGRAY} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${LIGHTGRAY} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${LIGHTGRAY} -promote all    ${infile} | ckfmt
+
+pnmpad ${size} -color ${DARKGRAY} ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${DARKGRAY} -promote all    ${infile} | ckfmt
+
+pnmpad ${size} -color ${PURPLE} ${infile} | ckfmt
+pnmpad ${size} -color ${PURPLE} -promote none   ${infile} | ckfmt
+pnmpad ${size} -color ${PURPLE} -promote format ${infile} | ckfmt
+pnmpad ${size} -color ${PURPLE} -promote all    ${infile} | ckfmt
+
+rm ${infile}
diff --git a/test/pnmpad-pnmmargin.ok b/test/pnmpad-pnmmargin.ok
new file mode 100644
index 00000000..552c530f
--- /dev/null
+++ b/test/pnmpad-pnmmargin.ok
@@ -0,0 +1,15 @@
+Test 1.  Should print match three times
+match
+match
+match
+Test 2.  Should print match four times
+match
+match
+match
+match
+Test 3.  Should print match five times
+match
+match
+match
+match
+match
diff --git a/test/pnmpad-pnmmargin.test b/test/pnmpad-pnmmargin.test
new file mode 100755
index 00000000..8b23be35
--- /dev/null
+++ b/test/pnmpad-pnmmargin.test
@@ -0,0 +1,79 @@
+#! /bin/sh
+# This script tests: pnmpad pnmmargin
+# Also requires: pamcat pamcut pamenlarge pbmmake pnmmargin ppmmake ppmpat
+
+tmpdir=${tmpdir:-/tmp}
+padded_pbm=${tmpdir}/padded.pbm
+argyle_ppm=${tmpdir}/argyle.ppm
+padded_ppm=${tmpdir}/padded.ppm
+
+spacer_pnm=${tmpdir}/spacer.pnm
+
+# define function
+addmargin () {
+
+# This function takes 3 positional parameters:
+#   $1: color black white or gofigure
+#   $2: color string (ignore if black white or gofigure)
+#   $3: margin
+#   $4: filename
+
+    case $1 in
+        -color) ppmmake $2 $3 $3 > ${spacer_pnm}; infile=$4 ;;
+        -black) pbmmake -black $2 $2 > ${spacer_pnm}; infile=$3 ;;
+        -white) pbmmake -white $2 $2 > ${spacer_pnm}; infile=$3 ;;
+        *) pamcut -t 0 -l 0 -w 1 -h 1 $2 | pamenlarge $1 > ${spacer_pnm}; infile=$2 ;;
+    esac
+    pamcat -lr ${spacer_pnm} ${infile} ${spacer_pnm} |\
+        pamcat -tb ${spacer_pnm} - ${spacer_pnm}
+    rm ${spacer_pnm}
+}
+
+echo "Test 1.  Should print match three times"
+
+pnmmargin -black 5 maze.pbm > ${padded_pbm} 
+pnmmargin -black 1 maze.pbm | pnmpad -black -t 4 -b 4 -l 4 -r 4 |\
+    cmp -s ${padded_pbm} - && echo "match" || echo "no match"
+pnmmargin 1 maze.pbm | pnmpad -black -t 4 -b 4 -l 4 -r 4 |\
+    cmp -s ${padded_pbm} - && echo "match" || echo "no match"
+pnmmargin -black 1 maze.pbm | pnmpad -extend-edge -t 4 -b 4 -l 4 -r 4 |\
+    cmp -s ${padded_pbm} - && echo "match" || echo "no match"
+
+
+echo "Test 2.  Should print match four times"
+
+addmargin -black 5 maze.pbm |\
+    cmp -s ${padded_pbm} - && echo "match" || echo "no match"
+addmargin -black 1 maze.pbm | pnmpad -black -t 4 -b 4 -l 4 -r 4 |\
+    cmp -s ${padded_pbm} - && echo "match" || echo "no match"
+addmargin 1 maze.pbm | pnmpad -black -t 4 -b 4 -l 4 -r 4 |\
+    cmp -s ${padded_pbm} - && echo "match" || echo "no match"
+addmargin -black 1 maze.pbm | pnmpad -extend-edge -t 4 -b 4 -l 4 -r 4 |\
+    cmp -s ${padded_pbm} - && echo "match" || echo "no match"
+
+rm ${padded_pbm}
+
+echo "Test 3.  Should print match five times"
+
+ppmpat -argyle1 -color=rgb:20/30/ff,rgb:70/80/ff 30 20 > ${argyle_ppm}
+
+addmargin 3 ${argyle_ppm} > ${padded_ppm}
+
+addmargin -color rgb:20/30/ff 1 ${argyle_ppm} |\
+  pnmpad -color=rgb:20/30/ff -t 2 -b 2 -r 2 -l 2 |\
+    cmp -s ${padded_ppm} - && echo "match" || echo "no match"
+addmargin -color rgb:20/30/ff 1 ${argyle_ppm} |\
+  pnmpad -color=rgb:20/30/ff -t 2 -b 2 -r 2 -l 2 |\
+    cmp -s ${padded_ppm} - && echo "match" || echo "no match"
+addmargin 1 ${argyle_ppm} |\
+  pnmpad -extend-edge -t 2 -b 2 -r 2 -l 2 |\
+    cmp -s ${padded_ppm} - && echo "match" || echo "no match"
+
+pnmpad -color rgb:20/30/ff -t 3 -b 3 -r 3 -l 3 ${argyle_ppm} |\
+    cmp -s ${padded_ppm} - && echo "match" || echo "no match"
+
+pnmpad -detect-background -t 3 -b 3 -r 3 -l 3 ${argyle_ppm} |\
+    cmp -s ${padded_ppm} - && echo "match" || echo "no match"
+
+
+rm ${argyle_ppm} ${padded_ppm}
diff --git a/test/pnmpad-reportonly.ok b/test/pnmpad-reportonly.ok
index e7d0a0d1..2cf58f39 100644
--- a/test/pnmpad-reportonly.ok
+++ b/test/pnmpad-reportonly.ok
@@ -65,3 +65,11 @@ Test 9.  Should print 0 0 4 8 19 112 seven times
 0 0 4 8 19 112
 0 0 4 8 19 112
 0 0 4 8 19 112
+Test Invalid
+Expected failure 1 (no output)
+Expected failure 2 (no output)
+Expected failure 3 (no output)
+Expected failure 4 (no output)
+Expected failure 5 (no output)
+Expected failure 6 (no output)
+Expected failure 7 (no output)
diff --git a/test/pnmpad-reportonly.test b/test/pnmpad-reportonly.test
index ccd79e69..412cb8a2 100755
--- a/test/pnmpad-reportonly.test
+++ b/test/pnmpad-reportonly.test
@@ -125,5 +125,34 @@ for pad in "-t 4 -b 8 -h 112" \
   pnmpad -reportonly ${pad} ${test_ppm} || echo "failure"
   done
 
-
+echo "Test Invalid"
+
+test_out=${tmpdir}/test_out
+n=1
+
+# define function
+invcmd () { $1 > ${test_out} || \
+  printf "Expected failure $n "
+  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
+  rm -f ${test_out}
+  n=$(($n +1)); }
+
+echo 1>&2
+echo "Invalid command-line arguments." 1>&2
+echo "Error messages should appear below the line." 1>&2
+echo "-----------------------------------------------------------" 1>&2
+
+invcmd "pnmpad -reportonly -l 1 -r 1 -w 100 testgrid.pbm"
+invcmd "pnmpad -reportonly -t 1 -b 1 -h 100 testgrid.pbm"
+invcmd "pnmpad -reportonly -black -white -l 1 testgrid.pbm"
+invcmd "pnmpad -reportonly -color -l 1 testgrid.pbm"
+invcmd "pnmpad -reportonly -color rgbi:0/0/0 -white -l 1 testgrid.pbm"
+invcmd "pnmpad -reportonly -color rgbi:0/0/0 -extend-edge -l 1 testgrid.pbm"
+invcmd "pnmpad -reportonly -color rgbi:0/0/0 -detect-background -l 1 testgrid.pbm"
+
+# echo "Test Invalid.  Should print failure twice"
+# 
+# pnmpad -reportonly -l 1 -r 1 -w 100 testgrid.pbm && echo "unexpected success" || echo "failure" 
+# pnmpad -reportonly -t 1 -b 1 -h 100 testgrid.pbm && echo "unexpected success" || echo "failure"
+# 
 rm ${test1_pbm} ${test2_pbm} ${test_pgm} ${test_ppm}
diff --git a/test/pnmquantall.ok b/test/pnmquantall.ok
index 5885d370..c7563d88 100644
--- a/test/pnmquantall.ok
+++ b/test/pnmquantall.ok
@@ -1,7 +1,14 @@
+Test 1.
 2373957371 33838
 3892560659 33838
 1383839923 33838
-1
+color count 20: success
+Test 2.
+452076937 33838
+452076937 33838
+452076937 33838
+color count 1: success
+Test Invalid
 Expected failure 1
 Expected failure 1.rm
 Expected failure 2
diff --git a/test/pnmquantall.test b/test/pnmquantall.test
index f047e856..7910d0fc 100755
--- a/test/pnmquantall.test
+++ b/test/pnmquantall.test
@@ -12,21 +12,45 @@ rose_red=${tmpdir}/rose.red
 rose_grn=${tmpdir}/rose.grn
 rose_blu=${tmpdir}/rose.blu
 
-pnmquantall 20 ${rose_red} ${rose_grn} ${rose_blu}
+cp ${rose_red} ${rose_red}.1
+cp ${rose_grn} ${rose_grn}.1
+cp ${rose_blu} ${rose_blu}.1
 
-for i in ${rose_red} ${rose_grn} ${rose_blu}
+echo "Test 1."
+
+pnmquantall 20 ${rose_red}.1 ${rose_grn}.1 ${rose_blu}.1
+
+for i in ${rose_red}.1 ${rose_grn}.1 ${rose_blu}.1
 do
 cat $i | cksum
 done
 
-# Should print 1
+pamcat ${rose_red}.1 ${rose_grn}.1 ${rose_blu}.1 -tb | \
+    pgmhist -m |\
+    awk '$2>0 {s++};
+         END { printf("color count %u: %s\n", s,
+                 (s==20) ? "success" : "failure") }'
 
-pamcat ${rose_red} ${rose_grn} ${rose_blu} -tb | \
-    pgmhist -m | awk '$2>0 {s++}; END { print (s<=20) }'
+rm ${rose_red}.1 ${rose_grn}.1 ${rose_blu}.1
 
+echo "Test 2."
 
-tmpdir=${tmpdir:-/tmp}
-rose_out=${tmpdir}/rose_out
+pnmquantall -ext .2 1 ${rose_red} ${rose_grn} ${rose_blu}
+
+for i in ${rose_red}.2 ${rose_grn}.2 ${rose_blu}.2
+do
+cat $i | cksum
+done
+
+pamcat ${rose_red}.2 ${rose_grn}.2 ${rose_blu}.2 -tb | \
+    pgmhist -m |\
+    awk '$2>0 {s++};
+         END { printf("color count %u: %s\n", s,
+                 (s==1) ? "success" : "failure") }'
+
+rm ${rose_red}.2 ${rose_grn}.2 ${rose_blu}.2
+
+echo "Test Invalid"
 
 echo 1>&2
 echo "Invalid command-line argument combinations." 1>&2
@@ -37,11 +61,11 @@ pnmquantall -ext xx 0 ${rose_red} ${rose_grn} ${rose_blu} || \
    echo "Expected failure 1"
 rm ${rose_red}xx ${rose_grn}xx ${rose_blu}xx || \
    echo "Expected failure 1.rm"
-pnmquantall -ext xx 1 ${rose_red} ${rose_grn} ${rose_blu} || \
+pnmquantall -ext yy ${rose_red} ${rose_grn} ${rose_blu} || \
    echo "Expected failure 2"
-rm ${rose_red}xx ${rose_grn}xx ${rose_blu}xx || \
+rm ${rose_red}yy ${rose_grn}yy ${rose_blu}yy || \
    echo "Expected failure 2.rm"
-pnmquantall -ext xx 2 || \
+pnmquantall -ext zz 2 || \
    echo "Expected failure 3"
 
 rm ${rose_red} ${rose_grn} ${rose_blu} ${rose_ppm}
diff --git a/test/ppmforge.ok b/test/ppmforge.ok
index 2f3f9501..d2ed4a66 100644
--- a/test/ppmforge.ok
+++ b/test/ppmforge.ok
@@ -1,5 +1,5 @@
 Test 1. Should print: 547829788 196623  (Mersenne Twister)
-547829788 196623
+3820754824 196623
 Test 2.
 match
 Test 3.
diff --git a/test/ppmforge.test b/test/ppmforge.test
index 75de7cf7..e004d7e8 100755
--- a/test/ppmforge.test
+++ b/test/ppmforge.test
@@ -1,52 +1,50 @@
-#! /bin/sh
+q#! /bin/sh
 # This script tests: ppmforge
 # Also requires: pnmpsnr
 
 echo "Test 1. Should print: 547829788 196623  (Mersenne Twister)" 
-#               3634219838 196623 (Glibc rand() )
-#               3262664440 196623 (MAC OS rand() )
 ppmforge -night -seed 1 | cksum
 
 tmpdir=${tmpdir:-/tmp}
 test_ppm=${tmpdir}/test.ppm
 
-
 # Target values for following tests were determined by running the
-# ppmforge command pairs 30 times with different seeds, finding
+# ppmforge command pairs 1000 times with different seeds, finding
 # the minimum (or "poorest match") for each component and 
 # subtracting 0.01 dB.   As such these are weak tests.
 
-
 echo "Test 2."
-ppmforge -cloud -seed 1 -power 0.75 > ${test_ppm}
-ppmforge -cloud -seed 1 -power 0.74 | \
-  pnmpsnr -rgb -target1=41.15 -target2=41.15 -target3=999 - ${test_ppm}
+ppmforge -cloud -seed 110 -power 0.75 > ${test_ppm}
+ppmforge -cloud -seed 110 -power 0.74 | \
+  pnmpsnr -rgb -target1=40.53 -target2=40.53 -target3=999 - ${test_ppm}
+
 
 rm ${test_ppm}
 
 echo "Test 3."
-ppmforge -cloud -seed 1 -dimension 2.15 > ${test_ppm}
-ppmforge -cloud -seed 1 -dimension 2.175 | \
-  pnmpsnr -rgb -target1=43.39 -target2=43.39 -target3=999 - ${test_ppm}
+ppmforge -cloud -seed 111 -dimension 2.15 > ${test_ppm}
+ppmforge -cloud -seed 111 -dimension 2.16 | \
+  pnmpsnr -rgb -target1=40.34 -target2=40.34 -target3=999 - ${test_ppm}        
 
   # Note that there should be no difference for the target3: blue.
 
 
-
 rm ${test_ppm}
 
 echo "Test 4."
-ppmforge -seed 1 -stars 0 -ice 0.01 -power 1.18 -hour 10 >  ${test_ppm}
-ppmforge -seed 1 -stars 0 -ice 0.01 -power 1.22 -hour 10 | \
-  pnmpsnr -target1=27.89 -target2=24.25 -target3=37.87 - ${test_ppm}
+ppmforge -seed 200 -stars 0 -ice 0.01 -power 1.180 -hour 10 >  ${test_ppm}
+ppmforge -seed 200 -stars 0 -ice 0.01 -power 1.181 -hour 10 | \
+  pnmpsnr -rgb -target1=45.9 -target2=45.81 -target3=32.11 - ${test_ppm}
 
 rm ${test_ppm}
 
+
 echo "Test 5."
-ppmforge -seed 1 -stars 0 -ice 0.01 \
-    -inclination 9  -hour 12 -power 200 > ${test_ppm} 
-ppmforge -seed 1 -stars 0 -ice 0.01 \
-    -inclination 10 -hour 12 -power 200 | \
-  pnmpsnr -target1=46.07 -target2=52.00 -target3=67.77 - ${test_ppm}
+ppmforge -seed 300 -stars 0 -ice 0.01 \
+    -inclination 9  -hour 12 -power 300 > ${test_ppm} 
+ppmforge -seed 300 -stars 0 -ice 0.01 \
+    -inclination 9.1 -hour 12 -power 300 | \
+  pnmpsnr -rgb -target1=44.86 -target2=44.86 -target3=42.43 - ${test_ppm}
+
 
 rm ${test_ppm}
diff --git a/test/ppmpat-random.test b/test/ppmpat-random.test
index b1b78d94..4da0d77c 100755
--- a/test/ppmpat-random.test
+++ b/test/ppmpat-random.test
@@ -8,20 +8,14 @@
 # These tests require random numbers.
 
 echo "Test 1. Should print: 1366170000 36015" # Mersenne Twister
-#                           2219119109 36015 (glibc rand())
-#                           3606254242 36015 (MAC OS rand())
 
 ppmpat --randomseed=0 -camo 100 120 | cksum
 
 echo "Test 2. Should print: 4073196212 16813" # Mersenne Twister
-#                       3436846137 16813 (glibc)
-#                       3615722579 16813 (MAC OS rand())
 
 ppmpat --randomseed=0 -anticamo 80 70 | cksum
 
 echo "Test 3. Should print: 2292015301 16813" # Mersenne Twister 
-#                       908097729 16813 (glibc rand())
-#                       1756684515 16813 (MAC OS rand())
 
 ppmpat --randomseed=0 --color \
   rgb:55/c0/34,rgb:0/ff/0,rgb:0/ee/0,rgb:0/cd/0,rgb:0/8b/0,rgb:4f/4f/2f \
diff --git a/test/random-generator.test b/test/random-generator.test
index 14b6f11a..351b982e 100755
--- a/test/random-generator.test
+++ b/test/random-generator.test
@@ -26,9 +26,6 @@ echo "1023"
 echo "720 296 192 858 101 57 298 629 804 1019 64 617"
 echo "Above output is for Mersenne Twister"
 
-# GNU libc rand(): 593 252 207 990 507 824 961 805 559 110 167 172
-# MAC OS rand():   9 782 60 418 364 654 670 172 1022 515 593 903 
-
 pgmnoise -maxval=1023 -randomseed=3791 -plain 12 1
 
 echo
diff --git a/test/stdin-pnm1.test b/test/stdin-pnm1.test
index ae848752..20902d41 100755
--- a/test/stdin-pnm1.test
+++ b/test/stdin-pnm1.test
@@ -4,7 +4,7 @@
 # This script tests: pnmmontage pnmnlfilt pnmnorm pnmpad pnmquant pnmrotate
 # This script tests: pnmscalefixed pnmshear pnmsmooth pnmtile pnmtoddif
 # This script tests: pnmtopclxl
-# Also requires: ppmpat pamflip
+# Also requires: ppmpat
 
 tmpdir=${tmpdir:-/tmp}
 small_ppm=${tmpdir}/test.ppm