Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/test-striconveha.c @ 17460:d11431703671
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Fri, 09 Aug 2013 08:03:30 -0700 |
parents | e542fd46ad6f |
children |
rev | line source |
---|---|
7932 | 1 /* Test of character set conversion with error handling and autodetection. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
2 Copyright (C) 2007-2013 Free Software Foundation, Inc. |
7932 | 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 |
7932 | 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. |
7932 | 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/>. */ |
7932 | 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> |
7932 | 20 |
21 #include "striconveha.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" |
7932 | 32 |
33 /* Magic number for detecting bounds violations. */ | |
34 #define MAGIC 0x1983EFF1 | |
35 | |
36 static size_t * | |
37 new_offsets (size_t n) | |
38 { | |
39 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t)); | |
40 offsets[n] = MAGIC; | |
41 return offsets; | |
42 } | |
43 | |
44 int | |
45 main () | |
46 { | |
47 static enum iconv_ilseq_handler handlers[] = | |
48 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence }; | |
49 size_t h; | |
50 size_t o; | |
51 size_t i; | |
52 | |
53 #if HAVE_ICONV | |
54 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1, | |
55 ISO-8859-2, and UTF-8. */ | |
56 | |
57 /* ------------------------- Test mem_iconveha() ------------------------- */ | |
58 | |
59 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */ | |
60 for (h = 0; h < SIZEOF (handlers); h++) | |
61 { | |
62 enum iconv_ilseq_handler handler = handlers[h]; | |
63 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
64 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
65 for (o = 0; o < 2; o++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
66 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
67 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
68 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
69 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
70 int retval = mem_iconveha (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
71 "ISO-8859-2", "ISO-8859-1", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
72 false, handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
73 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
74 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
75 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
76 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
77 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
78 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
79 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
80 for (i = 0; i < 37; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
81 ASSERT (offsets[i] == i); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
82 ASSERT (offsets[37] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
83 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
84 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
85 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
86 } |
7932 | 87 } |
88 | |
89 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */ | |
90 for (h = 0; h < SIZEOF (handlers); h++) | |
91 { | |
92 enum iconv_ilseq_handler handler = handlers[h]; | |
93 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ | |
94 for (o = 0; o < 2; o++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
95 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
96 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
97 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
98 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
99 int retval = mem_iconveha (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
100 "ISO-8859-2", "ISO-8859-1", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
101 false, handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
102 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
103 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
104 switch (handler) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
105 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
106 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
107 ASSERT (retval == -1 && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
108 ASSERT (result == NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
109 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
110 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
111 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
112 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
113 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
114 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
115 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
116 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
117 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
118 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
119 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
120 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
121 ASSERT (offsets[i] == i); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
122 ASSERT (offsets[16] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
123 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
124 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
125 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
126 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
127 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
128 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
129 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
130 static const char expected[] = "Rafa\\u0142 Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
131 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
132 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
133 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
134 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
135 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
136 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
137 ASSERT (offsets[i] == (i < 5 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
138 i + 5)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
139 ASSERT (offsets[16] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
140 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
141 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
142 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
143 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
144 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
145 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
146 } |
7932 | 147 } |
148 | |
149 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ | |
150 for (h = 0; h < SIZEOF (handlers); h++) | |
151 { | |
152 enum iconv_ilseq_handler handler = handlers[h]; | |
153 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
154 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
155 for (o = 0; o < 2; o++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
156 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
157 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
158 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
159 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
160 int retval = mem_iconveha (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
161 "ISO-8859-1", "UTF-8", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
162 false, handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
163 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
164 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
165 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
166 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
167 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
168 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
169 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
170 for (i = 0; i < 37; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
171 ASSERT (offsets[i] == (i < 1 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
172 i < 12 ? i + 1 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
173 i < 18 ? i + 2 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
174 i + 3)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
175 ASSERT (offsets[37] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
176 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
177 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
178 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
179 } |
7932 | 180 } |
181 | |
182 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */ | |
183 for (h = 0; h < SIZEOF (handlers); h++) | |
184 { | |
185 enum iconv_ilseq_handler handler = handlers[h]; | |
186 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
187 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
188 for (o = 0; o < 2; o++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
189 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
190 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
191 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
192 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
193 int retval = mem_iconveha (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
194 "UTF-8", "ISO-8859-1", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
195 false, handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
196 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
197 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
198 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
199 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
200 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
201 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
202 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
203 for (i = 0; i < 41; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
204 ASSERT (offsets[i] == (i < 1 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
205 i == 1 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
206 i < 13 ? i - 1 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
207 i == 13 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
208 i < 20 ? i - 2 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
209 i == 20 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
210 i < 40 ? i - 3 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
211 (size_t)(-1))); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
212 ASSERT (offsets[41] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
213 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
214 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
215 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
216 } |
7932 | 217 } |
218 | |
219 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */ | |
220 for (h = 0; h < SIZEOF (handlers); h++) | |
221 { | |
222 enum iconv_ilseq_handler handler = handlers[h]; | |
223 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ | |
224 for (o = 0; o < 2; o++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
225 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
226 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
227 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
228 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
229 int retval = mem_iconveha (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
230 "UTF-8", "ISO-8859-1", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
231 false, handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
232 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
233 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
234 switch (handler) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
235 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
236 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
237 ASSERT (retval == -1 && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
238 ASSERT (result == NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
239 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
240 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
241 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
242 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
243 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
244 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
245 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
246 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
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:
9889
diff
changeset
|
248 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
249 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
250 for (i = 0; i < 17; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
251 ASSERT (offsets[i] == (i < 5 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
252 i == 5 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
253 i - 1)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
254 ASSERT (offsets[17] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
255 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
256 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
257 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
258 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
259 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
260 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
261 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
262 static const char expected[] = "Rafa\\u0142 Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
263 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
264 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
265 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
266 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
267 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
268 for (i = 0; i < 17; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
269 ASSERT (offsets[i] == (i < 5 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
270 i == 5 ? (size_t)(-1) : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
271 i + 4)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
272 ASSERT (offsets[17] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
273 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
274 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
275 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
276 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
277 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
278 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
279 } |
7932 | 280 } |
281 | |
282 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ | |
283 for (h = 0; h < SIZEOF (handlers); h++) | |
284 { | |
285 enum iconv_ilseq_handler handler = handlers[h]; | |
286 static const char input[] = "\342"; | |
287 for (o = 0; o < 2; o++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
288 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
289 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
290 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
291 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
292 int retval = mem_iconveha (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
293 "UTF-8", "ISO-8859-1", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
294 false, handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
295 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
296 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
297 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
298 ASSERT (length == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
299 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
300 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
301 ASSERT (offsets[0] == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
302 ASSERT (offsets[1] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
303 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
304 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
305 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
306 } |
7932 | 307 } |
308 | |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7932
diff
changeset
|
309 /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2. */ |
8602
14e648f874bb
Avoid test failures on OSF/1, AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
8585
diff
changeset
|
310 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun) |
7932 | 311 /* Test conversions from autodetect_jp to UTF-8. */ |
312 for (h = 0; h < SIZEOF (handlers); h++) | |
313 { | |
314 enum iconv_ilseq_handler handler = handlers[h]; | |
315 static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */ | |
316 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ | |
317 for (o = 0; o < 2; o++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
318 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
319 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
320 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
321 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
322 int retval = mem_iconveha (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
323 "autodetect_jp", "UTF-8", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
324 false, handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
325 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
326 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
327 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
328 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
329 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
330 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
331 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
332 for (i = 0; i < 10; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
333 ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
334 ASSERT (offsets[10] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
335 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
336 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
337 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
338 } |
7932 | 339 } |
340 for (h = 0; h < SIZEOF (handlers); h++) | |
341 { | |
342 enum iconv_ilseq_handler handler = handlers[h]; | |
343 static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */ | |
344 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ | |
345 for (o = 0; o < 2; o++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
346 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
347 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
348 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
349 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
350 int retval = mem_iconveha (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
351 "autodetect_jp", "UTF-8", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
352 false, handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
353 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
354 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
355 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
356 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
357 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
358 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
359 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
360 for (i = 0; i < 10; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
361 ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
362 ASSERT (offsets[10] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
363 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
364 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
365 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
366 } |
7932 | 367 } |
368 for (h = 0; h < SIZEOF (handlers); h++) | |
369 { | |
370 enum iconv_ilseq_handler handler = handlers[h]; | |
371 static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */ | |
372 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ | |
373 for (o = 0; o < 2; o++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
374 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
375 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
376 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
377 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
378 int retval = mem_iconveha (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
379 "autodetect_jp", "UTF-8", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
380 false, handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
381 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
382 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
383 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
384 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
385 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
386 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
387 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
388 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
389 ASSERT (offsets[i] == (i == 0 ? 0 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
390 i == 5 ? 3 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
391 i == 7 ? 6 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
392 i == 9 ? 9 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
393 i == 11 ? 12 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
394 i == 13 ? 15 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
395 (size_t)(-1))); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
396 ASSERT (offsets[16] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
397 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
398 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
399 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
400 } |
7932 | 401 } |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7932
diff
changeset
|
402 # endif |
7932 | 403 |
13885 | 404 # if (((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2) && !defined __UCLIBC__) || _LIBICONV_VERSION >= 0x0105 |
7932 | 405 /* Test conversion from UTF-8 to ISO-8859-1 with transliteration. */ |
406 for (h = 0; h < SIZEOF (handlers); h++) | |
407 { | |
408 enum iconv_ilseq_handler handler = handlers[h]; | |
409 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */ | |
410 static const char expected[] = "Costs: 27 EUR"; | |
411 for (o = 0; o < 2; o++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
412 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
413 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
414 char *result = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
415 size_t length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
416 int retval = mem_iconveha (input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
417 "UTF-8", "ISO-8859-1", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
418 true, handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
419 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
420 &result, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
421 ASSERT (retval == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
422 ASSERT (length == strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
423 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
424 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
425 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
426 for (i = 0; i < 13; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
427 ASSERT (offsets[i] == (i < 11 ? i : (size_t)(-1))); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
428 ASSERT (offsets[13] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
429 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
430 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
431 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
432 } |
7932 | 433 } |
434 # endif | |
435 | |
436 /* ------------------------- Test str_iconveha() ------------------------- */ | |
437 | |
438 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */ | |
439 for (h = 0; h < SIZEOF (handlers); h++) | |
440 { | |
441 enum iconv_ilseq_handler handler = handlers[h]; | |
442 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
443 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
444 char *result = str_iconveha (input, "ISO-8859-2", "ISO-8859-1", false, handler); | |
445 ASSERT (result != NULL); | |
446 ASSERT (strcmp (result, expected) == 0); | |
447 free (result); | |
448 } | |
449 | |
450 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */ | |
451 for (h = 0; h < SIZEOF (handlers); h++) | |
452 { | |
453 enum iconv_ilseq_handler handler = handlers[h]; | |
454 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ | |
455 char *result = str_iconveha (input, "ISO-8859-2", "ISO-8859-1", false, handler); | |
456 switch (handler) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
457 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
458 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
459 ASSERT (result == NULL && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
460 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
461 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
462 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
463 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
464 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
465 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
466 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
467 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
468 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
469 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
470 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
471 static const char expected[] = "Rafa\\u0142 Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
472 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
473 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
474 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
475 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
476 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
477 } |
7932 | 478 } |
479 | |
480 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ | |
481 for (h = 0; h < SIZEOF (handlers); h++) | |
482 { | |
483 enum iconv_ilseq_handler handler = handlers[h]; | |
484 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
485 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
486 char *result = str_iconveha (input, "ISO-8859-1", "UTF-8", false, handler); | |
487 ASSERT (result != NULL); | |
488 ASSERT (strcmp (result, expected) == 0); | |
489 free (result); | |
490 } | |
491 | |
492 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */ | |
493 for (h = 0; h < SIZEOF (handlers); h++) | |
494 { | |
495 enum iconv_ilseq_handler handler = handlers[h]; | |
496 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; | |
497 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; | |
498 char *result = str_iconveha (input, "UTF-8", "ISO-8859-1", false, handler); | |
499 ASSERT (result != NULL); | |
500 ASSERT (strcmp (result, expected) == 0); | |
501 free (result); | |
502 } | |
503 | |
504 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */ | |
505 for (h = 0; h < SIZEOF (handlers); h++) | |
506 { | |
507 enum iconv_ilseq_handler handler = handlers[h]; | |
508 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */ | |
509 char *result = str_iconveha (input, "UTF-8", "ISO-8859-1", false, handler); | |
510 switch (handler) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
511 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
512 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
513 ASSERT (result == NULL && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
514 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
515 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
516 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
517 static const char expected[] = "Costs: 27 ?"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
518 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
519 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
520 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
521 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
522 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
523 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
524 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
525 static const char expected[] = "Costs: 27 \\u20AC"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
526 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
527 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
528 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
529 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
530 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
531 } |
7932 | 532 } |
533 | |
534 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ | |
535 for (h = 0; h < SIZEOF (handlers); h++) | |
536 { | |
537 enum iconv_ilseq_handler handler = handlers[h]; | |
538 static const char input[] = "\342"; | |
539 char *result = str_iconveha (input, "UTF-8", "ISO-8859-1", false, handler); | |
540 ASSERT (result != NULL); | |
541 ASSERT (strcmp (result, "") == 0); | |
542 free (result); | |
543 } | |
544 | |
8602
14e648f874bb
Avoid test failures on OSF/1, AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
8585
diff
changeset
|
545 /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2. */ |
14e648f874bb
Avoid test failures on OSF/1, AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
8585
diff
changeset
|
546 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun) |
7932 | 547 /* Test conversions from autodetect_jp to UTF-8. */ |
548 for (h = 0; h < SIZEOF (handlers); h++) | |
549 { | |
550 enum iconv_ilseq_handler handler = handlers[h]; | |
551 static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */ | |
552 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ | |
553 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler); | |
554 ASSERT (result != NULL); | |
555 ASSERT (strcmp (result, expected) == 0); | |
556 free (result); | |
557 } | |
558 for (h = 0; h < SIZEOF (handlers); h++) | |
559 { | |
560 enum iconv_ilseq_handler handler = handlers[h]; | |
561 static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */ | |
562 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ | |
563 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler); | |
564 ASSERT (result != NULL); | |
565 ASSERT (strcmp (result, expected) == 0); | |
566 free (result); | |
567 } | |
568 for (h = 0; h < SIZEOF (handlers); h++) | |
569 { | |
570 enum iconv_ilseq_handler handler = handlers[h]; | |
571 static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */ | |
572 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ | |
573 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler); | |
574 ASSERT (result != NULL); | |
575 ASSERT (strcmp (result, expected) == 0); | |
576 free (result); | |
577 } | |
8602
14e648f874bb
Avoid test failures on OSF/1, AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
8585
diff
changeset
|
578 # endif |
7932 | 579 |
13885 | 580 # if (((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2) && !defined __UCLIBC__) || _LIBICONV_VERSION >= 0x0105 |
7932 | 581 /* Test conversion from UTF-8 to ISO-8859-1 with transliteration. */ |
582 for (h = 0; h < SIZEOF (handlers); h++) | |
583 { | |
584 enum iconv_ilseq_handler handler = handlers[h]; | |
585 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */ | |
586 static const char expected[] = "Costs: 27 EUR"; | |
587 char *result = str_iconveha (input, "UTF-8", "ISO-8859-1", true, handler); | |
588 ASSERT (result != NULL); | |
589 ASSERT (strcmp (result, expected) == 0); | |
590 free (result); | |
591 } | |
592 # endif | |
593 | |
594 #endif | |
595 | |
596 return 0; | |
597 } |