about summary refs log tree commit diff
path: root/test/pamfunc.test
blob: fa2570b45412d0f603f347894d7badd1b9dfdf29 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#! /bin/bash
# This script tests: pamfunc
# Also requires: pamseq pamtopnm pbmmake

tmpdir=${tmpdir:-/tmp}
input_pgm=${tmpdir}/input.pgm

echo "Test 1"

pamseq 1 15 | pamtopnm -assume > ${input_pgm}
pamtopnm -plain ${input_pgm} | tr '\n' ' '; echo

pamfunc -adder=3 -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -subtractor=3 -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -multiplier=3 -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -divisor=2 -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -max=6 -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -min=5 -plain ${input_pgm} | tr '\n' ' '; echo

pamfunc -shiftleft  1  -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -shiftright 1  -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -shiftleft  1 ${input_pgm} | pamfunc -shiftright 1 -plain | \
  tr '\n' ' '; echo
pamfunc -shiftright 1 ${input_pgm} | pamfunc -shiftleft 1  -plain | \
  tr '\n' ' '; echo


input_pbm=${tmpdir}/input.pbm

echo "Test 2"

pbmmake -g 8 1 > ${input_pbm}
pamtopnm -plain ${input_pbm} | tr '\n' ' '; echo

pamfunc -adder=1 -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -subtractor=1 -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -multiplier=1 -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -divisor=1 -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -max=1 -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -min=1 -plain ${input_pbm} | tr '\n' ' '; echo

pamfunc -shiftleft  1  -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -shiftright 1  -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -shiftleft  1 ${input_pbm} | pamfunc -shiftright 1 -plain | \
  tr '\n' ' '; echo
pamfunc -shiftright 1 ${input_pbm} | pamfunc -shiftleft 1  -plain | \
  tr '\n' ' '; echo


echo "Test 3 (-changemaxval)"

pamfunc -divisor 2 -changemaxval ${input_pgm} -plain | \
  tr '\n' ' '; echo
pamfunc -multiplier 0.25 -changemaxval ${input_pgm} -plain | \
  tr '\n' ' '; echo
pamfunc -divisor 2 -changemaxval ${input_pbm} -plain | \
  tr '\n' ' '; echo
pamfunc -multiplier 0.25 -changemaxval ${input_pbm} -plain | \
  tr '\n' ' '; echo

rm ${input_pgm} ${input_pbm}

echo "Test 4: Should print 1926073387 101484 eight times"

cat testimg.ppm | cksum

pamfunc -not testimg.ppm | pamfunc -not | cksum
pamfunc -andmask 0xff testimg.ppm | cksum
pamfunc -ormask  0x00 testimg.ppm | cksum
pamfunc -xormask 0x00 testimg.ppm | cksum
pamfunc -xormask 0xff testimg.ppm | pamfunc -xormask 0xff | cksum
pamfunc -shiftleft  0 testimg.ppm | cksum
pamfunc -shiftright 0 testimg.ppm | cksum


echo "Test 5: Should print 2425386270 41 six times"

cat testgrid.pbm | cksum

pamfunc -andmask  0x1 testgrid.pbm | cksum
pamfunc -ormask   0x0 testgrid.pbm | cksum
pamfunc -xormask  0x1 testgrid.pbm | pamfunc -xormask 0x1 | cksum

pamfunc -shiftleft  0 testgrid.pbm | cksum
pamfunc -shiftright 0 testgrid.pbm | cksum

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

echo "Test Invalid"

output_ppm=${tmpdir}/output.ppm

pamfunc -multiplier testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 1"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -multiplier=-1 testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 2"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -divisor testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 3"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -divisor=-20 testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 4"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -adder testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 5"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -adder 0.5 testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 6"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -subtractor testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 7"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -subtractor 0.1 testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 8"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -multiplier=1 -divisor=2 testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 9"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -adder=2 -subtractor=3 testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 10"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -min testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 11"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -max testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 12"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -andmask testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 13"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -ormask testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 14"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -xormask testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 15"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -not 1 testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 16"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -min=1 -max=2 testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 17"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -andmask=1 -ormask=0 testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 18"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -andmask=0xffff testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 19"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -shiftleft testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 20"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -shiftright testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 21"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -changemaxval testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 22"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -shiftleft=1 -shiftright=1 testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 23"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}

pamfunc -multiplier=0.5 -changemaxval=65535 testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 24"
  test -s ${output_ppm}; echo " "$?
  rm -f ${test_out}