usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-mbfile.c
blob3565404294b3d9e46681aacb0edd90430ae61330
1 /* Test of multibyte character I/O.
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 "mbfile.h"
23 #include <locale.h>
24 #include <string.h>
26 #include "localcharset.h"
27 #include "macros.h"
29 int
30 main ()
32 /* Switch to an UTF-8 locale. */
33 if (!(setlocale (LC_ALL, "en_US.UTF-8") != NULL
34 /* Check whether it's really an UTF-8 locale.
35 On native Windows, this setlocale call succeeds but the encoding
36 of this locale is CP1252, not UTF-8. */
37 && strcmp (locale_charset (), "UTF-8") == 0))
39 fprintf (stderr, "Skipping test: English Unicode locale is not installed\n");
40 return 77;
43 mb_file_t mbstdin;
44 mbf_init (mbstdin, stdin);
45 /* The input consists of 4 UTF-8 characters:
46 '$', U+00A5, U+20AC, U+0001F403. */
47 mbf_char_t next;
49 mbf_getc (next, mbstdin);
50 ASSERT (!mb_iseof (next));
51 ASSERT (mb_len (next) == 1);
52 ASSERT (mb_iseq (next, 0x0024));
54 mbf_getc (next, mbstdin);
55 ASSERT (!mb_iseof (next));
56 ASSERT (mb_len (next) == 2);
57 ASSERT (mb_iseq (next, 0x00A5));
59 mbf_getc (next, mbstdin);
60 ASSERT (!mb_iseof (next));
61 ASSERT (mb_len (next) == 3);
62 ASSERT (mb_iseq (next, 0x20AC));
64 mbf_getc (next, mbstdin);
65 ASSERT (!mb_iseof (next));
66 ASSERT (mb_len (next) == 4);
67 ASSERT (mb_iseq (next, 0x1F403));
69 mbf_getc (next, mbstdin);
70 ASSERT (mb_iseof (next));
72 return test_exit_status;