]> diplodocus.org Git - nmh/blob - test/mhshow/test-charset
mhshow/test-charset: Use octal, not hex, in printf(1) format string.
[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 skip_param_value_checks=0
24 if test "$ICONV_ENABLED" -eq 0; then
25 text_size=10
26 else
27 text_size=11
28 #### For unknown reasons, the parameter values checks fail on the
29 #### FreeBSD10 buildbot. It doesn't support EBCDIC-US, which is used
30 #### by the checks, so check for that. Though that doesn't seem to be
31 #### the reason.
32 printf '\0344' | iconv -f EBCDIC-US -t UTF-8 >/dev/null 2>&1 ||
33 skip_param_value_checks=1
34 fi
35
36 expected=$MH_TEST_DIR/$$.expected
37 actual=$MH_TEST_DIR/$$.actual
38
39 echo 'mhshow-charset-windows-1252: echo "This is a test"' >> "$MH"
40
41 # Write message with bogus quoted-printable data.
42 start_test 'Write message with bogus quoted-printable data'
43 msgfile=`mhpath new`
44 msgnum=`basename $msgfile`
45 cat > $msgfile <<EOF
46 From: foo@example.edu
47 To: bar@example.edu
48 Subject: test
49 MIME-Version: 1.0
50 Content-Type: text/plain; charset=windows-1252
51 Content-Transfer-Encoding: quoted-printable
52 Content-Description: bogus quoted-printable data
53 Date: Sun, 18 Dec 2005 00:52:39 +0100
54
55 4 =F7 2 =3D 2
56 EOF
57
58 cat > $expected <<EOF
59 [ Message inbox:11 ]
60 Date: Sun, 18 Dec 2005 00:52:39 +0100
61 To: bar@example.edu
62 From: foo@example.edu
63 Subject: test
64
65 MIME-Version: 1.0
66 Content-Description: bogus quoted-printable data
67
68 [ part - text/plain - bogus quoted-printable data ${text_size}B ]
69 This is a test
70 EOF
71
72 run_prog mhshow $msgnum > $actual 2>&1
73 check "$expected" "$actual" 'keep first' : bogus quoted-printable data
74
75
76 start_test 'locale profile component'
77 #### Used LC_ALL above, now use locale profile component instead.
78 printf "locale: $LC_ALL\n" >> "${MH}"
79 unset LC_ALL
80
81 run_prog mhshow $msgnum > $actual 2>&1
82 check "$expected" "$actual" : locale profile component
83
84
85 if test $skip_param_value_checks -eq 1; then
86 finish_test
87 exit $failed
88 fi
89
90
91 start_test 'Encoded parameter value'
92 msgfile=`mhpath new`
93 msgnum=`basename $msgfile`
94 #### The encoded charset name is really UTF-8 encoded,
95 #### but say it's UTF-16 to exercise the iconv code,
96 #### if it's available, in get_param_value().
97 cat > $msgfile <<EOF
98 From: foo@example.edu
99 To: bar@example.edu
100 Subject: test
101 MIME-Version: 1.0
102 Content-Type: text/plain; charset*=EBCDIC-US''%e4%e3%c6%60%f8
103 Content-Transfer-Encoding: quoted-printable
104 Content-Description: bogus quoted-printable data
105 Date: Sun, 18 Dec 2005 00:52:39 +0100
106
107 4 =C3=B7 2 =3D 2
108 EOF
109
110 cat > $expected <<EOF
111 [ Message inbox:12 ]
112 Date: Sun, 18 Dec 2005 00:52:39 +0100
113 To: bar@example.edu
114 From: foo@example.edu
115 Subject: test
116
117 MIME-Version: 1.0
118 Content-Description: bogus quoted-printable data
119
120 [ part - text/plain - bogus quoted-printable data 11B ]
121 4 รท 2 = 2
122 EOF
123
124 run_prog mhshow $msgnum > $actual 2>&1
125 check "$expected" "$actual" : encoded parameter value
126
127
128 start_test 'replacement character in parameter value'
129 #### The output of this test doesn't show it, but it covers the
130 #### noiconv: portion of get_param_value().
131 cat > $msgfile <<'EOF'
132 Subject: invalid parameter value charset
133 MIME-Version: 1.0
134 Content-Type: text/plain; charset*=invalid''%0Dus-ascii
135 EOF
136
137 cat > $expected <<EOF
138 [ Message inbox:12 ]
139 Subject: invalid parameter value charset
140
141 MIME-Version: 1.0
142
143 [ part - text/plain - 0B ]
144 EOF
145
146 run_prog mhshow $msgnum > $actual 2>&1
147 check "$expected" "$actual"
148
149
150 finish_test
151 exit $failed