#! /bin/sh
# This script tests: pgmtofs fstopgm
# Also requires: pamchannel pamtopnm pgmramp pgmmake

echo "Test 1.  Should produce 1571496937 33838"
# cksum of testimg.red

pamchannel -infile=testimg.ppm -tupletype="GRAYSCALE" 0 |\
    pamtopnm | pgmtofs | fstopgm | cksum

echo "Test 2.  Should produce 2582999797 3376"
# pamdepth 255 maze.pbm | cksum 

pgmtofs maze.pbm | fstopgm | cksum

echo "Test 3.  Should produce 493599905 16"
# pgmramp -lr 5 1 | cksum

pgmramp -lr 5 1 | pgmtofs | fstopgm | cksum

tmpdir=${tmpdir:-/tmp}
test1_pgm=${tmpdir}/test1.pgm
test3_pgm=${tmpdir}/test3.pgm
test7_pgm=${tmpdir}/test7.pgm
test15_pgm=${tmpdir}/test15.pgm

echo "Test 4.1.  Should produce 3735757243 10"
pgmmake -maxval=1 0.1 1 1 | tee ${test1_pgm} | cksum

echo "Test 4.2.  Should produce 1655769442 10"
pgmmake -maxval=3 0.1 1 1 | tee ${test3_pgm} | cksum

echo "Test 4.3.  Should produce 3428680891 10"
pgmmake -maxval=7 0.1 1 1 | tee ${test7_pgm} | cksum

echo "Test 4.4.  Should produce 1663150238 11"
pgmmake -maxval=15 0.1 1 1 | tee ${test15_pgm} | cksum


echo "Test invalid"

. ./test-invalid.inc

test256_pgm=${tmpdir}/test256.pgm
test_fs=${tmpdir}/test.fs

pgmmake -maxval=256 0.1 1 1 > ${test256_pgm}
invCmd "pgmtofs ${test256_pgm}"
rm ${test256_pgm}

pgmtofs ${test1_pgm} > ${test_fs}
invCmd "fstopgm ${test_fs}"
rm ${test1_pgm} ${test_fs}

pgmtofs ${test3_pgm} > ${test_fs}
invCmd "fstopgm ${test_fs}"
rm ${test3_pgm} ${test_fs}

pgmtofs ${test7_pgm} > ${test_fs}
invCmd "fstopgm ${test_fs}"
rm ${test7_pgm} ${test_fs}

pgmtofs ${test15_pgm} > ${test_fs}
invCmd "fstopgm ${test_fs}"
rm ${test15_pgm} ${test_fs}

