annotate tests/test-striconveha.c @ 8754:1f57552cdb11

Better ASSERT macro.
author Bruno Haible <bruno@clisp.org>
date Sun, 29 Apr 2007 09:15:13 +0000
parents 14e648f874bb
children 633babea5f62
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.
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2007 Free Software Foundation, Inc.
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 any later version.
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #ifdef HAVE_CONFIG_H
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 # include <config.h>
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #endif
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include "striconveha.h"
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #if HAVE_ICONV
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 # include <iconv.h>
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #endif
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #include <errno.h>
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
31 #include <stdio.h>
7932
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #include <stdlib.h>
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #include <string.h>
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
36 #define ASSERT(expr) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
37 do \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
38 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
39 if (!(expr)) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
40 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
41 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
42 abort (); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
43 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
44 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
45 while (0)
7932
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 /* Magic number for detecting bounds violations. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 #define MAGIC 0x1983EFF1
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 static size_t *
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 new_offsets (size_t n)
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 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 offsets[n] = MAGIC;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 return offsets;
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
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 int
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 main ()
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 static enum iconv_ilseq_handler handlers[] =
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence };
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 size_t h;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 size_t o;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 size_t i;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 #if HAVE_ICONV
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 /* 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
69 ISO-8859-2, and UTF-8. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 /* ------------------------- Test mem_iconveha() ------------------------- */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 /* 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
74 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 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
78 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
79 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 "ISO-8859-2", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 for (i = 0; i < 37; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 ASSERT (offsets[i] == i);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 ASSERT (offsets[37] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 /* 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
104 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 "ISO-8859-2", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 switch (handler)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 case iconveh_error:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 ASSERT (retval == -1 && errno == EILSEQ);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 ASSERT (result == NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 case iconveh_question_mark:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 static const char expected[] = "Rafa? Maszkowski";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 for (i = 0; i < 16; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 ASSERT (offsets[i] == i);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 ASSERT (offsets[16] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 case iconveh_escape_sequence:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 static const char expected[] = "Rafa\\u0142 Maszkowski";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 for (i = 0; i < 16; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 ASSERT (offsets[i] == (i < 5 ? i :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 i + 5));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 ASSERT (offsets[16] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 /* 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
164 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 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
168 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
169 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 "ISO-8859-1", "UTF-8",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 for (i = 0; i < 37; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 ASSERT (offsets[i] == (i < 1 ? i :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 i < 12 ? i + 1 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 i < 18 ? i + 2 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 i + 3));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 ASSERT (offsets[37] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 /* 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
197 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 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
201 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
202 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
204 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208 "UTF-8", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
213 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
214 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 for (i = 0; i < 41; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218 ASSERT (offsets[i] == (i < 1 ? i :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 i == 1 ? (size_t)(-1) :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 i < 13 ? i - 1 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 i == 13 ? (size_t)(-1) :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 i < 20 ? i - 2 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
223 i == 20 ? (size_t)(-1) :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
224 i < 40 ? i - 3 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
225 (size_t)(-1)));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 ASSERT (offsets[41] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
235 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
239 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 "UTF-8", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 switch (handler)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250 case iconveh_error:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 ASSERT (retval == -1 && errno == EILSEQ);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 ASSERT (result == NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
253 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256 case iconveh_question_mark:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 static const char expected[] = "Rafa? Maszkowski";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 for (i = 0; i < 17; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265 ASSERT (offsets[i] == (i < 5 ? i :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 i == 5 ? (size_t)(-1) :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 i - 1));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 ASSERT (offsets[17] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 case iconveh_escape_sequence:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 static const char expected[] = "Rafa\\u0142 Maszkowski";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 if (o)
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 for (i = 0; i < 17; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 ASSERT (offsets[i] == (i < 5 ? i :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 i == 5 ? (size_t)(-1) :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 i + 4));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 ASSERT (offsets[17] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
291 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
292 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 static const char input[] = "\342";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 "UTF-8", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 ASSERT (length == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 ASSERT (offsets[0] == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 ASSERT (offsets[1] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
318 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
319 if (result != NULL)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
320 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
321 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323
8585
0290e58a0863 Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents: 7932
diff changeset
324 /* 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
325 # 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
326 /* Test conversions from autodetect_jp to UTF-8. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
327 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
328 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
329 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
330 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
331 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
332 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
334 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
335 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
336 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
337 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
338 "autodetect_jp", "UTF-8",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
339 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
340 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
341 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
344 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
345 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
346 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
347 for (i = 0; i < 10; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
348 ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1)));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349 ASSERT (offsets[10] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
351 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
354 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
356 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
357 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358 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
359 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
360 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
363 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 "autodetect_jp", "UTF-8",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
369 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
370 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
371 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
372 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
373 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
374 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
375 for (i = 0; i < 10; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
376 ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1)));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377 ASSERT (offsets[10] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
379 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
380 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
382 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
383 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
384 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
385 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
386 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
387 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
388 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
389 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
392 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
393 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
394 "autodetect_jp", "UTF-8",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
395 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
396 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
397 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
398 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
399 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
400 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
401 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
402 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
403 for (i = 0; i < 16; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
404 ASSERT (offsets[i] == (i == 0 ? 0 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405 i == 5 ? 3 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406 i == 7 ? 6 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
407 i == 9 ? 9 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
408 i == 11 ? 12 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
409 i == 13 ? 15 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
410 (size_t)(-1)));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
411 ASSERT (offsets[16] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
412 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
413 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
414 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
415 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
416 }
8585
0290e58a0863 Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents: 7932
diff changeset
417 # endif
7932
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
418
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 || _LIBICONV_VERSION >= 0x0105
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
420 /* Test conversion from UTF-8 to ISO-8859-1 with transliteration. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
421 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
422 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
423 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
424 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
425 static const char expected[] = "Costs: 27 EUR";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
426 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
427 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
428 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
429 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
430 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
431 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
432 "UTF-8", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
433 true, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
434 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
435 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
436 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
437 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
438 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
439 if (o)
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 for (i = 0; i < 13; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442 ASSERT (offsets[i] == (i < 11 ? i : (size_t)(-1)));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
443 ASSERT (offsets[13] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
444 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
445 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
446 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
447 }
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 # endif
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
450
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
451 /* ------------------------- Test str_iconveha() ------------------------- */
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 /* 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
454 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
455 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
456 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
457 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
458 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
459 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
460 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
461 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
462 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
463 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
464
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
465 /* 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
466 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
467 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
468 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
469 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
470 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
471 switch (handler)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
472 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
473 case iconveh_error:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
474 ASSERT (result == NULL && errno == EILSEQ);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
475 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
476 case iconveh_question_mark:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
477 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
478 static const char expected[] = "Rafa? Maszkowski";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
479 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
480 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
481 free (result);
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 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
484 case iconveh_escape_sequence:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
485 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
486 static const char expected[] = "Rafa\\u0142 Maszkowski";
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 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
492 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
493 }
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 /* 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
496 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
497 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
498 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
499 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
500 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
501 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
502 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
503 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
504 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
505 }
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 /* 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
508 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
509 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
510 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
511 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
512 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
513 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
514 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
515 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
516 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
517 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
518
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
519 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
520 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
521 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
522 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
523 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
524 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
525 switch (handler)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
526 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
527 case iconveh_error:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
528 ASSERT (result == NULL && errno == EILSEQ);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
529 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
530 case iconveh_question_mark:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
531 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
532 static const char expected[] = "Costs: 27 ?";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
533 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
534 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
535 free (result);
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 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
538 case iconveh_escape_sequence:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
539 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
540 static const char expected[] = "Costs: 27 \\u20AC";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
541 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
542 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
543 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
544 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
545 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
546 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
547 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
548
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
549 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
550 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
551 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
552 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
553 static const char input[] = "\342";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
554 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
555 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
556 ASSERT (strcmp (result, "") == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
557 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
558 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
559
8602
14e648f874bb Avoid test failures on OSF/1, AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 8585
diff changeset
560 /* 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
561 # 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
562 /* Test conversions from autodetect_jp to UTF-8. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
563 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
564 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
565 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
566 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
567 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
568 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
569 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
570 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
571 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
572 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
573 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
574 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
575 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
576 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
577 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
578 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
579 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
580 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
581 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
582 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
583 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
584 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
585 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
586 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
587 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
588 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
589 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
590 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
591 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
592 }
8602
14e648f874bb Avoid test failures on OSF/1, AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 8585
diff changeset
593 # endif
7932
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
594
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
595 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 || _LIBICONV_VERSION >= 0x0105
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
596 /* Test conversion from UTF-8 to ISO-8859-1 with transliteration. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
597 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
598 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
599 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
600 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
601 static const char expected[] = "Costs: 27 EUR";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
602 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
603 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
604 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
605 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
606 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
607 # endif
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
608
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
609 #endif
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
610
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
611 return 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
612 }