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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7932
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 8754
diff changeset
19 #include <config.h>
7932
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "striconveha.h"
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #if HAVE_ICONV
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 # include <iconv.h>
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #endif
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <errno.h>
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <stdlib.h>
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include <string.h>
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
31 #include "macros.h"
7932
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 /* Magic number for detecting bounds violations. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #define MAGIC 0x1983EFF1
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 static size_t *
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 new_offsets (size_t n)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 offsets[n] = MAGIC;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 return offsets;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 int
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 main ()
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 static enum iconv_ilseq_handler handlers[] =
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence };
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 size_t h;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 size_t o;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 size_t i;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 #if HAVE_ICONV
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 ISO-8859-2, and UTF-8. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 /* ------------------------- Test mem_iconveha() ------------------------- */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
223 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 static const char input[] = "\342";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 /* Test conversions from autodetect_jp to UTF-8. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
339 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
340 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
341 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343 static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
344 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
369 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
370 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
371 static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
372 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
403
13885
87a95303747f Port to uClibc.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
404 # if (((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2) && !defined __UCLIBC__) || _LIBICONV_VERSION >= 0x0105
7932
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405 /* Test conversion from UTF-8 to ISO-8859-1 with transliteration. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
407 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
408 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
409 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
410 static const char expected[] = "Costs: 27 EUR";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
433 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
434 # endif
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
435
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
436 /* ------------------------- Test str_iconveha() ------------------------- */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
437
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
438 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
439 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
440 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
441 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
443 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
444 char *result = str_iconveha (input, "ISO-8859-2", "ISO-8859-1", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
445 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
446 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
447 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
448 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
449
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
450 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
451 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
452 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
453 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
454 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
455 char *result = str_iconveha (input, "ISO-8859-2", "ISO-8859-1", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
478 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
479
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
480 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
481 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
482 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
483 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
484 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
485 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
486 char *result = str_iconveha (input, "ISO-8859-1", "UTF-8", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
487 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
488 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
489 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
490 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
491
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
492 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
493 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
494 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
495 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
496 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
497 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
498 char *result = str_iconveha (input, "UTF-8", "ISO-8859-1", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
499 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
500 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
501 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
502 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
503
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
504 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
505 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
506 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
507 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
508 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
509 char *result = str_iconveha (input, "UTF-8", "ISO-8859-1", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
532 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
533
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
534 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
535 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
536 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
537 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
538 static const char input[] = "\342";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
539 char *result = str_iconveha (input, "UTF-8", "ISO-8859-1", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
540 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
541 ASSERT (strcmp (result, "") == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
542 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
543 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
547 /* Test conversions from autodetect_jp to UTF-8. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
548 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
549 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
550 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
551 static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
552 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
553 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
554 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
555 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
556 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
557 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
558 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
559 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
560 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
561 static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
562 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
563 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
564 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
565 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
566 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
567 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
568 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
569 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
570 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
571 static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
572 static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
573 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
574 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
575 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
576 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
579
13885
87a95303747f Port to uClibc.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
580 # if (((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2) && !defined __UCLIBC__) || _LIBICONV_VERSION >= 0x0105
7932
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
581 /* Test conversion from UTF-8 to ISO-8859-1 with transliteration. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
582 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
583 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
584 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
585 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
586 static const char expected[] = "Costs: 27 EUR";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
587 char *result = str_iconveha (input, "UTF-8", "ISO-8859-1", true, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
588 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
589 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
590 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
591 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
592 # endif
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
593
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
594 #endif
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
595
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
596 return 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
597 }