1
/* -*- buffer-read-only: t -*- vi: set ro: */
2
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3
/* Test of character set conversion.
4
Copyright (C) 2007-2010 Free Software Foundation, Inc.
6
This program is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 3 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
39
/* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1,
41
iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
42
iconv_t cd_utf8_to_88591 = iconv_open ("ISO-8859-1", "UTF-8");
44
ASSERT (cd_88591_to_utf8 != (iconv_t)(-1));
45
ASSERT (cd_utf8_to_88591 != (iconv_t)(-1));
47
/* ------------------------- Test mem_cd_iconv() ------------------------- */
49
/* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
51
static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
52
static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
55
int retval = mem_cd_iconv (input, strlen (input), cd_88591_to_utf8,
58
ASSERT (length == strlen (expected));
59
ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
63
/* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
65
static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
66
static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
69
int retval = mem_cd_iconv (input, strlen (input), cd_utf8_to_88591,
72
ASSERT (length == strlen (expected));
73
ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
77
/* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
79
static const char input[] = "\342\202\254"; /* EURO SIGN */
82
int retval = mem_cd_iconv (input, strlen (input), cd_utf8_to_88591,
84
ASSERT (retval == -1 && errno == EILSEQ);
85
ASSERT (result == NULL);
88
/* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
90
static const char input[] = "\342";
93
int retval = mem_cd_iconv (input, strlen (input), cd_utf8_to_88591,
100
/* ------------------------- Test str_cd_iconv() ------------------------- */
102
/* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
104
static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
105
static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
106
char *result = str_cd_iconv (input, cd_88591_to_utf8);
107
ASSERT (result != NULL);
108
ASSERT (strcmp (result, expected) == 0);
112
/* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
114
static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
115
static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
116
char *result = str_cd_iconv (input, cd_utf8_to_88591);
117
ASSERT (result != NULL);
118
ASSERT (strcmp (result, expected) == 0);
122
/* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
124
static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
125
char *result = str_cd_iconv (input, cd_utf8_to_88591);
126
ASSERT (result == NULL && errno == EILSEQ);
129
/* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
131
static const char input[] = "\342";
132
char *result = str_cd_iconv (input, cd_utf8_to_88591);
133
ASSERT (result != NULL);
134
ASSERT (strcmp (result, "") == 0);
138
iconv_close (cd_88591_to_utf8);
139
iconv_close (cd_utf8_to_88591);
141
/* -------------------------- Test str_iconv() -------------------------- */
143
/* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
145
static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
146
static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
147
char *result = str_iconv (input, "ISO-8859-1", "UTF-8");
148
ASSERT (result != NULL);
149
ASSERT (strcmp (result, expected) == 0);
153
/* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
155
static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
156
static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
157
char *result = str_iconv (input, "UTF-8", "ISO-8859-1");
158
ASSERT (result != NULL);
159
ASSERT (strcmp (result, expected) == 0);
163
/* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
165
static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
166
char *result = str_iconv (input, "UTF-8", "ISO-8859-1");
167
ASSERT (result == NULL && errno == EILSEQ);
170
/* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
172
static const char input[] = "\342";
173
char *result = str_iconv (input, "UTF-8", "ISO-8859-1");
174
ASSERT (result != NULL);
175
ASSERT (strcmp (result, "") == 0);