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