#! /bin/bash # This script tests: pamfunc # Also requires: pamseq pamtopnm pbmmake tmpdir=${tmpdir:-/tmp} input_pgm=${tmpdir}/input.pgm echo "Test 1" pamseq 1 15 | pamtopnm -assume > ${input_pgm} pamtopnm -plain ${input_pgm} | tr '\n' ' '; echo pamfunc -adder=3 -plain ${input_pgm} | tr '\n' ' '; echo pamfunc -subtractor=3 -plain ${input_pgm} | tr '\n' ' '; echo pamfunc -multiplier=3 -plain ${input_pgm} | tr '\n' ' '; echo pamfunc -divisor=2 -plain ${input_pgm} | tr '\n' ' '; echo pamfunc -max=6 -plain ${input_pgm} | tr '\n' ' '; echo pamfunc -min=5 -plain ${input_pgm} | tr '\n' ' '; echo pamfunc -shiftleft 1 -plain ${input_pgm} | tr '\n' ' '; echo pamfunc -shiftright 1 -plain ${input_pgm} | tr '\n' ' '; echo pamfunc -shiftleft 1 ${input_pgm} | pamfunc -shiftright 1 -plain | \ tr '\n' ' '; echo pamfunc -shiftright 1 ${input_pgm} | pamfunc -shiftleft 1 -plain | \ tr '\n' ' '; echo input_pbm=${tmpdir}/input.pbm echo "Test 2" pbmmake -g 8 1 > ${input_pbm} pamtopnm -plain ${input_pbm} | tr '\n' ' '; echo pamfunc -adder=1 -plain ${input_pbm} | tr '\n' ' '; echo pamfunc -subtractor=1 -plain ${input_pbm} | tr '\n' ' '; echo pamfunc -multiplier=1 -plain ${input_pbm} | tr '\n' ' '; echo pamfunc -divisor=1 -plain ${input_pbm} | tr '\n' ' '; echo pamfunc -max=1 -plain ${input_pbm} | tr '\n' ' '; echo pamfunc -min=1 -plain ${input_pbm} | tr '\n' ' '; echo pamfunc -shiftleft 1 -plain ${input_pbm} | tr '\n' ' '; echo pamfunc -shiftright 1 -plain ${input_pbm} | tr '\n' ' '; echo pamfunc -shiftleft 1 ${input_pbm} | pamfunc -shiftright 1 -plain | \ tr '\n' ' '; echo pamfunc -shiftright 1 ${input_pbm} | pamfunc -shiftleft 1 -plain | \ tr '\n' ' '; echo echo "Test 3 (-changemaxval)" pamfunc -divisor 2 -changemaxval ${input_pgm} -plain | \ tr '\n' ' '; echo pamfunc -multiplier 0.25 -changemaxval ${input_pgm} -plain | \ tr '\n' ' '; echo pamfunc -divisor 2 -changemaxval ${input_pbm} -plain | \ tr '\n' ' '; echo pamfunc -multiplier 0.25 -changemaxval ${input_pbm} -plain | \ tr '\n' ' '; echo rm ${input_pgm} ${input_pbm} echo "Test 4: Should print 1926073387 101484 eight times" cat testimg.ppm | cksum pamfunc -not testimg.ppm | pamfunc -not | cksum pamfunc -andmask 0xff testimg.ppm | cksum pamfunc -ormask 0x00 testimg.ppm | cksum pamfunc -xormask 0x00 testimg.ppm | cksum pamfunc -xormask 0xff testimg.ppm | pamfunc -xormask 0xff | cksum pamfunc -shiftleft 0 testimg.ppm | cksum pamfunc -shiftright 0 testimg.ppm | cksum echo "Test 5: Should print 2425386270 41 six times" cat testgrid.pbm | cksum pamfunc -andmask 0x1 testgrid.pbm | cksum pamfunc -ormask 0x0 testgrid.pbm | cksum pamfunc -xormask 0x1 testgrid.pbm | pamfunc -xormask 0x1 | cksum pamfunc -shiftleft 0 testgrid.pbm | cksum pamfunc -shiftright 0 testgrid.pbm | cksum echo "Invalid command-line argument combinations." 1>&2 echo "Error messages should appear below the line." 1>&2 echo "-----------------------------------------------------------" 1>&2 echo "Test Invalid" output_ppm=${tmpdir}/output.ppm pamfunc -multiplier testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 1" test -s ${output_ppm}; echo " "$? pamfunc -multiplier=-1 testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 2" test -s ${output_ppm}; echo " "$? pamfunc -divisor testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 3" test -s ${output_ppm}; echo " "$? pamfunc -divisor=-20 testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 4" test -s ${output_ppm}; echo " "$? pamfunc -adder testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 5" test -s ${output_ppm}; echo " "$? pamfunc -adder 0.5 testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 6" test -s ${output_ppm}; echo " "$? pamfunc -subtractor testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 7" test -s ${output_ppm}; echo " "$? pamfunc -subtractor 0.1 testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 8" test -s ${output_ppm}; echo " "$? pamfunc -multiplier=1 -divisor=2 testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 9" test -s ${output_ppm}; echo " "$? pamfunc -adder=2 -subtractor=3 testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 10" test -s ${output_ppm}; echo " "$? pamfunc -min testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 11" test -s ${output_ppm}; echo " "$? pamfunc -max testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 12" test -s ${output_ppm}; echo " "$? pamfunc -andmask testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 13" test -s ${output_ppm}; echo " "$? pamfunc -ormask testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 14" test -s ${output_ppm}; echo " "$? pamfunc -xormask testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 15" test -s ${output_ppm}; echo " "$? pamfunc -not 1 testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 16" test -s ${output_ppm}; echo " "$? pamfunc -min=1 -max=2 testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 17" test -s ${output_ppm}; echo " "$? pamfunc -andmask=1 -ormask=0 testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 18" test -s ${output_ppm}; echo " "$? pamfunc -andmask=0xffff testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 19" test -s ${output_ppm}; echo " "$? pamfunc -shiftleft testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 20" test -s ${output_ppm}; echo " "$? pamfunc -shiftright testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 21" test -s ${output_ppm}; echo " "$? pamfunc -changemaxval testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 22" test -s ${output_ppm}; echo " "$? pamfunc -shiftleft=1 -shiftright=1 testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 23" test -s ${output_ppm}; echo " "$? pamfunc -multiplier=0.5 -changemaxval=65535 testimg.ppm > ${output_ppm} || \ echo -n "Expected failure 24" test -s ${output_ppm}; echo " "$?