Mercurial > hg > octave-nkf > gnulib-hg
annotate tests/test-striconveh.c @ 17693:53803f7bacc5
maint: add ChangeLog entry missing in previous commit
* ChangeLog: Add the omitted entry.
author | Pádraig Brady <P@draigBrady.com> |
---|---|
date | Mon, 02 Jun 2014 20:08:05 +0100 |
parents | 344018b6e5d7 |
children | ab58d4870664 |
rev | line source |
---|---|
7883 | 1 /* Test of character set conversion with error handling. |
17587 | 2 Copyright (C) 2007-2014 Free Software Foundation, Inc. |
7883 | 3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
7883 | 5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
7 (at your option) any later version. |
7883 | 8 |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
7883 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ | |
18 | |
8891
633babea5f62
Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents:
8754
diff
changeset
|
19 #include <config.h> |
7883 | 20 |
21 #include "striconveh.h" | |
22 | |
23 #if HAVE_ICONV | |
24 # include <iconv.h> | |
25 #endif | |
26 | |
27 #include <errno.h> | |
28 #include <stdlib.h> | |
29 #include <string.h> | |
30 | |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
31 #include "macros.h" |
7883 | 32 |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
33 /* Magic number for detecting bounds violations. */ |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
34 #define MAGIC 0x1983EFF1 |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
35 |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
36 static size_t * |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
37 new_offsets (size_t n) |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
38 { |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
39 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t)); |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
40 offsets[n] = MAGIC; |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
41 return offsets; |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
42 } |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
43 |
7883 | 44 int |
45 main () | |
46 { | |
47 static enum iconv_ilseq_handler handlers[] = | |
48 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence }; | |
11951
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
49 size_t indirect; |
7883 | 50 size_t h; |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
51 size_t o; |
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
52 size_t i; |
7883 | 53 |
54 #if HAVE_ICONV | |
55 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1, | |
56 ISO-8859-2, and UTF-8. */ | |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
57 iconv_t cd_ascii_to_88591 = iconv_open ("ISO-8859-1", "ASCII"); |
7883 | 58 iconv_t cd_88591_to_88592 = iconv_open ("ISO-8859-2", "ISO-8859-1"); |
59 iconv_t cd_88592_to_88591 = iconv_open ("ISO-8859-1", "ISO-8859-2"); | |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
60 iconv_t cd_ascii_to_utf8 = iconv_open ("UTF-8", "ASCII"); |
7883 | 61 iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1"); |
62 iconv_t cd_utf8_to_88591 = iconv_open ("ISO-8859-1", "UTF-8"); | |
63 iconv_t cd_88592_to_utf8 = iconv_open ("UTF-8", "ISO-8859-2"); | |
64 iconv_t cd_utf8_to_88592 = iconv_open ("ISO-8859-2", "UTF-8"); | |
10407
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
65 iconv_t cd_utf7_to_utf8 = iconv_open ("UTF-8", "UTF-7"); |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
66 iconveh_t cdeh_ascii_to_88591; |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
67 iconveh_t cdeh_ascii_to_88591_indirectly; |
11912
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
68 iconveh_t cdeh_88592_to_88591; |
11951
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
69 iconveh_t cdeh_88592_to_88591_indirectly; |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
70 iconveh_t cdeh_ascii_to_utf8; |
11912
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
71 iconveh_t cdeh_88591_to_utf8; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
72 iconveh_t cdeh_utf8_to_88591; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
73 iconveh_t cdeh_utf7_to_utf8; |
7883 | 74 |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
75 ASSERT (cd_ascii_to_utf8 != (iconv_t)(-1)); |
7883 | 76 ASSERT (cd_88591_to_utf8 != (iconv_t)(-1)); |
77 ASSERT (cd_utf8_to_88591 != (iconv_t)(-1)); | |
78 ASSERT (cd_88592_to_utf8 != (iconv_t)(-1)); | |
79 ASSERT (cd_utf8_to_88592 != (iconv_t)(-1)); | |
80 | |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
81 cdeh_ascii_to_88591.cd = cd_ascii_to_88591; |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
82 cdeh_ascii_to_88591.cd1 = cd_ascii_to_utf8; |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
83 cdeh_ascii_to_88591.cd2 = cd_utf8_to_88591; |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
84 |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
85 cdeh_ascii_to_88591_indirectly.cd = (iconv_t)(-1); |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
86 cdeh_ascii_to_88591_indirectly.cd1 = cd_ascii_to_utf8; |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
87 cdeh_ascii_to_88591_indirectly.cd2 = cd_utf8_to_88591; |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
88 |
11912
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
89 cdeh_88592_to_88591.cd = cd_88592_to_88591; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
90 cdeh_88592_to_88591.cd1 = cd_88592_to_utf8; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
91 cdeh_88592_to_88591.cd2 = cd_utf8_to_88591; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
92 |
11951
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
93 cdeh_88592_to_88591_indirectly.cd = (iconv_t)(-1); |
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
94 cdeh_88592_to_88591_indirectly.cd1 = cd_88592_to_utf8; |
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
95 cdeh_88592_to_88591_indirectly.cd2 = cd_utf8_to_88591; |
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
96 |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
97 cdeh_ascii_to_utf8.cd = cd_ascii_to_utf8; |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
98 cdeh_ascii_to_utf8.cd1 = cd_ascii_to_utf8; |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
99 cdeh_ascii_to_utf8.cd2 = (iconv_t)(-1); |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
100 |
11912
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
101 cdeh_88591_to_utf8.cd = cd_88591_to_utf8; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
102 cdeh_88591_to_utf8.cd1 = cd_88591_to_utf8; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
103 cdeh_88591_to_utf8.cd2 = (iconv_t)(-1); |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
104 |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
105 cdeh_utf8_to_88591.cd = cd_utf8_to_88591; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
106 cdeh_utf8_to_88591.cd1 = (iconv_t)(-1); |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
107 cdeh_utf8_to_88591.cd2 = cd_utf8_to_88591; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
108 |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
109 cdeh_utf7_to_utf8.cd = cd_utf7_to_utf8; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
110 cdeh_utf7_to_utf8.cd1 = cd_utf7_to_utf8; |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
111 cdeh_utf7_to_utf8.cd2 = (iconv_t)(-1); |
ba1f5a03459a
Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents:
11464
diff
changeset
|
112 |
7883 | 113 /* ------------------------ Test mem_cd_iconveh() ------------------------ */ |
114 | |
115 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */ | |
11951
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
116 for (indirect = 0; indirect <= 1; indirect++) |
7883 | 117 { |
11951
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
118 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
119 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
120 enum iconv_ilseq_handler handler = handlers[h]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
121 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
122 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
123 for (o = 0; o < 2; o++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
124 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
125 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
126 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
127 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
128 int retval = mem_cd_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
129 (indirect |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
130 ? &cdeh_88592_to_88591_indirectly |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
131 : &cdeh_88592_to_88591), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
132 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
133 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
134 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
135 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
136 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
137 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
138 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
139 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
140 for (i = 0; i < 37; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
141 ASSERT (offsets[i] == i); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
142 ASSERT (offsets[37] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
143 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
144 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
145 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
146 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
147 } |
7883 | 148 } |
149 | |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
150 /* Test conversion from ASCII to ISO-8859-1 with invalid input (EILSEQ). */ |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
151 for (indirect = 0; indirect <= 1; indirect++) |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
152 { |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
153 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
154 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
155 enum iconv_ilseq_handler handler = handlers[h]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
156 static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
157 for (o = 0; o < 2; o++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
158 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
159 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
160 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
161 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
162 int retval = mem_cd_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
163 (indirect |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
164 ? &cdeh_ascii_to_88591_indirectly |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
165 : &cdeh_ascii_to_88591), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
166 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
167 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
168 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
169 switch (handler) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
170 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
171 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
172 ASSERT (retval == -1 && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
173 ASSERT (result == NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
174 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
175 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
176 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
177 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
178 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
179 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
180 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
181 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
182 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
183 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
184 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
185 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
186 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
187 ASSERT (offsets[i] == i); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
188 ASSERT (offsets[16] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
189 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
190 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
191 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
192 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
193 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
194 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
195 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
196 } |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
197 } |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
198 |
7883 | 199 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */ |
11951
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
200 for (indirect = 0; indirect <= 1; indirect++) |
7883 | 201 { |
11951
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
202 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
203 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
204 enum iconv_ilseq_handler handler = handlers[h]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
205 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
206 for (o = 0; o < 2; o++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
207 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
208 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
209 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
210 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
211 int retval = mem_cd_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
212 (indirect |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
213 ? &cdeh_88592_to_88591_indirectly |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
214 : &cdeh_88592_to_88591), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
215 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
216 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
217 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
218 switch (handler) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
219 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
220 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
221 ASSERT (retval == -1 && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
222 ASSERT (result == NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
223 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
224 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
225 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
226 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
227 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
228 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
229 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
230 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
231 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
232 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
233 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
234 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
235 ASSERT (offsets[i] == i); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
236 ASSERT (offsets[16] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
237 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
238 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
239 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
240 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
241 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
242 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
243 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
244 static const char expected[] = "Rafa\\u0142 Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
245 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
246 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
247 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
248 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
249 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
250 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
251 ASSERT (offsets[i] == (i < 5 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
252 i + 5)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
253 ASSERT (offsets[16] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
254 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
255 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
256 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
257 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
258 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
259 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
260 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
261 } |
7883 | 262 } |
263 | |
264 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ | |
265 for (h = 0; h < SIZEOF (handlers); h++) | |
266 { | |
267 enum iconv_ilseq_handler handler = handlers[h]; | |
268 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
269 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
270 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
271 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
272 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
273 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
274 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
275 int retval = mem_cd_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
276 &cdeh_88591_to_utf8, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
277 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
278 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
279 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
280 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
281 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
282 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
283 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
284 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
285 for (i = 0; i < 37; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
286 ASSERT (offsets[i] == (i < 1 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
287 i < 12 ? i + 1 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
288 i < 18 ? i + 2 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
289 i + 3)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
290 ASSERT (offsets[37] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
291 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
292 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
293 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
294 } |
7883 | 295 } |
296 | |
297 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */ | |
298 for (h = 0; h < SIZEOF (handlers); h++) | |
299 { | |
300 enum iconv_ilseq_handler handler = handlers[h]; | |
301 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
302 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
303 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
304 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
305 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
306 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
307 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
308 int retval = mem_cd_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
309 &cdeh_utf8_to_88591, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
310 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
311 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
312 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
313 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
314 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
315 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
316 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
317 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
318 for (i = 0; i < 41; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
319 ASSERT (offsets[i] == (i < 1 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
320 i == 1 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
321 i < 13 ? i - 1 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
322 i == 13 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
323 i < 20 ? i - 2 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
324 i == 20 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
325 i < 40 ? i - 3 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
326 (size_t)(-1))); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
327 ASSERT (offsets[41] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
328 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
329 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
330 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
331 } |
7883 | 332 } |
333 | |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
334 /* Test conversion from ASCII to UTF-8 with invalid input (EILSEQ). */ |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
335 for (h = 0; h < SIZEOF (handlers); h++) |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
336 { |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
337 enum iconv_ilseq_handler handler = handlers[h]; |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
338 static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */ |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
339 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
340 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
341 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
342 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
343 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
344 int retval = mem_cd_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
345 &cdeh_ascii_to_utf8, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
346 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
347 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
348 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
349 switch (handler) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
350 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
351 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
352 ASSERT (retval == -1 && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
353 ASSERT (result == NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
354 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
355 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
356 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
357 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
358 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
359 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
360 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
361 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
362 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
363 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
364 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
365 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
366 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
367 ASSERT (offsets[i] == i); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
368 ASSERT (offsets[16] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
369 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
370 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
371 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
372 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
373 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
374 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
375 } |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
376 } |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
377 |
7883 | 378 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */ |
379 for (h = 0; h < SIZEOF (handlers); h++) | |
380 { | |
381 enum iconv_ilseq_handler handler = handlers[h]; | |
382 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ | |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
383 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
384 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
385 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
386 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
387 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
388 int retval = mem_cd_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
389 &cdeh_utf8_to_88591, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
390 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
391 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
392 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
393 switch (handler) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
394 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
395 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
396 ASSERT (retval == -1 && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
397 ASSERT (result == NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
398 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
399 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
400 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
401 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
402 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
403 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
404 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
405 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
406 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
407 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
408 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
409 for (i = 0; i < 17; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
410 ASSERT (offsets[i] == (i < 5 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
411 i == 5 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
412 i - 1)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
413 ASSERT (offsets[17] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
414 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
415 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
416 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
417 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
418 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
419 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
420 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
421 static const char expected[] = "Rafa\\u0142 Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
422 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
423 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
424 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
425 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
426 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
427 for (i = 0; i < 17; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
428 ASSERT (offsets[i] == (i < 5 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
429 i == 5 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
430 i + 4)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
431 ASSERT (offsets[17] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
432 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
433 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
434 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
435 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
436 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
437 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
438 } |
7883 | 439 } |
440 | |
441 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ | |
442 for (h = 0; h < SIZEOF (handlers); h++) | |
443 { | |
444 enum iconv_ilseq_handler handler = handlers[h]; | |
445 static const char input[] = "\342"; | |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
446 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
447 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
448 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
449 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
450 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
451 int retval = mem_cd_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
452 &cdeh_utf8_to_88591, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
453 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
454 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
455 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
456 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
457 ASSERT (length == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
458 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
459 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
460 ASSERT (offsets[0] == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
461 ASSERT (offsets[1] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
462 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
463 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
464 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
465 } |
7883 | 466 } |
467 | |
10407
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
468 if (cd_utf7_to_utf8 != (iconv_t)(-1)) |
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
469 { |
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
470 /* Disabled on Solaris, because Solaris 9 iconv() is buggy: it returns |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
471 -1 / EILSEQ when converting the 7th byte of the input "+VDLYP9hA". */ |
10407
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
472 # if !(defined __sun && !defined _LIBICONV_VERSION) |
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
473 /* Test conversion from UTF-7 to UTF-8 with EINVAL. */ |
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
474 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
475 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
476 enum iconv_ilseq_handler handler = handlers[h]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
477 /* This is base64 encoded 0x54 0x32 0xD8 0x3F 0xD8 0x40. It would |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
478 convert to U+5432 U+D83F U+D840 but these are Unicode surrogates. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
479 static const char input[] = "+VDLYP9hA"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
480 static const char expected1[] = "\345\220\262"; /* 吲 glibc */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
481 static const char expected2[] = ""; /* libiconv */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
482 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
483 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
484 int retval = mem_cd_iconveh (input, 7, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
485 &cdeh_utf7_to_utf8, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
486 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
487 NULL, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
488 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
489 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
490 ASSERT (length == strlen (expected1) || length == strlen (expected2)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
491 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
492 if (length == strlen (expected1)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
493 ASSERT (memcmp (result, expected1, strlen (expected1)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
494 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
495 ASSERT (memcmp (result, expected2, strlen (expected2)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
496 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
497 } |
10407
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
498 |
13370
aac0d7011945
Avoid a test failure on NetBSD 5.0.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
499 /* Disabled on NetBSD, because NetBSD 5.0 iconv() is buggy: it converts |
aac0d7011945
Avoid a test failure on NetBSD 5.0.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
500 the input "+2D/YQNhB" to U+1FED8 U+3FD8 U+40D8. */ |
aac0d7011945
Avoid a test failure on NetBSD 5.0.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
501 # if !(defined __NetBSD__ && !defined _LIBICONV_VERSION) |
10407
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
502 /* Test conversion from UTF-7 to UTF-8 with EILSEQ. */ |
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
503 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
504 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
505 enum iconv_ilseq_handler handler = handlers[h]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
506 /* This is base64 encoded 0xD8 0x3F 0xD8 0x40 0xD8 0x41. It would |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
507 convert to U+D83F U+D840 U+D841 but these are Unicode surrogates. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
508 static const char input[] = "+2D/YQNhB"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
509 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
510 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
511 int retval = mem_cd_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
512 &cdeh_utf7_to_utf8, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
513 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
514 NULL, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
515 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
516 switch (handler) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
517 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
518 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
519 ASSERT (retval == -1 && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
520 ASSERT (result == NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
521 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
522 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
523 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
524 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
525 /* glibc result */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
526 static const char expected1[] = "?????"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
527 /* libiconv <= 1.12 result */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
528 static const char expected2[] = "?2D/YQNhB"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
529 /* libiconv behaviour changed in version 1.13: the result is |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
530 '?' U+0FF6 U+1036; this is U+D83F U+D840 U+D841 shifted left |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
531 by 6 bits. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
532 static const char expected3[] = "?\340\277\266\341\200\266"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
533 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
534 ASSERT (length == strlen (expected1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
535 || length == strlen (expected2) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
536 || length == strlen (expected3)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
537 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
538 if (length == strlen (expected1)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
539 ASSERT (memcmp (result, expected1, strlen (expected1)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
540 else if (length == strlen (expected2)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
541 ASSERT (memcmp (result, expected2, strlen (expected2)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
542 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
543 ASSERT (memcmp (result, expected3, strlen (expected3)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
544 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
545 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
546 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
547 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
548 } |
13370
aac0d7011945
Avoid a test failure on NetBSD 5.0.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
549 # endif |
10407
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
550 # endif |
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
551 } |
2575b6d4b6b5
Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
552 |
7883 | 553 /* ------------------------ Test str_cd_iconveh() ------------------------ */ |
554 | |
555 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */ | |
11951
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
556 for (indirect = 0; indirect <= 1; indirect++) |
7883 | 557 { |
11951
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
558 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
559 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
560 enum iconv_ilseq_handler handler = handlers[h]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
561 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
562 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
563 char *result = str_cd_iconveh (input, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
564 (indirect |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
565 ? &cdeh_88592_to_88591_indirectly |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
566 : &cdeh_88592_to_88591), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
567 handler); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
568 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
569 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
570 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
571 } |
7883 | 572 } |
573 | |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
574 /* Test conversion from ASCII to ISO-8859-1 with invalid input (EILSEQ). */ |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
575 for (indirect = 0; indirect <= 1; indirect++) |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
576 { |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
577 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
578 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
579 enum iconv_ilseq_handler handler = handlers[h]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
580 static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
581 char *result = str_cd_iconveh (input, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
582 (indirect |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
583 ? &cdeh_ascii_to_88591_indirectly |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
584 : &cdeh_ascii_to_88591), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
585 handler); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
586 switch (handler) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
587 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
588 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
589 ASSERT (result == NULL && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
590 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
591 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
592 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
593 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
594 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
595 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
596 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
597 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
598 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
599 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
600 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
601 } |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
602 } |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
603 |
7883 | 604 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */ |
11951
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
605 for (indirect = 0; indirect <= 1; indirect++) |
7883 | 606 { |
11951
5bb7bec3987e
Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents:
11912
diff
changeset
|
607 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
608 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
609 enum iconv_ilseq_handler handler = handlers[h]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
610 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
611 char *result = str_cd_iconveh (input, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
612 (indirect |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
613 ? &cdeh_88592_to_88591_indirectly |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
614 : &cdeh_88592_to_88591), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
615 handler); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
616 switch (handler) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
617 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
618 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
619 ASSERT (result == NULL && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
620 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
621 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
622 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
623 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
624 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
625 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
626 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
627 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
628 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
629 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
630 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
631 static const char expected[] = "Rafa\\u0142 Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
632 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
633 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
634 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
635 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
636 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
637 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
638 } |
7883 | 639 } |
640 | |
641 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ | |
642 for (h = 0; h < SIZEOF (handlers); h++) | |
643 { | |
644 enum iconv_ilseq_handler handler = handlers[h]; | |
645 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
646 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
647 char *result = str_cd_iconveh (input, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
648 &cdeh_88591_to_utf8, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
649 handler); |
7883 | 650 ASSERT (result != NULL); |
651 ASSERT (strcmp (result, expected) == 0); | |
652 free (result); | |
653 } | |
654 | |
655 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */ | |
656 for (h = 0; h < SIZEOF (handlers); h++) | |
657 { | |
658 enum iconv_ilseq_handler handler = handlers[h]; | |
659 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
660 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
661 char *result = str_cd_iconveh (input, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
662 &cdeh_utf8_to_88591, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
663 handler); |
7883 | 664 ASSERT (result != NULL); |
665 ASSERT (strcmp (result, expected) == 0); | |
666 free (result); | |
667 } | |
668 | |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
669 /* Test conversion from ASCII to UTF-8 with invalid input (EILSEQ). */ |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
670 for (h = 0; h < SIZEOF (handlers); h++) |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
671 { |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
672 enum iconv_ilseq_handler handler = handlers[h]; |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
673 static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */ |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
674 char *result = str_cd_iconveh (input, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
675 &cdeh_ascii_to_utf8, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
676 handler); |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
677 switch (handler) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
678 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
679 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
680 ASSERT (result == NULL && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
681 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
682 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
683 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
684 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
685 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
686 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
687 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
688 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
689 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
690 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
691 } |
11952
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
692 } |
0ae7f1f4ed08
Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents:
11951
diff
changeset
|
693 |
7883 | 694 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */ |
695 for (h = 0; h < SIZEOF (handlers); h++) | |
696 { | |
697 enum iconv_ilseq_handler handler = handlers[h]; | |
698 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */ | |
699 char *result = str_cd_iconveh (input, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
700 &cdeh_utf8_to_88591, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
701 handler); |
7883 | 702 switch (handler) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
703 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
704 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
705 ASSERT (result == NULL && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
706 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
707 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
708 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
709 static const char expected[] = "Costs: 27 ?"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
710 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
711 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
712 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
713 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
714 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
715 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
716 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
717 static const char expected[] = "Costs: 27 \\u20AC"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
718 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
719 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
720 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
721 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
722 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
723 } |
7883 | 724 } |
725 | |
726 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ | |
727 for (h = 0; h < SIZEOF (handlers); h++) | |
728 { | |
729 enum iconv_ilseq_handler handler = handlers[h]; | |
730 static const char input[] = "\342"; | |
731 char *result = str_cd_iconveh (input, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
732 &cdeh_utf8_to_88591, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
733 handler); |
7883 | 734 ASSERT (result != NULL); |
735 ASSERT (strcmp (result, "") == 0); | |
736 free (result); | |
737 } | |
738 | |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7927
diff
changeset
|
739 if (cd_88591_to_88592 != (iconv_t)(-1)) |
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7927
diff
changeset
|
740 iconv_close (cd_88591_to_88592); |
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7927
diff
changeset
|
741 if (cd_88592_to_88591 != (iconv_t)(-1)) |
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7927
diff
changeset
|
742 iconv_close (cd_88592_to_88591); |
7883 | 743 iconv_close (cd_88591_to_utf8); |
744 iconv_close (cd_utf8_to_88591); | |
745 iconv_close (cd_88592_to_utf8); | |
746 iconv_close (cd_utf8_to_88592); | |
747 | |
7915 | 748 /* ------------------------- Test mem_iconveh() ------------------------- */ |
749 | |
750 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */ | |
751 for (h = 0; h < SIZEOF (handlers); h++) | |
752 { | |
753 enum iconv_ilseq_handler handler = handlers[h]; | |
754 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
755 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
756 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
757 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
758 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
759 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
760 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
761 int retval = mem_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
762 "ISO-8859-2", "ISO-8859-1", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
763 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
764 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
765 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
766 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
767 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
768 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
769 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
770 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
771 for (i = 0; i < 37; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
772 ASSERT (offsets[i] == i); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
773 ASSERT (offsets[37] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
774 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
775 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
776 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
777 } |
7915 | 778 } |
779 | |
780 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */ | |
781 for (h = 0; h < SIZEOF (handlers); h++) | |
782 { | |
783 enum iconv_ilseq_handler handler = handlers[h]; | |
784 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ | |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
785 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
786 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
787 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
788 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
789 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
790 int retval = mem_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
791 "ISO-8859-2", "ISO-8859-1", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
792 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
793 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
794 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
795 switch (handler) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
796 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
797 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
798 ASSERT (retval == -1 && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
799 ASSERT (result == NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
800 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
801 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
802 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
803 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
804 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
805 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
806 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
807 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
808 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
809 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
810 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
811 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
812 ASSERT (offsets[i] == i); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
813 ASSERT (offsets[16] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
814 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
815 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
816 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
817 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
818 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
819 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
820 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
821 static const char expected[] = "Rafa\\u0142 Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
822 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
823 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
824 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
825 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
826 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
827 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
828 ASSERT (offsets[i] == (i < 5 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
829 i + 5)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
830 ASSERT (offsets[16] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
831 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
832 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
833 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
834 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
835 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
836 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
837 } |
7915 | 838 } |
839 | |
840 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ | |
841 for (h = 0; h < SIZEOF (handlers); h++) | |
842 { | |
843 enum iconv_ilseq_handler handler = handlers[h]; | |
844 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
845 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
846 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
847 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
848 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
849 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
850 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
851 int retval = mem_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
852 "ISO-8859-1", "UTF-8", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
853 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
854 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
855 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
856 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
857 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
858 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
859 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
860 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
861 for (i = 0; i < 37; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
862 ASSERT (offsets[i] == (i < 1 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
863 i < 12 ? i + 1 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
864 i < 18 ? i + 2 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
865 i + 3)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
866 ASSERT (offsets[37] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
867 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
868 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
869 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
870 } |
7915 | 871 } |
872 | |
873 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */ | |
874 for (h = 0; h < SIZEOF (handlers); h++) | |
875 { | |
876 enum iconv_ilseq_handler handler = handlers[h]; | |
877 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
878 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
879 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
880 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
881 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
882 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
883 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
884 int retval = mem_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
885 "UTF-8", "ISO-8859-1", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
886 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
887 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
888 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
889 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
890 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
891 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
892 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
893 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
894 for (i = 0; i < 41; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
895 ASSERT (offsets[i] == (i < 1 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
896 i == 1 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
897 i < 13 ? i - 1 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
898 i == 13 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
899 i < 20 ? i - 2 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
900 i == 20 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
901 i < 40 ? i - 3 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
902 (size_t)(-1))); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
903 ASSERT (offsets[41] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
904 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
905 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
906 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
907 } |
7915 | 908 } |
909 | |
910 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */ | |
911 for (h = 0; h < SIZEOF (handlers); h++) | |
912 { | |
913 enum iconv_ilseq_handler handler = handlers[h]; | |
914 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ | |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
915 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
916 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
917 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
918 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
919 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
920 int retval = mem_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
921 "UTF-8", "ISO-8859-1", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
922 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
923 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
924 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
925 switch (handler) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
926 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
927 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
928 ASSERT (retval == -1 && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
929 ASSERT (result == NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
930 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
931 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
932 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
933 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
934 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
935 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
936 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
937 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
938 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
939 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
940 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
941 for (i = 0; i < 17; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
942 ASSERT (offsets[i] == (i < 5 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
943 i == 5 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
944 i - 1)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
945 ASSERT (offsets[17] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
946 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
947 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
948 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
949 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
950 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
951 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
952 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
953 static const char expected[] = "Rafa\\u0142 Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
954 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
955 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
956 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
957 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
958 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
959 for (i = 0; i < 17; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
960 ASSERT (offsets[i] == (i < 5 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
961 i == 5 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
962 i + 4)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
963 ASSERT (offsets[17] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
964 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
965 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
966 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
967 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
968 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
969 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
970 } |
7915 | 971 } |
972 | |
973 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ | |
974 for (h = 0; h < SIZEOF (handlers); h++) | |
975 { | |
976 enum iconv_ilseq_handler handler = handlers[h]; | |
977 static const char input[] = "\342"; | |
7927
7ebab05df4f6
Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents:
7915
diff
changeset
|
978 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
979 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
980 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
981 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
982 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
983 int retval = mem_iconveh (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
984 "UTF-8", "ISO-8859-1", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
985 handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
986 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
987 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
988 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
989 ASSERT (length == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
990 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
991 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
992 ASSERT (offsets[0] == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
993 ASSERT (offsets[1] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
994 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
995 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
996 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
997 } |
7915 | 998 } |
999 | |
7883 | 1000 /* ------------------------- Test str_iconveh() ------------------------- */ |
1001 | |
1002 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */ | |
1003 for (h = 0; h < SIZEOF (handlers); h++) | |
1004 { | |
1005 enum iconv_ilseq_handler handler = handlers[h]; | |
1006 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
1007 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
1008 char *result = str_iconveh (input, "ISO-8859-2", "ISO-8859-1", handler); | |
1009 ASSERT (result != NULL); | |
1010 ASSERT (strcmp (result, expected) == 0); | |
1011 free (result); | |
1012 } | |
1013 | |
1014 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */ | |
1015 for (h = 0; h < SIZEOF (handlers); h++) | |
1016 { | |
1017 enum iconv_ilseq_handler handler = handlers[h]; | |
1018 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ | |
1019 char *result = str_iconveh (input, "ISO-8859-2", "ISO-8859-1", handler); | |
1020 switch (handler) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1021 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1022 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1023 ASSERT (result == NULL && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1024 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1025 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1026 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1027 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1028 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1029 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1030 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1031 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1032 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1033 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1034 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1035 static const char expected[] = "Rafa\\u0142 Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1036 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1037 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1038 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1039 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1040 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1041 } |
7883 | 1042 } |
1043 | |
1044 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ | |
1045 for (h = 0; h < SIZEOF (handlers); h++) | |
1046 { | |
1047 enum iconv_ilseq_handler handler = handlers[h]; | |
1048 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
1049 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
1050 char *result = str_iconveh (input, "ISO-8859-1", "UTF-8", handler); | |
1051 ASSERT (result != NULL); | |
1052 ASSERT (strcmp (result, expected) == 0); | |
1053 free (result); | |
1054 } | |
1055 | |
1056 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */ | |
1057 for (h = 0; h < SIZEOF (handlers); h++) | |
1058 { | |
1059 enum iconv_ilseq_handler handler = handlers[h]; | |
1060 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
1061 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
1062 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler); | |
1063 ASSERT (result != NULL); | |
1064 ASSERT (strcmp (result, expected) == 0); | |
1065 free (result); | |
1066 } | |
1067 | |
1068 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */ | |
1069 for (h = 0; h < SIZEOF (handlers); h++) | |
1070 { | |
1071 enum iconv_ilseq_handler handler = handlers[h]; | |
1072 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */ | |
1073 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler); | |
1074 switch (handler) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1075 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1076 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1077 ASSERT (result == NULL && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1078 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1079 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1080 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1081 static const char expected[] = "Costs: 27 ?"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1082 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1083 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1084 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1085 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1086 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1087 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1088 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1089 static const char expected[] = "Costs: 27 \\u20AC"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1090 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1091 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1092 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1093 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1094 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11952
diff
changeset
|
1095 } |
7883 | 1096 } |
1097 | |
1098 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ | |
1099 for (h = 0; h < SIZEOF (handlers); h++) | |
1100 { | |
1101 enum iconv_ilseq_handler handler = handlers[h]; | |
1102 static const char input[] = "\342"; | |
1103 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler); | |
1104 ASSERT (result != NULL); | |
1105 ASSERT (strcmp (result, "") == 0); | |
1106 free (result); | |
1107 } | |
1108 | |
1109 #endif | |
1110 | |
1111 return 0; | |
1112 } |