about summary refs log tree commit diff
path: root/test/pbmtext-bdf.test
blob: 50df7b75f327c5b3ad1789878d3021c53bbeb1e6 (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
#! /bin/bash
# This script tests: pbmtext
# Also requires:

tmpdir=${tmpdir:-/tmp}

font_bdf=${tmpdir}/font.bdf
font_corrupt=${tmpdir}/fontcorrupt

# Though this BDF font file defines only three letters, it is valid.

cat > ${font_bdf} << EOF
STARTFONT 2.1
COMMENT simple font for pbmtext test
COMMENT derived from: $XFree86: xc/fonts/bdf/misc/micro.bdf,v 1.1 1999/09/25 14:36:34 dawes Exp $
FONT test
SIZE 4 75 75
FONTBOUNDINGBOX 4 5 0 0
STARTPROPERTIES 5
FONT_DESCENT 0
FONT_ASCENT 5
CHARSET_REGISTRY "ISO88591"
CHARSET_ENCODING "1"
COPYRIGHT "Public domain font.  Share and enjoy."
ENDPROPERTIES
CHARS 3
STARTCHAR A
ENCODING 65
SWIDTH 1000 0
DWIDTH 4 0
BBX 4 5 0 0
BITMAP
e0
a0
e0
a0
a0
ENDCHAR
STARTCHAR B
ENCODING 66
SWIDTH 1000 0
DWIDTH 4 0
BBX 4 5 0 0
BITMAP
e0
a0
c0
a0
e0
ENDCHAR
STARTCHAR C
ENCODING 67
SWIDTH 1000 0
DWIDTH 4 0
BBX 4 5 0 0
BITMAP
e0
80
80
80
e0
ENDCHAR
ENDFONT
EOF

# Test 1
# This should succeed and produce 386826492 35
pbmtext -font ${font_bdf} ABC | cksum


# Test 2
# These should all fail.  Writes 1 eightteen times.

echo "Test whether corrupted BDF font files are properly handled." 1>&2
echo "Error messages should appear below the line." 1>&2
echo "-----------------------------------------------------------" 1>&2

pbmtext -font ${font_bdf} BCD
echo $?

for token in "STARTPROPERTIES" "CHARS" "STARTCHAR" "ENCODING" "DWIDTH"
do
  font_corrupt_bdf=${font_corrupt}.naked_${token}.bdf
  sed 's/^'${token}' .*$/'${token}'/' \
    ${font_bdf} >  ${font_corrupt_bdf}
  pbmtext -font ${font_corrupt_bdf} ABC > /dev/null
  echo $?
  rm ${font_corrupt_bdf}
done

font_corrupt_bdf=${font_corrupt}.fbbx_narrow.bdf
sed 's/FONTBOUNDINGBOX 4 5 0 0/FONTBOUNDINGBOX 4 4 0 0/' \
  ${font_bdf} > ${font_corrupt_bdf}
pbmtext -font ${font_corrupt_bdf} ABC > /dev/null
echo $?
rm ${font_corrupt_bdf}

font_corrupt_bdf=${font_corrupt}.fbbx_low.bdf
sed 's/FONTBOUNDINGBOX 4 5 0 0/FONTBOUNDINGBOX 3 5 0 0/' \
  ${font_bdf} >  ${font_corrupt_bdf}
pbmtext -font ${font_corrupt_bdf} ABC > /dev/null
echo $?
rm ${font_corrupt_bdf}

font_corrupt_bdf=${font_corrupt}.bbx_only3fields.bdf
sed 's/BBX 4 5 0 0/BBX 4 5 0/' \
  ${font_bdf} >  ${font_corrupt_bdf}
pbmtext -font ${font_corrupt_bdf} ABC > /dev/null
echo $?
rm ${font_corrupt_bdf}

font_corrupt_bdf=${font_corrupt}.bbx_wide.bdf
sed 's/BBX 4 5 0 0/BBX 9 5 0 0/' \
  ${font_bdf} >  ${font_corrupt_bdf}
pbmtext -font ${font_corrupt_bdf} ABC > /dev/null
echo $?
rm ${font_corrupt_bdf}

font_corrupt_bdf=${font_corrupt}.bbx_zerowidth.bdf
sed 's/BBX 4 5 0 0/BBX 0 5 0 0/' \
  ${font_bdf} >  ${font_corrupt_bdf}
pbmtext -font ${font_corrupt_bdf} ABC > /dev/null
echo $?
rm ${font_corrupt_bdf}

font_corrupt_bdf=${font_corrupt}.bbx_tall.bdf
sed 's/BBX 4 5 0 0/BBX 4 6 0 0/' \
  ${font_bdf} >  ${font_corrupt_bdf}
pbmtext -font ${font_corrupt_bdf} ABC > /dev/null
echo $?
rm ${font_corrupt_bdf}

font_corrupt_bdf=${font_corrupt}.bbx_low.bdf
sed 's/BBX 4 5 0 0/BBX 4 1 0 0/' \
  ${font_bdf} >  ${font_corrupt_bdf}
pbmtext -font ${font_corrupt_bdf} ABC > /dev/null
echo $?
rm ${font_corrupt_bdf}

font_corrupt_bdf=${font_corrupt}.bbx_zeroheight.bdf
sed 's/BBX 4 5 0 0/BBX 4 0 0 0/' \
  ${font_bdf} >  ${font_corrupt_bdf}
pbmtext -font ${font_corrupt_bdf} ABC > /dev/null
echo $?
rm ${font_corrupt_bdf}

for delete_line in 14 16 18 20
  do
  font_corrupt_bdf=${font_corrupt}.del${delete_line}.pdf
  sed "${delete_line}"d ${font_bdf} >  ${font_corrupt_bdf}
  pbmtext -font ${font_corrupt_bdf} ABC > /dev/null
  echo $?
  rm ${font_corrupt_bdf}
  done


# Test 2
# These should succeed.  Warning messages will be displayed.
# Writes 1 two times.

for token in "CHARSET_ENCODING" "CHARSET_REGISTRY"
do
  font_corrupt_bdf=${font_corrupt}.naked_${token}.bdf
  sed 's/^'${token}' .*$/'${token}'/' \
    ${font_bdf} >  ${font_corrupt_bdf}
  pbmtext -font ${font_corrupt_bdf} ABC > /dev/null
  echo $?
  rm ${font_corrupt_bdf}
done