]> diplodocus.org Git - nmh/blob - test/mhshow/test-charset
Reworked parameter value tests to reflect Ralph's (re-?) discovery
[nmh] / test / mhshow / test-charset
1 #!/bin/sh
2 ######################################################
3 #
4 # Test charset conversion functionality
5 #
6 ######################################################
7
8 set -e
9
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirname "$0"`/../..
12 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
13 fi
14
15 . "$MH_OBJ_DIR/test/common.sh"
16
17 setup_test
18
19 check_exit '-eq 1' mhshow -
20
21 require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8
22
23 iconv_elides_question_marks=0
24 if test "$ICONV_ENABLED" -eq 0; then
25 text_size=10
26 else
27 text_size=11
28 #### The GNU iconv library normalises charset names by eliding '?', along
29 #### with some other characters. The iconv library used on FreeBSD/NetBSD
30 #### doesn't.
31 printf x | iconv -f ?UTF-8 -t UTF-8 >/dev/null 2>&1 &&
32 iconv_elides_question_marks=1
33 fi
34
35 expected=$MH_TEST_DIR/$$.expected
36 actual=$MH_TEST_DIR/$$.actual
37
38 echo 'mhshow-charset-windows-1252: echo "This is a test"' >> "$MH"
39
40 # Write message with bogus quoted-printable data.
41 start_test 'Write message with bogus quoted-printable data'
42 msgfile=`mhpath new`
43 msgnum=`basename $msgfile`
44 cat > $msgfile <<EOF
45 From: foo@example.edu
46 To: bar@example.edu
47 Subject: test
48 MIME-Version: 1.0
49 Content-Type: text/plain; charset=windows-1252
50 Content-Transfer-Encoding: quoted-printable
51 Content-Description: bogus quoted-printable data
52 Date: Sun, 18 Dec 2005 00:52:39 +0100
53
54 4 =F7 2 =3D 2
55 EOF
56
57 cat > $expected <<EOF
58 [ Message inbox:11 ]
59 Date: Sun, 18 Dec 2005 00:52:39 +0100
60 To: bar@example.edu
61 From: foo@example.edu
62 Subject: test
63
64 MIME-Version: 1.0
65 Content-Description: bogus quoted-printable data
66
67 [ part - text/plain - bogus quoted-printable data ${text_size}B ]
68 This is a test
69 EOF
70
71 run_prog mhshow $msgnum > $actual 2>&1
72 check "$expected" "$actual" 'keep first' : bogus quoted-printable data
73
74
75 start_test 'locale profile component'
76 #### Used LC_ALL above, now use locale profile component instead.
77 printf "locale: $LC_ALL\n" >> "${MH}"
78 unset LC_ALL
79
80 run_prog mhshow $msgnum > $actual 2>&1
81 check "$expected" "$actual" : locale profile component
82
83
84 #### RFC 2231 defines the extended value syntax:
85 #### extended-initial-value := [charset] "'" [language] "'"
86 #### extended-other-values
87 #### used below, where language is blank.
88
89 start_test 'Encoded parameter value'
90 msgfile=`mhpath new`
91 msgnum=`basename $msgfile`
92 #### Use a charset to exercise the iconv code, if it's available,
93 #### in get_param_value().
94 cat > $msgfile <<EOF
95 From: foo@example.edu
96 To: bar@example.edu
97 Subject: test
98 MIME-Version: 1.0
99 Content-Type: text/plain; charset*=EBCDIC-US''%e4%e3%c6%60%f8
100 Content-Transfer-Encoding: quoted-printable
101 Content-Description: bogus quoted-printable data
102 Date: Sun, 18 Dec 2005 00:52:39 +0100
103
104 4 =C3=B7 2 =3D 2
105 EOF
106
107 cat > $expected <<EOF
108 [ Message inbox:12 ]
109 Date: Sun, 18 Dec 2005 00:52:39 +0100
110 To: bar@example.edu
111 From: foo@example.edu
112 Subject: test
113
114 MIME-Version: 1.0
115 Content-Description: bogus quoted-printable data
116
117 [ part - text/plain - bogus quoted-printable data 11B ]
118 4 รท 2 = 2
119 EOF
120
121 run_prog mhshow $msgnum > $actual 2>&1
122 check "$expected" "$actual" : encoded parameter value
123
124
125 start_test 'replacement character in parameter value'
126 #### The output of this test doesn't show it, but it covers the
127 #### noiconv: portion of get_param_value().
128 cat > $msgfile <<'EOF'
129 Subject: invalid parameter value charset
130 MIME-Version: 1.0
131 Content-Type: text/plain; charset*=invalid''%0Dus-ascii
132 EOF
133
134 cat > $expected <<EOF
135 [ Message inbox:12 ]
136 Subject: invalid parameter value charset
137
138 MIME-Version: 1.0
139
140 [ part - text/plain - 0B ]
141 EOF
142
143 run_prog mhshow $msgnum > $actual 2>&1
144 if [ $iconv_elides_question_marks -eq 1 ]; then
145 check "$expected" "$actual"
146 else
147 grep "Can't convert .*us-ascii to UTF-8" "$actual" >/dev/null || failed=1
148 fi
149
150
151 finish_test
152 exit $failed