about summary refs log tree commit diff
path: root/test/pnmcat.test
blob: 02fefd387f62fbafbd548f79afd1817fc3cc7cf2 (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
#! /bin/sh
# This script tests: pnmcat
# Also requires: pbmmake pgmramp ppmtoppm pamcat

if [ ${CHECK_TYPE} = tree ]
  then echo "Skipping." 1>&2
       echo "Running \"make package; make check\" is recommended." 1>&2
  exit 80;
fi

tmpdir=${tmpdir:-/tmp}
check2x2_pbm=${tmpdir}/check2x2.pbm
maze2lr_pbm=${tmpdir}/maze2lr.pbm
maze2tb_pbm=${tmpdir}/maze2tb.pbm
diag_pgm=${tmpdir}/diag.pgm
diag_ppm=${tmpdir}/diag.ppm
diag2lr_ppm=${tmpdir}/diag2lr.ppm
diag2tb_ppm=${tmpdir}/diag2tb.ppm

echo "Test 1.  Should print a simple PBM image five times"
# Check input from stdin and from designated input file
# Similar to tests in stdin-p?m.test

pbmmake -g 2 2 | tee ${check2x2_pbm} | pnmcat -lr -plain
pnmcat -tb -plain ${check2x2_pbm}
pnmcat -tb -plain < ${check2x2_pbm}
pnmcat -lr -black -plain ${check2x2_pbm}
cat ${check2x2_pbm} | pnmcat -tb -white -plain

rm ${check2x2_pbm}

echo "Test 2.  Should print 2197356643 895 twice"
pnmcat -lr -white maze.pbm maze.pbm | tee ${maze2lr_pbm} | cksum
cat maze.pbm | pnmcat -lr -black maze.pbm - | cksum

echo "Test 3.  Should print 3313353797 954"
pnmcat -tb maze.pbm maze.pbm | tee ${maze2tb_pbm} | cksum

echo "Test 4.  Should print 1731660895 1308 three times"
pnmcat -lr maze.pbm maze.pbm maze.pbm | cksum
pnmcat -lr ${maze2lr_pbm} maze.pbm | cksum
cat ${maze2lr_pbm} | pnmcat -lr - maze.pbm | cksum

echo "Test 5.  Should print 2985957591 1426 three times"
pnmcat -tb maze.pbm maze.pbm maze.pbm | cksum
pnmcat -tb maze.pbm ${maze2tb_pbm} | cksum
cat maze.pbm | pnmcat -tb - ${maze2tb_pbm} | cksum

rm ${maze2lr_pbm} ${maze2tb_pbm}

echo "Test 6.  Should print a simple PGM image three times"
# Use sed to scrape off space at line end for compatibility
# with older versions of pnmcat

pgmramp -diag 4 4 -maxval=3 | tee ${diag_pgm} | pnmcat -lr -plain |\
  sed 's/ *$//'
pnmcat -tb -plain ${diag_pgm} | sed 's/ *$//'
cat ${diag_pgm} | pnmcat -tb -plain | sed 's/ *$//'

rm ${diag_pgm}

pgmramp -diag 8 8 -maxval 7 | ppmtoppm > ${diag_ppm} 

echo "Test 7.  Should print 2097565808 394 twice"
pnmcat -lr -black ${diag_ppm} ${diag_ppm} | tee ${diag2lr_ppm} | cksum
cat ${diag_ppm} | pnmcat -lr -white ${diag_ppm} - | cksum

echo "Test 8.  Should print 3086569577 394"
pnmcat -tb ${diag_ppm} ${diag_ppm} | tee ${diag2tb_ppm} | cksum

echo "Test 9.  Should print 4288335051 586 three times"
pnmcat -lr ${diag_ppm} ${diag_ppm} ${diag_ppm} | cksum
pnmcat -lr ${diag_ppm}  ${diag2lr_ppm} | cksum 
cat ${diag2lr_ppm} | pnmcat -lr - ${diag_ppm} | cksum

echo "Test 10.  Should print 642720605 586 three times"
pnmcat -tb ${diag_ppm} ${diag_ppm} ${diag_ppm} | cksum
pnmcat -tb ${diag2tb_ppm} ${diag_ppm} | cksum
cat ${diag_ppm} | pnmcat -tb ${diag2tb_ppm} - | cksum

rm ${diag2lr_ppm} ${diag2tb_ppm}

echo "Test 11.  Should print 3622741282 1019 twice"
pnmcat -tb -white testgrid.pbm ${diag_ppm} | cksum
pnmcat -tb -jcenter -white testgrid.pbm ${diag_ppm} | cksum
echo "Test 12.  Should print 1401081637 1019"
pnmcat -tb -jleft -white testgrid.pbm ${diag_ppm}  | cksum
echo "Test 13.  Should print 2756501917 1019"
pnmcat -tb -jright -white testgrid.pbm ${diag_ppm} | cksum

echo "Test 14. Should print 587933655 107742 twice"
pnmcat -lr -black testgrid.pbm testimg.ppm | cksum
pnmcat -lr -jcenter -black testgrid.pbm testimg.ppm | cksum
echo "Test 15.  Should print 3948141157 107742"
pnmcat -lr -jtop -black testgrid.pbm testimg.ppm | cksum
echo "Test 16.  Should print 3910239002 107742"
pnmcat -lr -jbottom -black testgrid.pbm testimg.ppm | cksum

rm ${diag_ppm}

echo "Test Invalid"

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

# direction not specified
pnmcat testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 1 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

# both directions specified
pnmcat -topbottom -leftright testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 2 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

# both pad colors specified
pnmcat -topbottom -white -black testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 3 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

# justification parameters overspecified
pnmcat -lr -jtop -jbottom testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 4 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

pnmcat -lr -jtop -jcenter testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 5 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

pnmcat -lr -jcenter -jbottom testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 6 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

pnmcat -tb -jleft -jright testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 7 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

pnmcat -tb -jleft -jcenter testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 8 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

pnmcat -tb -jcenter -jright testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 9 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

# justification parameter in the wrong direction
pnmcat -lr -jleft    testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 10 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

pnmcat -lr -jright   testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 11 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

pnmcat -tb -jtop     testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 12 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

pnmcat -tb -jbottom  testgrid.pbm testimg.ppm > ${test_out} || \
  printf "Expected failure 13 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}

# more than one input image from standard input
cat testgrid.pbm | pnmcat -lr - - testimg.ppm > ${test_out} || \
  printf "Expected failure 14 "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}