about summary refs log tree commit diff
path: root/test/pamcut.test
blob: fce61ea849faf28bfb13c4bb34506a2f5d536a36 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
#! /bin/sh
# This script tests: pamcut pbmmake
# Also requires: pamfile pnmpad

echo "Test 1a.  Should print 0 259 0 159 227 149 260 160 twice"

pamcut -left 0 -right 259 -top 0 -bottom 159 \
       -pad -reportonly testimg.ppm
pamcut  -left 0 -top 0 -width 260 -height 160 \
       -pad -reportonly testimg.ppm

echo "Test 1b.  Should print 2958909756 124815"

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

echo "Test 2a.  Should print 120 159 120 159 227 149 40 40 three times"

pamcut -left 120 -right 159 -top 120 -bottom 159 \
  -pad -reportonly testimg.ppm
pamcut -right 159 -bottom 159 -width 40 -height 40 \
  -pad -reportonly testimg.ppm
pamcut -left 120 -top 120 -width 40 -height 40 \
  -pad -reportonly testimg.ppm

echo "Test 2b.  Should print 3876978825 4813 twice"

pamcut -left 120 -right 159 -top 120 -bottom 159 \
  -pad testimg.ppm | cksum
pamcut -left 120 -top 120 -width 40  \
  -pad testimg.ppm | pnmpad -black -bottom 11 | cksum

echo "Test 3a.  Should print 5 5 5 5 227 149 1 1 three times"

pamcut -top 5 -left 5 -bottom 5 -right 5 -reportonly testimg.ppm
pamcut -width 1 -height 1 -bottom 5 -right 5 -reportonly testimg.ppm
pamcut -cropleft 5 -croptop 5 -width 1 -height 1 -reportonly testimg.ppm

echo "Test 3b.  Should print 708474423 14"

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

echo "Test 4a.  Should print 10 216 10 138 227 149 207 129 five times"

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

echo "Test 4b.  Should print 659346598 80124"

pamcut -top 10 -left 10 -width 207 -height 129 testimg.ppm | cksum

echo "Test 5a. Should print 0 56 0 58 57 59 57 59 five times"

mazesize=$(pamfile -size maze.pbm)
width=$(echo ${mazesize} | cut -d " " -f 1)
height=$(echo ${mazesize} | cut -d " " -f 2)

pamcut -croptop 0 -cropleft 0 -cropbottom 0 -cropright 0 \
       -reportonly maze.pbm
pamcut -top 0 -left 0 \
       -bottom $((${height} -1)) -right $((${width} -1)) \
        -reportonly maze.pbm
pamcut -top 0 -left 0 -bottom -1 -right -1 -reportonly maze.pbm 
pamcut -top 0 -left 0 -width ${width} -height ${height} \
       -reportonly maze.pbm
pamcut -reportonly maze.pbm 

echo "Test 5b. Should print 281226646 481 twice"

pamcut -croptop 0 -cropleft 0 -cropbottom 0 -cropright 0 maze.pbm | \
  cksum
pamcut maze.pbm | cksum


echo "Test 6a.  Should print 5 34 5 34 50 50 30 30"

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

echo "Test 6b.  Should print 3412257956 129"

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

echo "Test 7.  Should print 1576602925 8 four times"

pbmmake -b 1 1 | cksum
pbmmake -g 5 5 | pamcut -pad -left=6 -right=6 -top=6 -bottom 6 | cksum
pbmmake -g 5 5 | pamcut -pad -left=-6 -right=-6 -top=-6 -bottom -6 | cksum
pbmmake -g 5 5 | pamcut -pad -left=101 -right=101 -top=1001 -bottom 1001 | cksum

echo "Test Invalid"

. ${srcdir}/test-invalid.inc

# overspecification
invCmd "pamcut -left=1 -right=1 -width=14 testgrid.pbm"
invCmd "pamcut -top=1 -bottom=1 -height=16 testgrid.pbm"
invCmd "pamcut -right=1 -cropright=1 testgrid.pbm"
invCmd "pamcut -top=1 -croptop=1 testgrid.pbm"
invCmd "pamcut -bottom=1 -cropbottom=1 testgrid.pbm"
invCmd "pamcut -left=1 -cropleft=1 testgrid.pbm"

# excessive amounts
invCmd "pamcut -cropleft=14 testgrid.pbm"
invCmd "pamcut -cropleft=7 -cropright=8 testgrid.pbm"
invCmd "pamcut -left=7 -right=6 testgrid.pbm"
invCmd "pamcut -croptop=16 testgrid.pbm"
invCmd "pamcut -croptop=8 -cropbottom=8 testgrid.pbm"
invCmd "pamcut -top=10 -bottom=9 testgrid.pbm"

# pad absent
invCmd "pamcut -cropleft=1 -width=14 testgrid.pbm"
invCmd "pamcut -croptop=1  -height=16 testgrid.pbm"

# legacy style: insufficient number of positional parameters
invCmd "pamcut 5 testimg.ppm"
invCmd "pamcut 5 4 testimg.ppm"
invCmd "pamcut 5 5 30 testimg.ppm"