about summary refs log tree commit diff
path: root/test/pnmcrop3.test
blob: 1e8da3456eadf4a4273b9741710ac0b7a08fa731 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /bin/sh
# This script tests: pnmcrop
# Also requires: pnmpad pamfile pgmmake

tmpdir=${tmpdir:-/tmp}

test_pbm=${tmpdir}/test.pbm
test_ppm=${tmpdir}/test.ppm
border_pbm=${tmpdir}/border.pbm
border_ppm=${tmpdir}/border.ppm
gray_pgm=${tmpdir}/gray.pgm

pnmpad -top=3 -bottom=5 -left=11 -right=2 testgrid.pbm > ${test_pbm}
pnmpad -top=11 -bottom=1 -left=21 -right=9 testimg.ppm > ${test_ppm}

pnmpad -top=4 -bottom=4 -left=8 -right=5 testgrid.pbm > ${border_pbm}
pnmpad -top=7 -bottom=5 -left=30 -right=0 testimg.ppm > ${border_ppm}

pgmmake 0.5 $(pamfile -size ${test_pbm}) > ${gray_pgm}

# Test 1
echo Test 1

for input_file in ${test_pbm} ${test_ppm}
  do
  echo `basename ${input_file}`
  for option in "-left" "-right" "-top" "-bottom" \
            "-left -right" "-left -bottom" "-right -bottom"
    do
    echo ${option}
    pnmcrop -reportsize ${option} ${input_file} || echo fail1
    done
  done

# Test 2
echo Test 2

for input_file in ${test_pbm} ${test_ppm}
  do
  echo `basename ${input_file}`
  for margin in 0 1 2 3 4 5  # for margin in `seq 0 5`
    do
    pnmcrop -reportsize -margin=${margin} ${input_file} || echo fail2
    done
  done

# Test 3
echo Test 3

pnmcrop -borderfile=${border_pbm} ${gray_pgm} | pamfile -size
pnmcrop -borderfile=${border_pbm} ${gray_pgm} -plain 

pnmcrop -borderfile=${test_pbm} ${test_pbm}   | pamfile -size
pnmcrop -borderfile=${test_pbm} ${test_pbm}   | pnmcrop -black -reportsize

pnmcrop -borderfile=${border_pbm} ${test_pbm} | pamfile -size
pnmcrop -borderfile=${border_pbm} ${test_pbm} -plain
pnmcrop -borderfile=${border_pbm} ${test_pbm} | pnmcrop -black -reportsize

pnmcrop -borderfile=${border_ppm} ${test_ppm} | cksum 

test_out=${tmpdir}/test_out

# The following two cases are expected to fail

echo "Border file size mismatch" 1>&2
echo "Error messages should appear below the line." 1>&2
echo "--------------------------------------------" 1>&2

pnmcrop -borderfile=${border_ppm} ${test_pbm} > ${test_out} || \
        printf "Expected failure 1";
        test -s ${test_out}; echo " "$?
        rm ${test_out}

pnmcrop -borderfile=${border_pbm} ${test_ppm} > ${test_out} || \
        printf "Expected failure 2";
        test -s ${test_out}; echo " "$?
        rm ${test_out}

rm ${test_pbm} ${test_ppm} ${border_pbm} ${border_ppm} ${gray_pgm}