annotate tests/test-striconveh.c @ 17693:53803f7bacc5

maint: add ChangeLog entry missing in previous commit * ChangeLog: Add the omitted entry.
author Pádraig Brady <P@draigBrady.com>
date Mon, 02 Jun 2014 20:08:05 +0100
parents 344018b6e5d7
children ab58d4870664
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of character set conversion with error handling.
17587
344018b6e5d7 maint: update copyright
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
2 Copyright (C) 2007-2014 Free Software Foundation, Inc.
7883
e590ba9dd9c2 Tests for striconveh 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
7883
e590ba9dd9c2 Tests for striconveh 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.
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
e590ba9dd9c2 Tests for striconveh 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/>. */
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
e590ba9dd9c2 Tests for striconveh 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>
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "striconveh.h"
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #if HAVE_ICONV
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 # include <iconv.h>
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #endif
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <errno.h>
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <stdlib.h>
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include <string.h>
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
31 #include "macros.h"
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
33 /* Magic number for detecting bounds violations. */
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
34 #define MAGIC 0x1983EFF1
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
35
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
36 static size_t *
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
37 new_offsets (size_t n)
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
38 {
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
39 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t));
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
40 offsets[n] = MAGIC;
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
41 return offsets;
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
42 }
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
43
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 int
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 main ()
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 static enum iconv_ilseq_handler handlers[] =
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence };
11951
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
49 size_t indirect;
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 size_t h;
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
51 size_t o;
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
52 size_t i;
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 #if HAVE_ICONV
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1,
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 ISO-8859-2, and UTF-8. */
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
57 iconv_t cd_ascii_to_88591 = iconv_open ("ISO-8859-1", "ASCII");
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 iconv_t cd_88591_to_88592 = iconv_open ("ISO-8859-2", "ISO-8859-1");
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 iconv_t cd_88592_to_88591 = iconv_open ("ISO-8859-1", "ISO-8859-2");
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
60 iconv_t cd_ascii_to_utf8 = iconv_open ("UTF-8", "ASCII");
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 iconv_t cd_utf8_to_88591 = iconv_open ("ISO-8859-1", "UTF-8");
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 iconv_t cd_88592_to_utf8 = iconv_open ("UTF-8", "ISO-8859-2");
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 iconv_t cd_utf8_to_88592 = iconv_open ("ISO-8859-2", "UTF-8");
10407
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
65 iconv_t cd_utf7_to_utf8 = iconv_open ("UTF-8", "UTF-7");
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
66 iconveh_t cdeh_ascii_to_88591;
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
67 iconveh_t cdeh_ascii_to_88591_indirectly;
11912
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
68 iconveh_t cdeh_88592_to_88591;
11951
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
69 iconveh_t cdeh_88592_to_88591_indirectly;
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
70 iconveh_t cdeh_ascii_to_utf8;
11912
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
71 iconveh_t cdeh_88591_to_utf8;
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
72 iconveh_t cdeh_utf8_to_88591;
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
73 iconveh_t cdeh_utf7_to_utf8;
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
75 ASSERT (cd_ascii_to_utf8 != (iconv_t)(-1));
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 ASSERT (cd_88591_to_utf8 != (iconv_t)(-1));
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 ASSERT (cd_utf8_to_88591 != (iconv_t)(-1));
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 ASSERT (cd_88592_to_utf8 != (iconv_t)(-1));
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 ASSERT (cd_utf8_to_88592 != (iconv_t)(-1));
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
81 cdeh_ascii_to_88591.cd = cd_ascii_to_88591;
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
82 cdeh_ascii_to_88591.cd1 = cd_ascii_to_utf8;
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
83 cdeh_ascii_to_88591.cd2 = cd_utf8_to_88591;
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
84
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
85 cdeh_ascii_to_88591_indirectly.cd = (iconv_t)(-1);
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
86 cdeh_ascii_to_88591_indirectly.cd1 = cd_ascii_to_utf8;
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
87 cdeh_ascii_to_88591_indirectly.cd2 = cd_utf8_to_88591;
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
88
11912
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
89 cdeh_88592_to_88591.cd = cd_88592_to_88591;
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
90 cdeh_88592_to_88591.cd1 = cd_88592_to_utf8;
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
91 cdeh_88592_to_88591.cd2 = cd_utf8_to_88591;
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
92
11951
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
93 cdeh_88592_to_88591_indirectly.cd = (iconv_t)(-1);
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
94 cdeh_88592_to_88591_indirectly.cd1 = cd_88592_to_utf8;
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
95 cdeh_88592_to_88591_indirectly.cd2 = cd_utf8_to_88591;
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
96
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
97 cdeh_ascii_to_utf8.cd = cd_ascii_to_utf8;
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
98 cdeh_ascii_to_utf8.cd1 = cd_ascii_to_utf8;
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
99 cdeh_ascii_to_utf8.cd2 = (iconv_t)(-1);
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
100
11912
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
101 cdeh_88591_to_utf8.cd = cd_88591_to_utf8;
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
102 cdeh_88591_to_utf8.cd1 = cd_88591_to_utf8;
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
103 cdeh_88591_to_utf8.cd2 = (iconv_t)(-1);
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
104
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
105 cdeh_utf8_to_88591.cd = cd_utf8_to_88591;
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
106 cdeh_utf8_to_88591.cd1 = (iconv_t)(-1);
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
107 cdeh_utf8_to_88591.cd2 = cd_utf8_to_88591;
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
108
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
109 cdeh_utf7_to_utf8.cd = cd_utf7_to_utf8;
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
110 cdeh_utf7_to_utf8.cd1 = cd_utf7_to_utf8;
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
111 cdeh_utf7_to_utf8.cd2 = (iconv_t)(-1);
ba1f5a03459a Make the striconveh API easier to use.
Bruno Haible <bruno@clisp.org>
parents: 11464
diff changeset
112
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 /* ------------------------ Test mem_cd_iconveh() ------------------------ */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
11951
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
116 for (indirect = 0; indirect <= 1; indirect++)
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 {
11951
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
118 for (h = 0; h < SIZEOF (handlers); h++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
119 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
120 enum iconv_ilseq_handler handler = handlers[h];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
121 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
122 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
123 for (o = 0; o < 2; o++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
124 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
125 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
126 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
127 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
128 int retval = mem_cd_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
129 (indirect
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
130 ? &cdeh_88592_to_88591_indirectly
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
131 : &cdeh_88592_to_88591),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
132 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
133 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
134 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
135 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
136 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
137 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
138 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
139 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
140 for (i = 0; i < 37; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
141 ASSERT (offsets[i] == i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
142 ASSERT (offsets[37] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
143 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
144 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
145 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
146 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
147 }
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
150 /* Test conversion from ASCII to ISO-8859-1 with invalid input (EILSEQ). */
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
151 for (indirect = 0; indirect <= 1; indirect++)
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
152 {
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
153 for (h = 0; h < SIZEOF (handlers); h++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
154 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
155 enum iconv_ilseq_handler handler = handlers[h];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
156 static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
157 for (o = 0; o < 2; o++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
158 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
159 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
160 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
161 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
162 int retval = mem_cd_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
163 (indirect
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
164 ? &cdeh_ascii_to_88591_indirectly
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
165 : &cdeh_ascii_to_88591),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
166 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
167 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
168 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
169 switch (handler)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
170 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
171 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
172 ASSERT (retval == -1 && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
173 ASSERT (result == NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
174 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
175 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
176 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
177 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
178 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
179 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
180 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
181 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
182 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
183 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
184 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
185 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
186 for (i = 0; i < 16; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
187 ASSERT (offsets[i] == i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
188 ASSERT (offsets[16] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
189 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
190 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
191 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
192 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
193 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
194 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
195 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
196 }
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
197 }
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
198
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
11951
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
200 for (indirect = 0; indirect <= 1; indirect++)
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 {
11951
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
202 for (h = 0; h < SIZEOF (handlers); h++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
203 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
204 enum iconv_ilseq_handler handler = handlers[h];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
205 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
206 for (o = 0; o < 2; o++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
207 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
208 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
209 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
210 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
211 int retval = mem_cd_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
212 (indirect
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
213 ? &cdeh_88592_to_88591_indirectly
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
214 : &cdeh_88592_to_88591),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
215 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
216 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
217 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
218 switch (handler)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
219 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
220 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
221 ASSERT (retval == -1 && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
222 ASSERT (result == NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
223 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
224 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
225 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
226 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
227 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
228 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
229 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
230 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
231 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
232 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
233 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
234 for (i = 0; i < 16; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
235 ASSERT (offsets[i] == i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
236 ASSERT (offsets[16] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
237 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
238 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
239 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
240 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
241 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
242 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
243 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
244 static const char expected[] = "Rafa\\u0142 Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
245 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
246 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
247 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
248 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
249 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
250 for (i = 0; i < 16; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
251 ASSERT (offsets[i] == (i < 5 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
252 i + 5));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
253 ASSERT (offsets[16] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
254 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
255 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
256 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
257 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
258 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
259 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
260 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
261 }
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
270 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
271 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
272 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
273 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
274 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
275 int retval = mem_cd_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
276 &cdeh_88591_to_utf8,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
277 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
278 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
279 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
280 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
281 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
282 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
283 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
284 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
285 for (i = 0; i < 37; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
286 ASSERT (offsets[i] == (i < 1 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
287 i < 12 ? i + 1 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
288 i < 18 ? i + 2 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
289 i + 3));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
290 ASSERT (offsets[37] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
291 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
292 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
293 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
294 }
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
303 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
304 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
305 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
306 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
307 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
308 int retval = mem_cd_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
309 &cdeh_utf8_to_88591,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
310 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
311 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
312 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
313 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
314 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
315 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
316 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
317 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
318 for (i = 0; i < 41; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
319 ASSERT (offsets[i] == (i < 1 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
320 i == 1 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
321 i < 13 ? i - 1 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
322 i == 13 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
323 i < 20 ? i - 2 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
324 i == 20 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
325 i < 40 ? i - 3 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
326 (size_t)(-1)));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
327 ASSERT (offsets[41] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
328 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
329 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
330 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
331 }
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
334 /* Test conversion from ASCII to UTF-8 with invalid input (EILSEQ). */
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
335 for (h = 0; h < SIZEOF (handlers); h++)
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
336 {
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
337 enum iconv_ilseq_handler handler = handlers[h];
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
338 static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
339 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
340 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
341 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
342 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
343 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
344 int retval = mem_cd_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
345 &cdeh_ascii_to_utf8,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
346 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
347 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
348 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
349 switch (handler)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
350 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
351 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
352 ASSERT (retval == -1 && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
353 ASSERT (result == NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
354 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
355 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
356 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
357 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
358 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
359 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
360 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
361 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
362 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
363 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
364 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
365 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
366 for (i = 0; i < 16; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
367 ASSERT (offsets[i] == i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
368 ASSERT (offsets[16] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
369 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
370 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
371 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
372 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
373 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
374 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
375 }
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
376 }
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
377
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
379 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
380 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
382 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
383 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
384 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
385 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
386 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
387 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
388 int retval = mem_cd_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
389 &cdeh_utf8_to_88591,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
390 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
391 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
392 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
393 switch (handler)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
394 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
395 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
396 ASSERT (retval == -1 && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
397 ASSERT (result == NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
398 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
399 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
400 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
401 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
402 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
403 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
404 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
405 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
406 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
407 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
408 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
409 for (i = 0; i < 17; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
410 ASSERT (offsets[i] == (i < 5 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
411 i == 5 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
412 i - 1));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
413 ASSERT (offsets[17] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
414 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
415 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
416 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
417 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
418 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
419 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
420 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
421 static const char expected[] = "Rafa\\u0142 Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
422 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
423 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
424 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
425 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
426 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
427 for (i = 0; i < 17; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
428 ASSERT (offsets[i] == (i < 5 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
429 i == 5 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
430 i + 4));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
431 ASSERT (offsets[17] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
432 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
433 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
434 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
435 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
436 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
437 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
438 }
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
439 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
440
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
441 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
443 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
444 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
445 static const char input[] = "\342";
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
446 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
447 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
448 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
449 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
450 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
451 int retval = mem_cd_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
452 &cdeh_utf8_to_88591,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
453 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
454 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
455 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
456 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
457 ASSERT (length == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
458 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
459 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
460 ASSERT (offsets[0] == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
461 ASSERT (offsets[1] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
462 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
463 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
464 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
465 }
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
466 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
467
10407
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
468 if (cd_utf7_to_utf8 != (iconv_t)(-1))
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
469 {
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
470 /* Disabled on Solaris, because Solaris 9 iconv() is buggy: it returns
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
471 -1 / EILSEQ when converting the 7th byte of the input "+VDLYP9hA". */
10407
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
472 # if !(defined __sun && !defined _LIBICONV_VERSION)
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
473 /* Test conversion from UTF-7 to UTF-8 with EINVAL. */
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
474 for (h = 0; h < SIZEOF (handlers); h++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
475 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
476 enum iconv_ilseq_handler handler = handlers[h];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
477 /* This is base64 encoded 0x54 0x32 0xD8 0x3F 0xD8 0x40. It would
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
478 convert to U+5432 U+D83F U+D840 but these are Unicode surrogates. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
479 static const char input[] = "+VDLYP9hA";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
480 static const char expected1[] = "\345\220\262"; /* 吲 glibc */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
481 static const char expected2[] = ""; /* libiconv */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
482 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
483 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
484 int retval = mem_cd_iconveh (input, 7,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
485 &cdeh_utf7_to_utf8,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
486 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
487 NULL,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
488 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
489 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
490 ASSERT (length == strlen (expected1) || length == strlen (expected2));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
491 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
492 if (length == strlen (expected1))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
493 ASSERT (memcmp (result, expected1, strlen (expected1)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
494 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
495 ASSERT (memcmp (result, expected2, strlen (expected2)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
496 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
497 }
10407
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
498
13370
aac0d7011945 Avoid a test failure on NetBSD 5.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
499 /* Disabled on NetBSD, because NetBSD 5.0 iconv() is buggy: it converts
aac0d7011945 Avoid a test failure on NetBSD 5.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
500 the input "+2D/YQNhB" to U+1FED8 U+3FD8 U+40D8. */
aac0d7011945 Avoid a test failure on NetBSD 5.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
501 # if !(defined __NetBSD__ && !defined _LIBICONV_VERSION)
10407
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
502 /* Test conversion from UTF-7 to UTF-8 with EILSEQ. */
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
503 for (h = 0; h < SIZEOF (handlers); h++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
504 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
505 enum iconv_ilseq_handler handler = handlers[h];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
506 /* This is base64 encoded 0xD8 0x3F 0xD8 0x40 0xD8 0x41. It would
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
507 convert to U+D83F U+D840 U+D841 but these are Unicode surrogates. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
508 static const char input[] = "+2D/YQNhB";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
509 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
510 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
511 int retval = mem_cd_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
512 &cdeh_utf7_to_utf8,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
513 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
514 NULL,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
515 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
516 switch (handler)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
517 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
518 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
519 ASSERT (retval == -1 && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
520 ASSERT (result == NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
521 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
522 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
523 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
524 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
525 /* glibc result */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
526 static const char expected1[] = "?????";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
527 /* libiconv <= 1.12 result */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
528 static const char expected2[] = "?2D/YQNhB";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
529 /* libiconv behaviour changed in version 1.13: the result is
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
530 '?' U+0FF6 U+1036; this is U+D83F U+D840 U+D841 shifted left
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
531 by 6 bits. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
532 static const char expected3[] = "?\340\277\266\341\200\266";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
533 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
534 ASSERT (length == strlen (expected1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
535 || length == strlen (expected2)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
536 || length == strlen (expected3));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
537 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
538 if (length == strlen (expected1))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
539 ASSERT (memcmp (result, expected1, strlen (expected1)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
540 else if (length == strlen (expected2))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
541 ASSERT (memcmp (result, expected2, strlen (expected2)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
542 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
543 ASSERT (memcmp (result, expected3, strlen (expected3)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
544 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
545 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
546 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
547 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
548 }
13370
aac0d7011945 Avoid a test failure on NetBSD 5.0.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
549 # endif
10407
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
550 # endif
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
551 }
2575b6d4b6b5 Check behaviour when converting from UTF-7.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
552
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
553 /* ------------------------ Test str_cd_iconveh() ------------------------ */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
554
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
555 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
11951
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
556 for (indirect = 0; indirect <= 1; indirect++)
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
557 {
11951
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
558 for (h = 0; h < SIZEOF (handlers); h++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
559 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
560 enum iconv_ilseq_handler handler = handlers[h];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
561 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
562 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
563 char *result = str_cd_iconveh (input,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
564 (indirect
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
565 ? &cdeh_88592_to_88591_indirectly
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
566 : &cdeh_88592_to_88591),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
567 handler);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
568 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
569 ASSERT (strcmp (result, expected) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
570 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
571 }
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
572 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
573
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
574 /* Test conversion from ASCII to ISO-8859-1 with invalid input (EILSEQ). */
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
575 for (indirect = 0; indirect <= 1; indirect++)
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
576 {
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
577 for (h = 0; h < SIZEOF (handlers); h++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
578 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
579 enum iconv_ilseq_handler handler = handlers[h];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
580 static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
581 char *result = str_cd_iconveh (input,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
582 (indirect
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
583 ? &cdeh_ascii_to_88591_indirectly
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
584 : &cdeh_ascii_to_88591),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
585 handler);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
586 switch (handler)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
587 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
588 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
589 ASSERT (result == NULL && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
590 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
591 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
592 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
593 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
594 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
595 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
596 ASSERT (strcmp (result, expected) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
597 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
598 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
599 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
600 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
601 }
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
602 }
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
603
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
604 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
11951
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
605 for (indirect = 0; indirect <= 1; indirect++)
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
606 {
11951
5bb7bec3987e Test indirect conversion as well.
Bruno Haible <bruno@clisp.org>
parents: 11912
diff changeset
607 for (h = 0; h < SIZEOF (handlers); h++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
608 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
609 enum iconv_ilseq_handler handler = handlers[h];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
610 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
611 char *result = str_cd_iconveh (input,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
612 (indirect
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
613 ? &cdeh_88592_to_88591_indirectly
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
614 : &cdeh_88592_to_88591),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
615 handler);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
616 switch (handler)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
617 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
618 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
619 ASSERT (result == NULL && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
620 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
621 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
622 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
623 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
624 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
625 ASSERT (strcmp (result, expected) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
626 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
627 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
628 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
629 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
630 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
631 static const char expected[] = "Rafa\\u0142 Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
632 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
633 ASSERT (strcmp (result, expected) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
634 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
635 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
636 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
637 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
638 }
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
639 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
640
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
641 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
642 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
643 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
644 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
645 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
646 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
647 char *result = str_cd_iconveh (input,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
648 &cdeh_88591_to_utf8,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
649 handler);
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
650 ASSERT (result != NULL);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
651 ASSERT (strcmp (result, expected) == 0);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
652 free (result);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
653 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
654
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
655 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
656 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
657 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
658 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
659 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
660 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
661 char *result = str_cd_iconveh (input,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
662 &cdeh_utf8_to_88591,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
663 handler);
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
664 ASSERT (result != NULL);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
665 ASSERT (strcmp (result, expected) == 0);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
666 free (result);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
667 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
668
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
669 /* Test conversion from ASCII to UTF-8 with invalid input (EILSEQ). */
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
670 for (h = 0; h < SIZEOF (handlers); h++)
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
671 {
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
672 enum iconv_ilseq_handler handler = handlers[h];
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
673 static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
674 char *result = str_cd_iconveh (input,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
675 &cdeh_ascii_to_utf8,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
676 handler);
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
677 switch (handler)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
678 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
679 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
680 ASSERT (result == NULL && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
681 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
682 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
683 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
684 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
685 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
686 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
687 ASSERT (strcmp (result, expected) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
688 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
689 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
690 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
691 }
11952
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
692 }
0ae7f1f4ed08 Fix bug occurring when converting invalid input.
Bruno Haible <bruno@clisp.org>
parents: 11951
diff changeset
693
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
694 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
695 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
696 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
697 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
698 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
699 char *result = str_cd_iconveh (input,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
700 &cdeh_utf8_to_88591,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
701 handler);
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
702 switch (handler)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
703 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
704 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
705 ASSERT (result == NULL && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
706 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
707 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
708 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
709 static const char expected[] = "Costs: 27 ?";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
710 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
711 ASSERT (strcmp (result, expected) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
712 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
713 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
714 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
715 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
716 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
717 static const char expected[] = "Costs: 27 \\u20AC";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
718 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
719 ASSERT (strcmp (result, expected) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
720 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
721 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
722 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
723 }
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
724 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
725
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
726 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
727 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
728 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
729 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
730 static const char input[] = "\342";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
731 char *result = str_cd_iconveh (input,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
732 &cdeh_utf8_to_88591,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
733 handler);
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
734 ASSERT (result != NULL);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
735 ASSERT (strcmp (result, "") == 0);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
736 free (result);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
737 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
738
8585
0290e58a0863 Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents: 7927
diff changeset
739 if (cd_88591_to_88592 != (iconv_t)(-1))
0290e58a0863 Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents: 7927
diff changeset
740 iconv_close (cd_88591_to_88592);
0290e58a0863 Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents: 7927
diff changeset
741 if (cd_88592_to_88591 != (iconv_t)(-1))
0290e58a0863 Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents: 7927
diff changeset
742 iconv_close (cd_88592_to_88591);
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
743 iconv_close (cd_88591_to_utf8);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
744 iconv_close (cd_utf8_to_88591);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
745 iconv_close (cd_88592_to_utf8);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
746 iconv_close (cd_utf8_to_88592);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
747
7915
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
748 /* ------------------------- Test mem_iconveh() ------------------------- */
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
749
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
750 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
751 for (h = 0; h < SIZEOF (handlers); h++)
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
752 {
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
753 enum iconv_ilseq_handler handler = handlers[h];
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
754 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
755 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
756 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
757 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
758 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
759 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
760 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
761 int retval = mem_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
762 "ISO-8859-2", "ISO-8859-1",
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
763 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
764 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
765 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
766 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
767 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
768 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
769 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
770 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
771 for (i = 0; i < 37; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
772 ASSERT (offsets[i] == i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
773 ASSERT (offsets[37] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
774 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
775 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
776 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
777 }
7915
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
778 }
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
779
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
780 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
781 for (h = 0; h < SIZEOF (handlers); h++)
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
782 {
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
783 enum iconv_ilseq_handler handler = handlers[h];
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
784 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
785 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
786 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
787 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
788 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
789 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
790 int retval = mem_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
791 "ISO-8859-2", "ISO-8859-1",
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
792 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
793 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
794 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
795 switch (handler)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
796 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
797 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
798 ASSERT (retval == -1 && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
799 ASSERT (result == NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
800 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
801 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
802 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
803 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
804 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
805 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
806 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
807 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
808 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
809 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
810 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
811 for (i = 0; i < 16; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
812 ASSERT (offsets[i] == i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
813 ASSERT (offsets[16] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
814 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
815 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
816 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
817 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
818 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
819 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
820 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
821 static const char expected[] = "Rafa\\u0142 Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
822 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
823 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
824 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
825 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
826 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
827 for (i = 0; i < 16; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
828 ASSERT (offsets[i] == (i < 5 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
829 i + 5));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
830 ASSERT (offsets[16] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
831 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
832 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
833 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
834 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
835 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
836 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
837 }
7915
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
838 }
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
839
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
840 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
841 for (h = 0; h < SIZEOF (handlers); h++)
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
842 {
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
843 enum iconv_ilseq_handler handler = handlers[h];
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
844 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
845 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
846 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
847 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
848 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
849 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
850 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
851 int retval = mem_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
852 "ISO-8859-1", "UTF-8",
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
853 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
854 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
855 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
856 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
857 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
858 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
859 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
860 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
861 for (i = 0; i < 37; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
862 ASSERT (offsets[i] == (i < 1 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
863 i < 12 ? i + 1 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
864 i < 18 ? i + 2 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
865 i + 3));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
866 ASSERT (offsets[37] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
867 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
868 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
869 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
870 }
7915
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
871 }
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
872
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
873 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
874 for (h = 0; h < SIZEOF (handlers); h++)
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
875 {
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
876 enum iconv_ilseq_handler handler = handlers[h];
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
877 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
878 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
879 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
880 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
881 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
882 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
883 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
884 int retval = mem_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
885 "UTF-8", "ISO-8859-1",
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
886 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
887 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
888 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
889 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
890 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
891 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
892 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
893 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
894 for (i = 0; i < 41; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
895 ASSERT (offsets[i] == (i < 1 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
896 i == 1 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
897 i < 13 ? i - 1 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
898 i == 13 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
899 i < 20 ? i - 2 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
900 i == 20 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
901 i < 40 ? i - 3 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
902 (size_t)(-1)));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
903 ASSERT (offsets[41] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
904 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
905 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
906 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
907 }
7915
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
908 }
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
909
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
910 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
911 for (h = 0; h < SIZEOF (handlers); h++)
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
912 {
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
913 enum iconv_ilseq_handler handler = handlers[h];
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
914 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
915 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
916 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
917 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
918 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
919 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
920 int retval = mem_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
921 "UTF-8", "ISO-8859-1",
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
922 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
923 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
924 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
925 switch (handler)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
926 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
927 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
928 ASSERT (retval == -1 && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
929 ASSERT (result == NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
930 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
931 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
932 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
933 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
934 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
935 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
936 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
937 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
938 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
939 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
940 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
941 for (i = 0; i < 17; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
942 ASSERT (offsets[i] == (i < 5 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
943 i == 5 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
944 i - 1));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
945 ASSERT (offsets[17] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
946 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
947 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
948 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
949 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
950 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
951 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
952 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
953 static const char expected[] = "Rafa\\u0142 Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
954 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
955 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
956 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
957 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
958 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
959 for (i = 0; i < 17; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
960 ASSERT (offsets[i] == (i < 5 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
961 i == 5 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
962 i + 4));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
963 ASSERT (offsets[17] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
964 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
965 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
966 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
967 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
968 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
969 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
970 }
7915
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
971 }
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
972
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
973 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
974 for (h = 0; h < SIZEOF (handlers); h++)
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
975 {
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
976 enum iconv_ilseq_handler handler = handlers[h];
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
977 static const char input[] = "\342";
7927
7ebab05df4f6 Add optional offsets argument to conversion routines.
Bruno Haible <bruno@clisp.org>
parents: 7915
diff changeset
978 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
979 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
980 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
981 char *result = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
982 size_t length = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
983 int retval = mem_iconveh (input, strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
984 "UTF-8", "ISO-8859-1",
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
985 handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
986 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
987 &result, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
988 ASSERT (retval == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
989 ASSERT (length == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
990 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
991 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
992 ASSERT (offsets[0] == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
993 ASSERT (offsets[1] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
994 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
995 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
996 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
997 }
7915
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
998 }
957b6eccce2c New function mem_iconveh.
Bruno Haible <bruno@clisp.org>
parents: 7914
diff changeset
999
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1000 /* ------------------------- Test str_iconveh() ------------------------- */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1001
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1002 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1003 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1004 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1005 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1006 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1007 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1008 char *result = str_iconveh (input, "ISO-8859-2", "ISO-8859-1", handler);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1009 ASSERT (result != NULL);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1010 ASSERT (strcmp (result, expected) == 0);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1011 free (result);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1012 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1013
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1014 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1015 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1016 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1017 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1018 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1019 char *result = str_iconveh (input, "ISO-8859-2", "ISO-8859-1", handler);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1020 switch (handler)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1021 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1022 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1023 ASSERT (result == NULL && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1024 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1025 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1026 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1027 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1028 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1029 ASSERT (strcmp (result, expected) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1030 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1031 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1032 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1033 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1034 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1035 static const char expected[] = "Rafa\\u0142 Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1036 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1037 ASSERT (strcmp (result, expected) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1038 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1039 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1040 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1041 }
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1042 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1043
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1044 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1045 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1046 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1047 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1048 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1049 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1050 char *result = str_iconveh (input, "ISO-8859-1", "UTF-8", handler);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1051 ASSERT (result != NULL);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1052 ASSERT (strcmp (result, expected) == 0);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1053 free (result);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1054 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1055
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1056 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1057 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1058 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1059 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1060 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1061 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1062 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1063 ASSERT (result != NULL);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1064 ASSERT (strcmp (result, expected) == 0);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1065 free (result);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1066 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1067
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1068 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1069 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1070 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1071 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1072 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1073 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1074 switch (handler)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1075 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1076 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1077 ASSERT (result == NULL && errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1078 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1079 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1080 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1081 static const char expected[] = "Costs: 27 ?";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1082 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1083 ASSERT (strcmp (result, expected) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1084 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1085 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1086 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1087 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1088 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1089 static const char expected[] = "Costs: 27 \\u20AC";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1090 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1091 ASSERT (strcmp (result, expected) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1092 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1093 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1094 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11952
diff changeset
1095 }
7883
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1096 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1097
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1098 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1099 for (h = 0; h < SIZEOF (handlers); h++)
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1100 {
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1101 enum iconv_ilseq_handler handler = handlers[h];
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1102 static const char input[] = "\342";
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1103 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1104 ASSERT (result != NULL);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1105 ASSERT (strcmp (result, "") == 0);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1106 free (result);
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1107 }
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1108
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1109 #endif
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1110
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1111 return 0;
e590ba9dd9c2 Tests for striconveh module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1112 }