]> diplodocus.org Git - nmh/blob - test/mhshow/test-charset
Removed if ! bash-ism.
[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 '\xe4' | 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 start_test 'Encoded parameter value'
86 msgfile=`mhpath new`
87 msgnum=`basename $msgfile`
88 #### The encoded charset name is really UTF-8 encoded,
89 #### but say it's UTF-16 to exercise the iconv code,
90 #### if it's available, in get_param_value().
91 cat > $msgfile <<EOF
92 From: foo@example.edu
93 To: bar@example.edu
94 Subject: test
95 MIME-Version: 1.0
96 Content-Type: text/plain; charset*=EBCDIC-US''%e4%e3%c6%60%f8
97 Content-Transfer-Encoding: quoted-printable
98 Content-Description: bogus quoted-printable data
99 Date: Sun, 18 Dec 2005 00:52:39 +0100
100
101 4 =C3=B7 2 =3D 2
102 EOF
103
104 cat > $expected <<EOF
105 [ Message inbox:12 ]
106 Date: Sun, 18 Dec 2005 00:52:39 +0100
107 To: bar@example.edu
108 From: foo@example.edu
109 Subject: test
110
111 MIME-Version: 1.0
112 Content-Description: bogus quoted-printable data
113
114 [ part - text/plain - bogus quoted-printable data 11B ]
115 4 รท 2 = 2
116 EOF
117
118 if test $skip_param_value_checks -eq 0; then
119 run_prog mhshow $msgnum > $actual 2>&1
120 check "$expected" "$actual" : encoded parameter value
121 fi
122
123
124 start_test 'replacement character in parameter value'
125 #### The output of this test doesn't show it, but it covers the
126 #### noiconv: portion of get_param_value().
127 cat > $msgfile <<'EOF'
128 Subject: invalid parameter value charset
129 MIME-Version: 1.0
130 Content-Type: text/plain; charset*=invalid''%0Dus-ascii
131 EOF
132
133 cat > $expected <<EOF
134 [ Message inbox:12 ]
135 Subject: invalid parameter value charset
136
137 MIME-Version: 1.0
138
139 [ part - text/plain - 0B ]
140 EOF
141
142 if test $skip_param_value_checks -eq 0; then
143 run_prog mhshow $msgnum > $actual 2>&1
144 check "$expected" "$actual"
145 fi
146
147
148 finish_test
149 exit $failed