1 /* Tests for Unicode character output.
3 Copyright (C) 2020-2024 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* Written by Bruno Haible, 2020. */
23 #include "unicodeio.h"
28 #include "localcharset.h"
31 #define TEST_CODE 0x2022
32 #define TEST_CODE_AS_UTF8 "\xe2\x80\xa2"
33 #define TEST_CODE_AS_GB18030 "\x81\x36\xa6\x31"
35 static char result
[64];
38 success_callback (const char *buf
, size_t buflen
, void *callback_arg
)
40 memcpy (result
, buf
, buflen
);
41 result
[buflen
] = '\0';
46 failure_callback (unsigned int code
, const char *msg
, void *callback_arg
)
48 ASSERT (code
== TEST_CODE
);
54 main (int argc
, char *argv
[])
56 /* configure should already have checked that the locale is supported. */
57 if (setlocale (LC_ALL
, "") == NULL
)
60 switch (unicode_to_mb (TEST_CODE
, success_callback
, failure_callback
, NULL
))
67 /* On some platforms, the "C" locale has UTF-8 encoding.
68 And on native Windows, the "C" locale may have an 8-bit encoding
69 such as CP1252, that contains the U+2022 character. */
71 const char *charset
= locale_charset ();
72 if (strcmp (charset
, "CP874") == 0
73 || strcmp (charset
, "CP1250") == 0
74 || strcmp (charset
, "CP1251") == 0
75 || strcmp (charset
, "CP1252") == 0
76 || strcmp (charset
, "CP1253") == 0
77 || strcmp (charset
, "CP1254") == 0
78 || strcmp (charset
, "CP1255") == 0
79 || strcmp (charset
, "CP1256") == 0
80 || strcmp (charset
, "CP1257") == 0
81 || strcmp (charset
, "CP1258") == 0)
82 ASSERT (strcmp (result
, "\x95") == 0);
84 ASSERT (strcmp (result
, TEST_CODE_AS_UTF8
) == 0);
88 ASSERT (strcmp (result
, TEST_CODE_AS_UTF8
) == 0);
91 ASSERT (strcmp (result
, TEST_CODE_AS_GB18030
) == 0);
96 ASSERT (strcmp (result
, ".") == 0);
102 return test_exit_status
;