blob: 247f76c5fc1e7c2b1258da8035f89f1b276126d0 (
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
|
#! /bin/sh
# This script tests: pbmtext
# Also requires: pamfile
tmpdir=${tmpdir:-/tmp}
# Test 1:
echo "Test 1"
# Should print 3898818212 967 twice
pbmtext UNIX Philosophy: Do one thing and do it well. | cksum
printf "UNIX Philosophy: Do one thing and do it well." | pbmtext | cksum
# Should print 2506052117 1354 twice
pbmtext -builtin fixed \
For truth is always strange. Stranger than fiction. Lord Byron | cksum
printf "For truth is always strange. Stranger than fiction. Lord Byron" | \
pbmtext -builtin fixed | cksum
text="The quick brown fog jumps over the lazy docs."
# Test 2:
echo "Test 2"
for flags in "" "-nomargins" "-builtin fixed"
do
echo ${text} | pbmtext ${flags} | cksum
done
temp_pbm=${tmpdir}/temp.pbm
# Test 3: Check if image is produced unaltered when -width is specified
# Should print 1028079028 967 twice, then 1305436978 1018 twice
echo "Test 3"
for flags in "" "-builtin fixed"
do
pbmtext ${flags} ${text} | tee ${temp_pbm} | cksum
width1=`pamfile ${temp_pbm} | awk '$2=="PBM" && NR==1 {w=$4}; END {print w}' `
width2=`pbmtext ${flags} ${text} --dry-run | cut -d " " -f 1`
if [ ${width1} -eq ${width2} ]; then
pbmtext ${flags} -width=${width1} ${text} | cksum
else
echo ${width1} ${width2}
fi
rm ${temp_pbm}
done
# Test 4: Should print 1647614653 2027 three times
# Note: backslashes inserted in 3 locations in the rectangle to make
# possible input as a here document.
fontRectangle_txt=${tmpdir}/fontRectangle.txt
font_pbm=${tmpdir}/font.pbm
cat > ${fontRectangle_txt} << EOF
M ",/^_[\`jpqy| M
/ !"#$%&'()*+ /
< ,-./01234567 <
> 89:;<=>?@ABC >
@ DEFGHIJKLMNO @
_ PQRSTUVWXYZ[ _
{ \\]^_\`abcdefg {
} hijklmnopqrs }
~ tuvwxyz{|}~ ~
M ",/^_[\`jpqy| M
EOF
echo "Test 4"
pbmtext -dump-sheet -builtin fixed | tee ${font_pbm} | cksum
cat ${fontRectangle_txt} | pbmtext -nom -builtin fixed | cksum
cat ${fontRectangle_txt} | pbmtext -nom -font ${font_pbm} | cksum
rm ${fontRectangle_txt}
# Test 5: Print all characters defined in the built-in bdf font
echo "Test 5"
# One long row
# Should print 3233136020 4535
LC_ALL=C \
awk 'BEGIN { for (i=32; i<=126;++i) printf("%c",i);
for (i=160;i<=255;++i) printf("%c",i); }' | \
pbmtext -builtin bdf | cksum
# One tall column
# Should print 1216262214 5711
LC_ALL=C \
awk 'BEGIN { for (i=32; i<=126;++i) printf("%c\n",i);
for (i=160;i<=255;++i) printf("%c\n",i); }' | \
pbmtext -nomargins -builtin bdf | cksum
# Test 6
echo 1>&2
echo "Invalid font file specifications & command-line argument combinations." 1>&2
echo "Error messages should appear below the line." 1>&2
echo "-----------------------------------------------------------" 1>&2
echo "Test 6 Invalid"
test_out=${tmpdir}/test_out
pbmtext -font=testgrid.pbm foo > ${test_out} || \
printf "Expected failure 1";
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pbmtext -font=testimg.ppm foo > ${test_out} || \
printf "Expected failure 2";
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pbmtext -builtin=void foo > ${test_out} || \
printf "Expected failure 3";
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pbmtext -font=${font_pbm} -builtin=fixed foo > ${test_out} || \
printf "Expected failure 4";
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pbmtext -dry-run -text-dump foo > ${test_out} || \
printf "Expected failure 5";
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pbmtext -dump-sheet -text-dump foo > ${test_out} || \
printf "Expected failure 6";
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pbmtext -dry-run -dump-sheet foo > ${test_out} || \
printf "Expected failure 7";
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pbmtext -wchar foo > ${test_out} || \
printf "Expected failure 8";
test -s ${test_out}; echo " "$?
rm -f ${test_out}
rm ${font_pbm}
# Test 7
# Text to render in very long single line
echo "Test 7"
long_txt=${tmpdir}/long.txt
head -c 4999 /dev/zero | tr '\0' 'A' > ${long_txt}
awk '{print "text length:", length($0)}' ${long_txt}
pbmtext -nomargins -builtin fixed `cat ${long_txt}` | cksum
cat ${long_txt} | pbmtext -nomargins -builtin fixed | cksum
echo "Test 8 Invalid"
printf "z" >> ${long_txt}
awk '{print "text length:", length($0)}' ${long_txt}
echo 1>&2
echo "Test input text which exceeds length limit" 1>&2
echo "Error messages should appear below the line." 1>&2
echo "-----------------------------------------------------------" 1>&2
pbmtext -nomargins -builtin fixed `cat ${long_txt}` > ${test_out} || \
printf "Expected failure 1";
test -s ${test_out}; echo " "$?
rm -f ${test_out}
cat ${long_txt} | pbmtext -nomargins -builtin fixed > ${test_out} || \
printf "Expected failure 2";
test -s ${test_out}; echo " "$?
rm -f ${test_out}
cat ${long_txt} | \
LC_ALL=C pbmtext -nomargins -builtin fixed -wchar > ${test_out} || \
printf "Expected failure 3";
test -s ${test_out}; echo " "$?
rm -f ${test_out}
rm ${long_txt}
|