annotate tests/test-striconveha.c @ 12043:fc84db4ef49d

test-unlinkat: enhance test, to expose Solaris 9 bug Share the unlink tests with unlinkat. * tests/test-unlink.c (main): Factor guts... * tests/test-unlink.h (test_rmdir_func): ...into new file. * tests/test-rmdir.h (test_rmdir_func): Add parameter. * tests/test-rmdir.c (main): Adjust caller. * tests/test-unlinkat.c (main): Likewise. Add unlink tests. (unlinker): New helper function. (rmdirat): Enhance check. * modules/rmdir-tests (Depends-on): Add stdbool. * modules/unlink-tests (Depends-on): Likewise. (Files): Add test-unlink.h. * modules/openat-tests (Files): Likewise. (Depends-on): Add unlinkdir. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Thu, 17 Sep 2009 22:16:56 -0600
parents 0be6f1ab456d
children e8d2c6fc33ad
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.
9889
0be6f1ab456d Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents: 9749
diff changeset
2 Copyright (C) 2007-2008 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>
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
28 #include <stdio.h>
7932
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include <stdlib.h>
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #include <string.h>
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
33 #define ASSERT(expr) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
34 do \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
35 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
36 if (!(expr)) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
37 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
38 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
9889
0be6f1ab456d Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents: 9749
diff changeset
39 fflush (stderr); \
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
40 abort (); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
41 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
42 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8602
diff changeset
43 while (0)
7932
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 /* Magic number for detecting bounds violations. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 #define MAGIC 0x1983EFF1
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 static size_t *
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 new_offsets (size_t n)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 offsets[n] = MAGIC;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 return offsets;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 int
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 main ()
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 static enum iconv_ilseq_handler handlers[] =
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence };
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 size_t h;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 size_t o;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 size_t i;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 #if HAVE_ICONV
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 /* 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
67 ISO-8859-2, and UTF-8. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 /* ------------------------- Test mem_iconveha() ------------------------- */
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 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
72 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 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
76 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
77 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 "ISO-8859-2", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 if (o)
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 for (i = 0; i < 37; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 ASSERT (offsets[i] == i);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 ASSERT (offsets[37] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 free (result);
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 }
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 /* 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
102 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 "ISO-8859-2", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 switch (handler)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 case iconveh_error:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 ASSERT (retval == -1 && errno == EILSEQ);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 ASSERT (result == NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 case iconveh_question_mark:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 static const char expected[] = "Rafa? Maszkowski";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 for (i = 0; i < 16; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 ASSERT (offsets[i] == i);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 ASSERT (offsets[16] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 free (result);
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 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 case iconveh_escape_sequence:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 static const char expected[] = "Rafa\\u0142 Maszkowski";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 if (o)
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 for (i = 0; i < 16; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 ASSERT (offsets[i] == (i < 5 ? i :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 i + 5));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 ASSERT (offsets[16] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 free (result);
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 break;
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 }
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 /* 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
162 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 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
166 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
167 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 "ISO-8859-1", "UTF-8",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 if (o)
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 for (i = 0; i < 37; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 ASSERT (offsets[i] == (i < 1 ? i :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 i < 12 ? i + 1 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 i < 18 ? i + 2 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 i + 3));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 ASSERT (offsets[37] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 free (result);
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 }
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 /* 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
195 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 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
199 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
200 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
204 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 "UTF-8", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
213 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
214 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 for (i = 0; i < 41; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216 ASSERT (offsets[i] == (i < 1 ? i :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 i == 1 ? (size_t)(-1) :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218 i < 13 ? i - 1 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 i == 13 ? (size_t)(-1) :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 i < 20 ? i - 2 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 i == 20 ? (size_t)(-1) :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 i < 40 ? i - 3 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
223 (size_t)(-1)));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
224 ASSERT (offsets[41] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
225 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227 free (result);
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 }
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 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
235 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
239 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 "UTF-8", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246 switch (handler)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 case iconveh_error:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 ASSERT (retval == -1 && errno == EILSEQ);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250 ASSERT (result == NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
253 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254 case iconveh_question_mark:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256 static const char expected[] = "Rafa? Maszkowski";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 for (i = 0; i < 17; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 ASSERT (offsets[i] == (i < 5 ? i :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 i == 5 ? (size_t)(-1) :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265 i - 1));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 ASSERT (offsets[17] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 free (result);
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 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272 case iconveh_escape_sequence:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 static const char expected[] = "Rafa\\u0142 Maszkowski";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 for (i = 0; i < 17; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 ASSERT (offsets[i] == (i < 5 ? i :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 i == 5 ? (size_t)(-1) :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 i + 4));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 ASSERT (offsets[17] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 free (result);
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 break;
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 }
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 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298 static const char input[] = "\342";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305 "UTF-8", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 ASSERT (length == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 ASSERT (offsets[0] == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 ASSERT (offsets[1] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 }
9749
daf5ba9fe2d9 Remove useless "if" tests before free. Deprecate "free" module.
Jim Meyering <meyering@redhat.com>
parents: 9309
diff changeset
317 free (result);
7932
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 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
320
8585
0290e58a0863 Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents: 7932
diff changeset
321 /* 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
322 # 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
323 /* Test conversions from autodetect_jp to UTF-8. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
325 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
326 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
327 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
328 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
329 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
330 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
331 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
334 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
335 "autodetect_jp", "UTF-8",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
336 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
337 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
338 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
339 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
340 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
341 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
344 for (i = 0; i < 10; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
345 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
346 ASSERT (offsets[10] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
347 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
348 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 }
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 for (h = 0; h < SIZEOF (handlers); h++)
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 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355 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
356 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
357 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
359 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
360 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
363 "autodetect_jp", "UTF-8",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
369 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
370 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
371 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
372 for (i = 0; i < 10; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
373 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
374 ASSERT (offsets[10] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
375 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
376 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 }
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 for (h = 0; h < SIZEOF (handlers); h++)
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 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
383 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
384 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
385 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
386 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
387 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
388 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
389 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 "autodetect_jp", "UTF-8",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
392 false, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
393 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
394 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
395 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
396 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
397 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
398 if (o)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
399 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
400 for (i = 0; i < 16; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
401 ASSERT (offsets[i] == (i == 0 ? 0 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
402 i == 5 ? 3 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
403 i == 7 ? 6 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
404 i == 9 ? 9 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405 i == 11 ? 12 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406 i == 13 ? 15 :
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
407 (size_t)(-1)));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
408 ASSERT (offsets[16] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
409 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
410 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
411 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
412 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
413 }
8585
0290e58a0863 Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents: 7932
diff changeset
414 # endif
7932
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 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 || _LIBICONV_VERSION >= 0x0105
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
417 /* Test conversion from UTF-8 to ISO-8859-1 with transliteration. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
418 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
420 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
421 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
422 static const char expected[] = "Costs: 27 EUR";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
423 for (o = 0; o < 2; o++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
424 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
425 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
426 char *result = NULL;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
427 size_t length = 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
428 int retval = mem_iconveha (input, strlen (input),
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
429 "UTF-8", "ISO-8859-1",
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
430 true, handler,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
431 offsets,
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
432 &result, &length);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
433 ASSERT (retval == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
434 ASSERT (length == strlen (expected));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
435 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
436 if (o)
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 for (i = 0; i < 13; i++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
439 ASSERT (offsets[i] == (i < 11 ? i : (size_t)(-1)));
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
440 ASSERT (offsets[13] == MAGIC);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
441 free (offsets);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
443 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
444 }
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 # endif
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 /* ------------------------- Test str_iconveha() ------------------------- */
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 no errors. */
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[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
455 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
456 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
457 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
458 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
459 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
460 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
461
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
462 /* 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
463 for (h = 0; h < SIZEOF (handlers); h++)
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 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
466 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
467 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
468 switch (handler)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
469 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
470 case iconveh_error:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
471 ASSERT (result == NULL && errno == EILSEQ);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
472 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
473 case iconveh_question_mark:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
474 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
475 static const char expected[] = "Rafa? Maszkowski";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
476 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
477 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
478 free (result);
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 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
481 case iconveh_escape_sequence:
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 static const char expected[] = "Rafa\\u0142 Maszkowski";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
484 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
485 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
486 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
487 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
488 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
489 }
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 ISO-8859-1 to UTF-8 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[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
497 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
498 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
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 no errors. */
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[] = "\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
509 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
510 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
511 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
512 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
513 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
514 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
515
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
516 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
517 for (h = 0; h < SIZEOF (handlers); h++)
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 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
520 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
521 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
522 switch (handler)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
523 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
524 case iconveh_error:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
525 ASSERT (result == NULL && errno == EILSEQ);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
526 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
527 case iconveh_question_mark:
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
528 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
529 static const char expected[] = "Costs: 27 ?";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
530 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
531 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
532 free (result);
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 break;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
535 case iconveh_escape_sequence:
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 static const char expected[] = "Costs: 27 \\u20AC";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
538 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
539 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
540 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
541 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
542 break;
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 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
545
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
546 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
547 for (h = 0; h < SIZEOF (handlers); h++)
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 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
550 static const char input[] = "\342";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
551 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
552 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
553 ASSERT (strcmp (result, "") == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
554 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
555 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
556
8602
14e648f874bb Avoid test failures on OSF/1, AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 8585
diff changeset
557 /* 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
558 # 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
559 /* Test conversions from autodetect_jp to UTF-8. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
560 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
561 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
562 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
563 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
564 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
565 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
566 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
567 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
568 free (result);
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 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
571 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
572 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
573 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
574 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
575 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
576 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
577 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
578 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
579 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
580 for (h = 0; h < SIZEOF (handlers); h++)
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
581 {
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
582 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
583 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
584 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
585 char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
586 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
587 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
588 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
589 }
8602
14e648f874bb Avoid test failures on OSF/1, AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 8585
diff changeset
590 # endif
7932
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 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 || _LIBICONV_VERSION >= 0x0105
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
593 /* Test conversion from UTF-8 to ISO-8859-1 with transliteration. */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
594 for (h = 0; h < SIZEOF (handlers); h++)
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 enum iconv_ilseq_handler handler = handlers[h];
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
597 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
598 static const char expected[] = "Costs: 27 EUR";
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
599 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
600 ASSERT (result != NULL);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
601 ASSERT (strcmp (result, expected) == 0);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
602 free (result);
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
603 }
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
604 # endif
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
605
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
606 #endif
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
607
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
608 return 0;
1749aa1eb511 Tests for 'striconveha' module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
609 }