From ada0144457396bd228e2d767cf9881293a88b141 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 16 Feb 2020 16:28:35 +0000 Subject: Add tests for pamdice, pamundice git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3740 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- test/Test-Order | 3 + test/pamdice-roundtrip.ok | 17 ++++ test/pamdice-roundtrip.test | 34 +++++++- test/pamdice.ok | 21 +++++ test/pamdice.test | 68 ++++++++++++++++ test/pamundice.ok | 27 +++++++ test/pamundice.test | 183 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 349 insertions(+), 4 deletions(-) create mode 100644 test/pamdice.ok create mode 100755 test/pamdice.test create mode 100644 test/pamundice.ok create mode 100755 test/pamundice.test (limited to 'test') diff --git a/test/Test-Order b/test/Test-Order index 2548e501..729d124c 100644 --- a/test/Test-Order +++ b/test/Test-Order @@ -61,6 +61,9 @@ pamhue.test pbmclean.test pamcut.test pnmcat.test +pamdice.test +pamundice.test + pamflip1.test pamflip2.test pnminvert.test diff --git a/test/pamdice-roundtrip.ok b/test/pamdice-roundtrip.ok index 82eac5a8..4a850615 100644 --- a/test/pamdice-roundtrip.ok +++ b/test/pamdice-roundtrip.ok @@ -1 +1,18 @@ +test 1 +2425386270 41 +test 2 +2425386270 41 +test 3 +2425386270 41 +test 4. +1926073387 101484 +test 4.-hoverlap=0 +1926073387 101484 +test 4.-hoverlap=2 +1926073387 101484 +test 4.-voverlap=0 +1926073387 101484 +test 4.-voverlap=2 +1926073387 101484 +test 5 1926073387 101484 diff --git a/test/pamdice-roundtrip.test b/test/pamdice-roundtrip.test index 28997742..c5ccde66 100755 --- a/test/pamdice-roundtrip.test +++ b/test/pamdice-roundtrip.test @@ -4,9 +4,35 @@ tmpdir=${tmpdir:-/tmp} -fname_stem=${tmpdir}/a +fname_stem=${tmpdir}/pamdice_part -pamdice testimg.ppm -outstem=${fname_stem} -width=50 -height=40 -pamundice ${fname_stem}_%1d_%1a.ppm -down=4 -across=5 | cksum +echo test 1 -rm ${fname_stem}_?_?.ppm +pamdice testgrid.pbm -outstem=${fname_stem} +pamundice ${fname_stem}_%1d_%1a.pbm -down=1 -across=1 | cksum +rm ${fname_stem}_0_0.pbm + +echo test 2 + +pamdice testgrid.pbm -outstem=${fname_stem} -width=3 +pamundice ${fname_stem}_%1d_%1a.pbm -across=5 | cksum +rm ${fname_stem}_0_?.pbm + +echo test 3 + +pamdice testgrid.pbm -outstem=${fname_stem} -height=4 +pamundice ${fname_stem}_%1d_%1a.pbm -down=4 | cksum +rm ${fname_stem}_?_0.pbm + +for flags in "" "-hoverlap=0" "-hoverlap=2" "-voverlap=0" "-voverlap=2" + do + echo test 4.${flags} + pamdice testimg.ppm -outstem=${fname_stem} -width=50 -height=40 + pamundice ${fname_stem}_%1d_%1a.ppm -down=4 -across=5 | cksum + rm ${fname_stem}_?_?.ppm + done + +echo test 5 +pamdice testimg.ppm -outstem=${fname_stem} -width=20 -height=10 +ls ${fname_stem}*.ppm | pamundice -listfile=- -across=12 -down=15 | cksum +rm ${fname_stem}_??_??.ppm \ No newline at end of file diff --git a/test/pamdice.ok b/test/pamdice.ok new file mode 100644 index 00000000..83db2775 --- /dev/null +++ b/test/pamdice.ok @@ -0,0 +1,21 @@ +Test 1. + 10 P1@1 1@0@ +Test 2. +P1@1 1@0@ +P1@1 1@1@ +P1@1 1@1@ +P1@1 1@0@ +P1@1 1@0@ +P1@1 1@1@ +P1@1 1@1@ +P1@1 1@0@ +P1@1 1@0@ +P1@1 1@1@ +Test Invalid +Expected failure 1 +Expected failure 2 +Expected failure 3 +Expected failure 4 +Expected failure 5 +Expected failure 6 +Expected failure (output files) diff --git a/test/pamdice.test b/test/pamdice.test new file mode 100755 index 00000000..71a9d645 --- /dev/null +++ b/test/pamdice.test @@ -0,0 +1,68 @@ +#! /bin/bash +# This script tests: pamdice +# Also requires: pbmmake + +tmpdir=${tmpdir:-/tmp} +fname_stem=${tmpdir}/pamdice_part + +# Test 1. +echo "Test 1." + +pbmmake -w 2 5 | pamdice -height=1 -width=1 -outstem=${fname_stem} -plain +ls ${fname_stem}*.pbm | while read file + do + cat ${file} | tr '\n' '@' ; echo + done | sort | uniq -c + +rm ${fname_stem}*.pbm + +# Test 1. +echo "Test 2." + +pbmmake -g 2 5 | pamdice -height=1 -width=1 -outstem=${fname_stem} -plain +ls ${fname_stem}*.pbm | while read file + do + cat ${file} | tr '\n' '@' ; echo + done + +rm ${fname_stem}*.pbm + + +# Test Invalid. +echo "Test Invalid" + +echo 1>&2 +echo "Invalid command-line argument combinations." 1>&2 +echo "Error messages should appear below the line." 1>&2 +echo "-----------------------------------------------------------" 1>&2 + +# No input file +pamdice -width=10 -height=10 -outstem=${fname_stem} /dev/null || \ +echo "Expected failure 1" + +# No -outstem +pamdice -width=10 -height=10 testgrid.pbm || \ +echo "Expected failure 2" + +# -width=0 +pamdice -width=0 -height=10 -outstem=${fname_stem} testgrid.pbm || \ +echo "Expected failure 3" + +# -height=0 +pamdice -width=10 -height=0 -outstem=${fname_stem} testgrid.pbm || \ +echo "Expected failure 4" + +# -hoverlap larger than width +pamdice -width=10 -height=10 -hoverlap=11 \ + -outstem=${fname_stem} testgrid.pbm || \ +echo "Expected failure 5" + +# -voverlap larger than height +pamdice -width=10 -height=10 -voverlap=11 \ + -outstem=${fname_stem} testgrid.pbm || \ +echo "Expected failure 6" + + +# Ensure that no output files are produced by the above +ls ${fname_stem}* || \ +echo "Expected failure (output files)" \ No newline at end of file diff --git a/test/pamundice.ok b/test/pamundice.ok new file mode 100644 index 00000000..ef0f6e13 --- /dev/null +++ b/test/pamundice.ok @@ -0,0 +1,27 @@ +Test 1. +2096818803 2818 +2096818803 2818 +Test 2. +2096818803 2818 +2096818803 2818 +Test 3. +2096818803 2818 +2096818803 2818 +Test 4. +557392151 459 +557392151 459 +557392151 459 +557392151 459 +Test Invalid +Expected failure 1 1 +Expected failure 2 1 +Expected failure 3 1 +Expected failure 4 1 +Expected failure 5 1 +Expected failure 6 1 +Expected failure 7 1 +Expected failure 8 1 +Expected failure 9 1 +Expected failure 10 1 +Expected failure 11 1 +Expected failure 12 1 diff --git a/test/pamundice.test b/test/pamundice.test new file mode 100755 index 00000000..c49b9b2a --- /dev/null +++ b/test/pamundice.test @@ -0,0 +1,183 @@ +#! /bin/bash +# This script tests: pamundice +# Also requires: pbmmake pgmmake pnmtile pnmcat pnmpad + +tmpdir=${tmpdir:-/tmp} +fname_stem=${tmpdir}/part + +# Test 1. +echo "Test 1." + +for ((x=0; x<3; ++x)) + do for ((y=0; y<5; ++y)) + do + pgmmake "."$(( x* 25 + y )) 11 17 > ${fname_stem}_${y}_${x}.pgm + done + done + +pamundice -across=3 -down=5 ${fname_stem}"_%1d_%1a".pgm | cksum + +ls ${fname_stem}_?_?.pgm | \ + pamundice -across=3 -down=5 -listfile=- | cksum + + +# Test 2. +echo "Test 2." + +tempfile=${tmpdir}/temp + +for ((y=0; y<5; ++y)) + do + pamundice -across=3 ${fname_stem}"_"$y"_%1a".pgm > ${tempfile}_"$y" + done + +pnmcat -tb ${tempfile}_[01234] | cksum +rm ${tempfile}_[01234] + +# Note: the following 2 are valid. There should not be warning messages. + +for ((x=0; x<3; ++x)) + do + pamundice -down=5 ${fname_stem}"_%1d_"$x.pgm > ${tempfile}"_"$x + done + +pnmcat -lr ${tempfile}_[012] | cksum +rm ${tempfile}_[012] + +rm ${fname_stem}_?_?.pgm + +# Test 3. +echo "Test 3." + +for ((x=0; x<2; ++x)) + do for ((y=0; y<5; ++y)) + do + pgmmake "."$(( x* 25 + y )) 12 17 > ${fname_stem}_${y}_${x}.pgm + done + done + +for ((x=2; x<3; ++x)) + do for ((y=0; y<5; ++y)) + do + pgmmake "."$(( x* 25 + y )) 11 17 > ${fname_stem}_${y}_${x}.pgm + done + done + +pamundice -across=3 -down=5 \ + -hoverlap=1 ${fname_stem}"_%1d_%1a".pgm | cksum + +rm ${fname_stem}_?_?.pgm + +for ((x=0; x<3; ++x)) + do for ((y=0; y<4; ++y)) + do + pgmmake "."$(( x* 25 + y )) 11 18 > ${fname_stem}_${y}_${x}.pgm + done + done + +for ((x=0; x<3; ++x)) + do for ((y=4; y<5; ++y)) + do + pgmmake "."$(( x* 25 + y )) 11 17 > ${fname_stem}_${y}_${x}.pgm + done + done + +pamundice -across=3 -down=5 \ + -voverlap=1 ${fname_stem}"_%1d_%1a".pgm | cksum + +rm ${fname_stem}_?_?.pgm + + +# Test 4. +echo "Test 4." + +# Add margins to testgrid.pbm + +testimg_pbm=${tmpdir}/testimg.pbm +pnmpad -top=2 -left=3 -black testgrid.pbm > ${testimg_pbm} + +for x in `seq 0 1` + do for y in `seq 0 4` + do cp ${testimg_pbm} ${fname_stem}_${y}_${x}.pbm; done + done + +for (( i=0 ; i<=9; ++i)) + do + echo ${testimg_pbm} + done | pamundice -down=5 -across=2 -listfile=- | cksum + +pamundice -down=5 -across=2 ${fname_stem}_"%1d"_"%1a".pbm | cksum + +echo "A warning message should appear below the line." 1>&2 +echo "-----------------------------------------------------------" 1>&2 + +pamundice -down=5 -across=2 ${testimg_pbm} | cksum + +pnmtile 34 90 ${testimg_pbm} | cksum + +rm ${testimg_pbm} + +# Test Invalid. +echo "Test Invalid" + +test_out=${tmpdir}/test_out + +echo 1>&2 +echo "Invalid command-line argument combinations." 1>&2 +echo "Error messages should appear below the line." 1>&2 +echo "-----------------------------------------------------------" 1>&2 + +# No input file pattern specified +pamundice -down=5 -across=2 > ${test_out} || \ +echo -n "Expected failure 1"; test -s ${test_out}; echo " "$? + +# -down=0 +pamundice -down=0 -across=2 ${fname_stem}_"%1d"_"%1a".pbm > ${test_out} || \ +echo -n "Expected failure 2"; test -s ${test_out}; echo " "$? + +# -across=0 +pamundice -down=5 -across=0 ${fname_stem}_"%1d"_"%1a".pbm > ${test_out} || \ +echo -n "Expected failure 3"; test -s ${test_out}; echo " "$? + +# -down too large +pamundice -down=6 -across=2 ${fname_stem}_"%1d"_"%1a".pbm > ${test_out} || \ +echo -n "Expected failure 4"; test -s ${test_out}; echo " "$? + +# -across too large +pamundice -down=5 -across=3 ${fname_stem}_"%1d"_"%1a".pbm > ${test_out} || \ +echo -n "Expected failure 5"; test -s ${test_out}; echo " "$? + +# precision does not match +pamundice -down=5 -across=2 ${fname_stem}_"%2d"_"%2a".pbm > ${test_out} || \ +echo -n "Expected failure 6"; test -s ${test_out}; echo " "$? + +# precision set to zero +pamundice -down=5 -across=2 ${fname_stem}_"%0d"_"%0a".pbm > ${test_out} || \ +echo -n "Expected failure 7"; test -s ${test_out}; echo " "$? + +# no precision +pamundice -down=5 -across=2 ${fname_stem}_"%d"_"%a".pbm > ${test_out} || \ +echo -n "Expected failure 8"; test -s ${test_out}; echo " "$? + +# -hoverlap too large +pamundice -down=5 -across=2 -hoverlap=18 \ + ${fname_stem}_"%1d"_"%1a".pbm > ${test_out} || \ +echo -n "Expected failure 9"; test -s ${test_out}; echo " "$? + +# -voverlap too large +pamundice -down=5 -across=2 -voverlap=19 \ + ${fname_stem}_"%1d"_"%1a".pbm > ${test_out} || \ +echo -n "Expected failure 10"; test -s ${test_out}; echo " "$? + +# corrupt listfile : file names do not exist +seq 10 | sed -e 's/^/::::::/' -e 's/$/::::::/' | \ + pamundice -down=5 -across=2 -listfile=- > ${test_out} || \ +echo -n "Expected failure 11"; test -s ${test_out}; echo " "$? + +# listfile with insufficient lines (insufficient file entries) +ls ${fname_stem}_*_*.pbm | head -n 9 | \ + pamundice -down=5 -across=2 -listfile=- > ${test_out} || \ +echo -n "Expected failure 12"; test -s ${test_out}; echo " "$? + +rm ${fname_stem}*.pbm + -- cgit 1.4.1