about summary refs log tree commit diff
path: root/test/pbmtextps-dump.test
blob: fd68667da81ce1fd251d5dc65c5f6cfd4cf468b1 (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
#! /bin/sh
# This script tests: pbmtextps
# Also requires:

# Dump several variants of the ps file and compare against default.
# Ghostscript is not required.

tmpdir=${tmpdir:-/tmp}
text1_ps=${tmpdir}/text1.ps
text2_ps=${tmpdir}/text2.ps

text="UNIX Philosophy: Do one thing and do it well."

# Test 1:
echo "Test 1"

pbmtextps -dump-ps ${text} > ${text1_ps}

# Font name is random sequence of alphanumerical characters.
# Should not match any real name.

for flag in \
  "-font=ZQUEl8eS38RlsvEahHGNfnrbSswrcJKFwvlCdEttwcheuXvCN49MvWmndqj4" \
  "-fontsize 2000" \
  "-resolution 7200" \
  "-leftmargin=15" \
  "-rightmargin=20" \
  "-topmargin=10" \
  "-bottommargin=14" \
  "-ascent=30" \
  "-descent=20" \
  "-pad" \
  "-crop" \
  "-stroke 1"
  do
  echo ${flag}
  pbmtextps -dump-ps ${flag} ${text} | diff ${text1_ps} - | grep "^[<>]"
  done

rm ${text1_ps}


# Test 2:
echo "Test 2"

pbmtextps -dump-ps "012 ABC-xyz." > ${text2_ps}

for hextext in \
  "30 31 32  20	 41 42 43  2d	78 79 7a  2e" \
  "303132204142432d78797a2e" \
  "<303132 20 414243 2d 78797a 2e>" 
  do
  echo ${hextext}
  pbmtextps -dump-ps -asciihex ${hextext} | diff ${text2_ps} - | grep "^[<>]"
  echo $?
  done

rm ${text2_ps}


echo "Test Invalid"

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

test_out=${tmpdir}/test.out

n=1

for error_flag in \
  "-fontsize" \
  "-fontsize 0" \
  "-resolution" \
  "-resolution=0" \
  "-leftmargin" \
  "-leftmargin -1" \
  "-rightmargin" \
  "-rightmargin -1" \
  "-topmargin" \
  "-topmargin -1" \
  "-bottommargin" \
  "-bottommargin -1" \
  "-ascent" \
  "-ascent -1" \
  "-descent" \
  "-descent -1" \
  "-stroke=A" \
  "-pad -crop"
  do
    pbmtextps ${error_flag} -dump-ps ${text} >${test_out} || \
    printf "Expected failure $n (${error_flag}) "
    test -s ${test_out} && echo "unexpected output" || echo "(no output)"
    rm -f ${test_out}
    n=$((n + 1))
  done

for asciihex_string in \
  "<a>" \
  "" \
  "<53756c667572" \
  "53756c667572>" \
  "<5375<6c667572>" \
  "<53756c>667572>"
  do
    pbmtextps -dump-ps -asciihex ${asciihex_string} >${test_out} || \
    printf "Expected failure $n (-asciihex ${asciihex_string}) "
    test -s ${test_out} && echo "unexpected output" || echo "(no output)"
    rm -f ${test_out}
    n=$((n + 1))
  done

for ascii85_string in \
  '<~@<6O!FD5W(~'\
  '~@<6O!FD5W(~>'\
  "<~@<6O<~!FD5W(~>"\
  "<~@<6O~>!FD5W(~>"\
  "<~@<6O!FD5W(~~>"\
  "v"\
  "y"\
  "1z"\
  "z1z"\
  "<~0123z~>"
  do
    pbmtextps -dump-ps -ascii85 ${ascii85_string} >${test_out} || \
	printf "Expected failure $n (-ascii85 ${ascii85_string}) "
    test -s ${test_out} && echo "unexpected output" || echo "(no output)"
    rm -f ${test_out}
    n=$((n + 1))
  done

  pbmtextps -font="" -dump-ps ${text} >${test_out} || \
  printf "Expected failure $n (-font=\"\") "
  test -s ${test_out} && echo "unexpected output" || echo "(no output)"
  rm -f ${test_out}