1 /* Tests for Unicode character output.
3 Copyright (C) 2020 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"
30 #define TEST_CODE 0x2022
31 #define TEST_CODE_AS_UTF8 "\xe2\x80\xa2"
32 #define TEST_CODE_AS_GB18030 "\x81\x36\xa6\x31"
34 static char result
[64];
37 success_callback (const char *buf
, size_t buflen
, void *callback_arg
)
39 memcpy (result
, buf
, buflen
);
40 result
[buflen
] = '\0';
45 failure_callback (unsigned int code
, const char *msg
, void *callback_arg
)
47 ASSERT (code
== TEST_CODE
);
53 main (int argc
, char *argv
[])
55 /* configure should already have checked that the locale is supported. */
56 if (setlocale (LC_ALL
, "") == NULL
)
59 switch (unicode_to_mb (TEST_CODE
, success_callback
, failure_callback
, NULL
))
65 case '1': /* On some platforms, the "C" locale has UTF-8 encoding. */
67 ASSERT (strcmp (result
, TEST_CODE_AS_UTF8
) == 0);
70 ASSERT (strcmp (result
, TEST_CODE_AS_GB18030
) == 0);
75 ASSERT (strcmp (result
, ".") == 0);