about summary refs log tree commit diff
path: root/test/pnmcrop1.test
blob: 088ecf4677e54c0861119eb3c00681d77399b691 (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
#! /bin/bash
# This script tests: pnmcrop
# Also requires: pnmpad pnmmargin pamcut

tmpdir=${tmpdir:-/tmp}

test_pbm=${tmpdir}/test.pbm
test_ppm=${tmpdir}/test.ppm

pnmmargin -white 7 testgrid.pbm | pnmpad -black -bottom=2  > ${test_pbm}
pnmmargin -white 6 testimg.ppm  | pnmpad -black -right=11  > ${test_ppm}

#Test 1
echo Test 1

for input_file in ${test_pbm} ${test_ppm}
  do
  echo `basename ${input_file}`
  for option in "" "-white" "-black" "-sides" \
              "-top" "-bottom" "-left" "-right" "-top -bottom" \
              "-bottom -bg-corner=bottomright" \
              "-right -bg-corner=bottomright" \
              "-bg-color=white" "-bg-color=black" "-bg-color=red"
    do
    echo ${option}
    pnmcrop -reportfull ${option} ${input_file} || echo fail
    done
  done

#Test 2
echo Test 2

for input_file in ${test_pbm} ${test_ppm}
  do
  echo `basename ${input_file}`
  for option in "" "-white" "-top"
    do
    echo ${option}
    # Normal crop operation
    pnmcrop ${option} ${input_file} | cksum

    # Compute edge extents with pnmcrop; let pamcut do the actual cropping
    pamcut ${input_file} `pnmcrop -reportsize ${option} ${input_file} | \
        awk 'NF==6 && NR==1 && \
             $1<=0 && $2<=0 && $3<=0 && $4<=0 && $5>=0 && $6>=0 \
             { printf("-cropleft=%d -cropright=%d  ", -$1, -$2);
               printf("-croptop=%d -cropbottom=%d", -$3, -$4) }' ` | cksum
    done
  done

rm ${test_pbm} ${test_ppm}

# Test 3

echo 1>&2
echo "Invalid command-line argument combinations." 1>&2
echo "Error messages should appear below the line." 1>&2
echo "-----------------------------------------------------------" 1>&2

echo Test 3
for option in "-reportfull -reportsize" \
              "-reportfull -borderfile=testgrid.pbm" \
              "-reportsize -borderfile=testgrid.pbm" \
              "-black -white" \
              "-black -sides" \
              "-white -bg-color=red" \
              "-white -bg-corner=topleft" \
              "-white -bg-corner=top" \
              "-bg-color=black -bg-color=white" \
              "-bg-corner=topleft -bg-corner=bottomright" \
              "-blank-image=maxcrop" \
              "-blank-image=past" \
              "-bg-color=black -closeness=-1" \
              "-bg-color=black -closeness=101"
    do
    echo ${option}
    pnmcrop -reportfull ${option} testgrid.pbm || echo expected failure
    done