about summary refs log tree commit diff
path: root/test/pamarith.test
blob: d8055385940aee2b15d5c3c159e3bafb808d4166 (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

#! /bin/bash
# This script tests: pamarith
# Also requires: pamchannel pamseq pamtopnm pgmmake pnmcat rgb3toppm
# Also requires: pbmmake pamenlarge

tmpdir=${tmpdir:-/tmp}
input1_pgm=${tmpdir}/input1.pgm
input2_pgm=${tmpdir}/input2.pgm
output_pgm=${tmpdir}/output.pgm
input1_ppm=${tmpdir}/input1.ppm
input2_ppm=${tmpdir}/input2.ppm

echo "Test 1"

pamseq 1 15 | pamtopnm -assume > ${input1_pgm}
pgmmake -maxval 15 0.15 16 1 > ${input2_pgm}

rgb3toppm ${input1_pgm} ${input1_pgm} ${input1_pgm} > ${input1_ppm} 
rgb3toppm ${input2_pgm} ${input2_pgm} ${input2_pgm} > ${input2_ppm} 

pnmcat -tb -plain ${input1_pgm} ${input2_pgm}

for fn in "-add" "-subtract" "-multiply" "-divide" "-difference" \
    "-minimum" "-maximum" "-mean" "-compare" \
    "-and" "-or" "-nand" "-nor"  "-xor" \
    "-shiftleft" "-shiftright"
  do
  echo ${fn}
  pamarith ${fn} -plain ${input1_pgm} ${input2_pgm} | tr '\n' ' '; echo
  pamarith ${fn} ${input1_pgm} ${input2_pgm} > ${output_pgm}
  rgb3toppm  ${output_pgm} ${output_pgm} ${output_pgm} | cksum
  pamarith ${fn} ${input1_ppm} ${input2_pgm} | cksum
  pamarith ${fn} ${input1_ppm} ${input2_ppm} | cksum
  done

rm ${input1_pgm} ${input2_pgm} ${output_pgm} ${input2_ppm}


input1_pbm=${tmpdir}/input1.pbm
input2_pbm=${tmpdir}/input2.pbm

echo "Test 2 PBM"

pbmmake -g 8 1 > ${input1_pbm}
pbmmake -g 2 1 | pamenlarge -xscale=4 > ${input2_pbm}

pnmcat -tb -plain ${input1_pbm} ${input2_pbm}

for fn in "-add" "-subtract" "-multiply" "-divide" "-difference" \
    "-minimum" "-maximum" "-mean" "-compare" \
    "-and" "-or" "-nand" "-nor"  "-xor" \
    "-shiftleft" "-shiftright"
  do
  echo ${fn}
  pamarith ${fn} -plain ${input1_pbm} ${input2_pbm} | tr '\n' ' '; echo
  done

rm ${input1_pbm} ${input2_pbm}


echo "Test 3 (input = output)"
echo "cksum is 2425386270 41 or 2921940274 59"

for image in testgrid.pbm ${input1_ppm}
  do
  echo "input image"
  cat ${image} | cksum 
  for fn in "-minimum" "-maximum" "-mean" "-and" "-or"
    do
    echo ${fn}
    pamarith ${fn} ${image} ${image} | cksum
    done
  done


echo "Test 4 (blank output)"
echo "cksum is 2817549367 41 or 320101399 59"

for image in testgrid.pbm ${input1_ppm}
  do
  for fn in "-subtract" "-difference" "-xor"
    do
    echo ${fn}
    pamarith ${fn} ${image} ${image} | cksum
    done
  done

rm ${input1_ppm}


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

pamarith -add -subtract testimg.ppm testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 1"
  test -s ${output_ppm}; echo " "$?
pamarith -multiply -divide testimg.ppm testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 2"
  test -s ${output_ppm}; echo " "$?
pamarith -difference -minimum testimg.ppm testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 3"
  test -s ${output_ppm}; echo " "$?
pamarith -maximum -mean testimg.ppm testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 4"
  test -s ${output_ppm}; echo " "$?
pamarith -compare -and testimg.ppm testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 5"
  test -s ${output_ppm}; echo " "$?
pamarith -or -nand testimg.ppm testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 6"
  test -s ${output_ppm}; echo " "$?
pamarith -nor -xor testimg.ppm testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 7"
  test -s ${output_ppm}; echo " "$?
pamarith -shiftleft -shiftright testimg.ppm testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 8"
  test -s ${output_ppm}; echo " "$?
pamarith -add=1 testimg.ppm testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 9"
  test -s ${output_ppm}; echo " "$?

pamarith -plain testimg.ppm testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 10"
  test -s ${output_ppm}; echo " "$?

pamarith testimg.ppm testimg.ppm > ${output_ppm} || \
  echo -n "Expected failure 11"
  test -s ${output_ppm}; echo " "$?

pamarith -add testimg.ppm testimg.ppm testimg.ppm > ${output_ppm}
  echo -n "Expected failure 12"
  test -s ${output_ppm}; echo " "$?
pamarith -add testimg.ppm > ${output_ppm}
  echo -n "Expected failure 13"
  test -s ${output_ppm}; echo " "$?
pamarith -add > ${output_ppm}
  echo -n "Expected failure 14"
  test -s ${output_ppm}; echo " "$?

pamarith -add testimg.ppm testgrid.pbm > ${output_ppm}
  echo -n "Expected failure 15"
  test -s ${output_ppm}; echo " "$?

pamchannel -infile testimg.ppm 0 1 | \
  pamarith -add testimg.ppm - > ${output_ppm}
  echo -n "Expected failure 16"
  test -s ${output_ppm}; echo " "$?

pamenlarge -xscale=2 testgrid.pbm | \
  pamarith -add testgrid.pbm - > ${output_ppm}
  echo -n "Expected failure 17"
  test -s ${output_ppm}; echo " "$?

pamenlarge -yscale=3 testgrid.pbm | \
  pamarith -add testgrid.pbm - > ${output_ppm}
  echo -n "Expected failure 18"
  test -s ${output_ppm}; echo " "$?

rm ${output_ppm}