maint.mk: Update system header list for #include syntax checks.
[gnulib.git] / tests / test-mbrtoc32-regular.c
blob513e0eae0cd73467668972d7ac0d3cabeac98e04
1 /* Test of conversion of multibyte character to 32-bit wide character.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2023. */
19 #include <config.h>
21 #include <uchar.h>
23 #include <locale.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <uchar.h>
28 #include <wchar.h>
30 #include "macros.h"
32 int
33 main (int argc, char *argv[])
35 /* The only locales in which mbrtoc32 may map a multibyte character to a
36 sequence of two or more Unicode characters are those with BIG5-HKSCS
37 encoding. See
38 <https://lists.gnu.org/archive/html/bug-gnulib/2023-06/msg00134.html>
39 <https://lists.gnu.org/archive/html/bug-gnulib/2023-07/msg00014.html> */
40 if (setlocale (LC_ALL, "zh_HK.BIG5-HKSCS") == NULL)
42 fprintf (stderr, "Skipping test: found no locale with BIG5-HKSCS encoding.\n");
43 return 77;
46 /* The problematic BIG5-HKSCS characters are:
48 input maps to name
49 ----- ------- ----
50 0x88 0x62 U+00CA U+0304 LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND MACRON
51 0x88 0x64 U+00CA U+030C LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND CARON
52 0x88 0xA3 U+00EA U+0304 LATIN SMALL LETTER E WITH CIRCUMFLEX AND MACRON
53 0x88 0xA5 U+00EA U+030C LATIN SMALL LETTER E WITH CIRCUMFLEX AND CARON
55 Test one of them.
56 See <https://sourceware.org/bugzilla/show_bug.cgi?id=30611>. */
57 mbstate_t state;
58 memset (&state, '\0', sizeof (mbstate_t));
59 char32_t c32 = (char32_t) 0xBADFACE;
60 size_t ret = mbrtoc32 (&c32, "\210\142", 2, &state);
61 /* It is OK if this conversion fails. */
62 if (ret != (size_t)(-1))
64 /* mbrtoc32 being regular, means that STATE is in an initial state. */
65 ASSERT (mbsinit (&state));
66 ret = mbrtoc32 (&c32, "", 0, &state);
67 /* mbrtoc32 being regular, means that it returns (size_t)(-2), not
68 (size_t)(-3), here. */
69 ASSERT (ret == (size_t)(-2));
70 ret = mbrtoc32 (&c32, "", 1, &state);
71 /* mbrtoc32 being regular, means that it returns the null 32-bit wide
72 character, here, not any remnant from the previous multibyte
73 character. */
74 ASSERT (ret == 0);
75 ASSERT (c32 == 0);
78 return test_exit_status;