1 /* Verify that using C.UTF-8 works.
3 Copyright (C) 2021-2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library 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 GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
24 #include <support/support.h>
25 #include <support/check.h>
27 /* This test does two things:
28 (1) Verify that we have likely included translit_combining in C.UTF-8.
29 (2) Verify default_missing is '?' as expected. */
31 /* ISO-8859-1 encoding of "für". */
32 char iso88591_in
[] = { 0x66, 0xfc, 0x72, 0x0 };
33 /* ASCII transliteration is "fur" with C.UTF-8 translit_combining. */
34 char ascii_exp
[] = { 0x66, 0x75, 0x72, 0x0 };
36 /* First 3-byte UTF-8 code point. */
37 char utf8_in
[] = { 0xe0, 0xa0, 0x80, 0x0 };
38 /* There is no ASCII transliteration for SAMARITAN LETTER ALAF
39 so we get default_missing used which is '?'. */
40 char default_missing_exp
[] = { 0x3f, 0x0 };
53 /* The C.UTF-8 locale should include translit_combining, which provides
54 the transliteration for "LATIN SMALL LETTER U WITH DIAERESIS" which
55 is not provided by locale/C-translit.h.in. */
56 xsetlocale (LC_ALL
, "C.UTF-8");
58 /* From ISO-8859-1 to ASCII. */
59 cd
= iconv_open ("ASCII//TRANSLIT,IGNORE", "ISO-8859-1");
60 TEST_VERIFY (cd
!= (iconv_t
) -1);
65 n
= iconv (cd
, &inbuf
, &inbytes
, &outbuf
, &outbytes
);
66 TEST_VERIFY (n
!= -1);
68 TEST_COMPARE_BLOB (ascii_out
, 3, ascii_exp
, 3);
69 TEST_VERIFY (iconv_close (cd
) == 0);
71 /* From UTF-8 to ASCII. */
72 cd
= iconv_open ("ASCII//TRANSLIT,IGNORE", "UTF-8");
73 TEST_VERIFY (cd
!= (iconv_t
) -1);
78 n
= iconv (cd
, &inbuf
, &inbytes
, &outbuf
, &outbytes
);
79 TEST_VERIFY (n
!= -1);
81 TEST_COMPARE_BLOB (ascii_out
, 1, default_missing_exp
, 1);
82 TEST_VERIFY (iconv_close (cd
) == 0);
87 #include <support/test-driver.c>