about summary refs log tree commit diff
path: root/test/pamcut.test
blob: e4d8c62f6e65cad7329c7930d3a1bf4d2e79ccf2 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#! /bin/bash
# This script tests: pamcut pbmmake
# Also requires:

# Test 1.  Should print 2958909756 124815
echo Test 1.

pamcut -top 0 -left 0 -width 260 -height 160 \
  -pad testimg.ppm | cksum

# Test 2.  Should print 1550940962 10933
echo Test 2.

pamcut -top 200 -left 120 -width 40 -height 40 \
  -pad testimg.ppm | cksum

# Test 3.  Should print 708474423 14 twice
echo Test 3.

pamcut -top 5 -left 5 -bottom 5 -right 5 testimg.ppm | cksum
pamcut -width 1 -height 1 -bottom 5 -right 5 testimg.ppm | cksum


# Test 4.  Should print 659346598 80124 four times
echo Test 4.

pamcut -croptop 10 -cropleft 10 -cropbottom 10 -cropright 10 testimg.ppm | \
  cksum
pamcut -top 10 -left 10 -bottom 138 -right 216 testimg.ppm | cksum
pamcut -top 10 -left 10 -bottom -11 -right -11 testimg.ppm | cksum
pamcut -top 10 -left 10 -width 207 -height 129 testimg.ppm | cksum


# Test 5. Should print 2425386270 41 five times
echo Test 5.

pamcut -croptop 0 -cropleft 0 -cropbottom 0 -cropright 0 testgrid.pbm | \
  cksum
pamcut -top 0 -left 0 -bottom 15 -right 13 testgrid.pbm | cksum
pamcut -top 0 -left 0 -bottom -1 -right -1 testgrid.pbm | cksum
pamcut -top 0 -left 0 -width 14 -height 16 testgrid.pbm | cksum
pamcut testgrid.pbm | cksum

# Test 6.  Should print 3412257956 129
echo Test 6.

pbmmake -g 50 50 | pamcut 5 5 30 30 | cksum


echo "Test Invalid"

tmpdir=${tmpdir:-/tmp}
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

# overspecification
pamcut -left=1 -right=1 -width=14 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 1"; test -s ${test_out}; echo " "$?

pamcut -top=1 -bottom=1 -height=16 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 2"; test -s ${test_out}; echo " "$?

pamcut -right=1 -cropright=1 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 3"; test -s ${test_out}; echo " "$?

pamcut -top=1 -croptop=1 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 4"; test -s ${test_out}; echo " "$?

pamcut -bottom=1 -cropbottom=1 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 5"; test -s ${test_out}; echo " "$?

pamcut -left=1 -cropleft=1 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 6"; test -s ${test_out}; echo " "$?

# excessive cropping
pamcut -cropleft=7 -cropright=8 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 7"; test -s ${test_out}; echo " "$?

pamcut -left=7 -right=6 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 8"; test -s ${test_out}; echo " "$?

pamcut -croptop=8 -cropbottom=8 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 9"; test -s ${test_out}; echo " "$?

pamcut -top=10 -bottom=9 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 6"; test -s ${test_out}; echo " "$?

# pad absent
pamcut -cropleft=1 -width=14 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 10"; test -s ${test_out}; echo " "$?

pamcut -croptop=1  -height=16 testgrid.pbm > ${test_out} || \
   echo -n "Expected failure 11"; test -s ${test_out}; echo " "$?

# legacy style: insufficient number of positional parameters
pamcut 5 testimg.ppm > ${test_out} || \
   echo -n "Expected failure 12"; test -s ${test_out}; echo " "$?

pamcut 5 4 testimg.ppm > ${test_out} || \
   echo -n "Expected failure 13"; test -s ${test_out}; echo " "$?

pamcut 5 5 30 testimg.ppm > ${test_out} || \
   echo -n "Expected failure 14"; test -s ${test_out}; echo " "$?

rm -f ${test_out}