#! /bin/sh
# This script tests: pbmtomacp macptopbm
# Also requires: pnmcrop pbmpage pbmupc pnmpad pbmmake

tmpdir=${tmpdir:-/tmp}
temp1_pbm=${tmpdir}/temp1.pbm
temp2_pbm=${tmpdir}/temp2.pbm
tempupc_pbm=${tmpdir}/tempupc.pbm
temp3_pbm=${tmpdir}/temp3.pbm
temp3_macp=${tmpdir}/temp3.macp

# Macpaint files are fixed size (576 x 720 pixels)
# pbmtomacp automatically adds padding when input is smaller.

echo "Test 1. Should produce 281226646 481 twice"
pbmtomacp maze.pbm | macptopbm | tee ${temp1_pbm} | \
    pnmcrop | cksum

pbmtomacp ${temp1_pbm} | macptopbm | pnmcrop | cksum

rm ${temp1_pbm}

echo "Test 2. Should produce 2329957971 51851"
pbmpage 1 | pbmtomacp | macptopbm | cksum

echo "Test 3. Should produce 2907103393 5086 three times"
pbmupc 0 12345 67890 | tee ${tempupc_pbm} | \
    pnmpad -black -t 44 -b 20 -l 100 -r 251 | \
    pbmtomacp | macptopbm | \
    tee ${temp2_pbm} | \
    pnmcrop | pnmcrop | cksum

pnmpad -black -t 44 -l 100 ${tempupc_pbm} | \
    pbmtomacp|  macptopbm | pnmcrop -white | pnmcrop | cksum

pbmtomacp ${temp2_pbm} | macptopbm | pnmcrop | pnmcrop | cksum

rm ${temp2_pbm} ${tempupc_pbm}


echo "Test 4. Should produce 3432623660 51851 four times"
pbmmake -b 576 720 | tee ${temp3_pbm} | cksum

pbmtomacp ${temp3_pbm} | tee ${temp3_macp} | macptopbm | cksum

pbmtomacp -norle ${temp3_pbm} | macptopbm | cksum

( head -c 128 /dev/zero ; cat ${temp3_macp} ) | \
    macptopbm -extraskip 128 | cksum

rm ${temp3_pbm} ${temp3_macp}
