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