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