1 /* Verify the BIG5HKSCS outputs that generate 2 wchar_t's (Bug 25734).
2 Copyright (C) 2020-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
23 #include <support/check.h>
24 #include <support/support.h>
26 /* A few BIG5-HKSCS characters map in two unicode code points.
28 /x88/x62 => <U00CA><U0304>
29 /x88/x64 => <U00CA><U030C>
30 /x88/xa3 => <U00EA><U0304>
31 /x88/xa5 => <U00EA><U030C>
32 Each of these is special cased in iconvdata/big5hkscs.c.
33 This test ensures that we correctly reset the shift state after
34 outputting any of these characters. We do this by converting
35 each them followed by converting an ASCII character. If we fail
36 to reset the shift state (bug 25734) then we'll see the last
37 character in the queue output again. */
39 /* Each test has name, input bytes, and expected wide character
47 /* In BIG5-HKSCS (2008) there are 4 characters that generate multiple
49 struct testdata tests
[4] = {
50 /* <H-8862>X => <U+00CA><U+0304>X */
51 { "<H-8862>", "\x88\x62\x58", { 0x00CA, 0x0304, 0x0058 } },
52 /* <H-8864>X => <U+00CA><U+030C>X */
53 { "<H-8864>", "\x88\x64\x58", { 0x00CA, 0x030C, 0x0058 } },
54 /* <H-88A3>X => <U+00EA><U+0304>X */
55 { "<H-88A3>", "\x88\xa3\x58", { 0x00EA, 0x0304, 0x0058 } },
56 /* <H-88A5>X => <U+00EA><U+030C>X */
57 { "<H-88A5>", "\x88\xa5\x58", { 0x00EA, 0x030C, 0x0058 } }
60 /* Each test is of the form:
61 - Translate first code sequence (two bytes)
62 - Translate second (zero bytes)
63 - Translate the third (one byte). */
65 check_conversion (struct testdata test
)
71 const char *mbs
= test
.input
;
73 /* Input is always 3 bytes long. */
76 memset (&st
, 0, sizeof (st
));
77 /* First conversion: Consumes first 2 bytes. */
78 ret
= mbrtowc (&wc
, mbs
, inlen
- consumed
, &st
);
81 printf ("error: First conversion consumed only %zd bytes.\n", ret
);
84 /* Advance the two consumed bytes. */
87 if (wc
!= test
.expected
[0])
89 printf ("error: Result of first conversion was wrong.\n");
92 /* Second conversion: Consumes 0 bytes. */
93 ret
= mbrtowc (&wc
, mbs
, inlen
- consumed
, &st
);
96 printf ("error: Second conversion consumed only %zd bytes.\n", ret
);
99 /* Advance the zero consumed bytes. */
102 if (wc
!= test
.expected
[1])
104 printf ("error: Result of second conversion was wrong.\n");
107 /* After the second conversion the state of the converter should be
108 in the initial state. It is in the initial state because the two
109 input BIG5-HKSCS bytes have been consumed and the 2 wchar_t's have
111 if (mbsinit (&st
) == 0)
113 printf ("error: Converter not in initial state.\n");
116 /* Third conversion: Consumes 1 byte (it's an ASCII character). */
117 ret
= mbrtowc (&wc
, mbs
, inlen
- consumed
, &st
);
120 printf ("error: Third conversion consumed only %zd bytes.\n", ret
);
123 /* Advance the one byte. */
126 if (wc
!= test
.expected
[2])
128 printf ("error: Result of third conversion was wrong.\n");
131 /* Return 0 if we saw no errors. */
140 /* Testing BIG5-HKSCS. */
141 xsetlocale (LC_ALL
, "zh_HK.BIG5-HKSCS");
143 /* Run all the special conversions. */
144 for (int i
= 0; i
< (sizeof (tests
) / sizeof (struct testdata
)); i
++)
146 printf ("Running test for %s\n", tests
[i
].name
);
147 ret
= check_conversion (tests
[i
]);
149 printf ("Test %s failed.\n", tests
[i
].name
);
153 /* Fail if any conversion had an error. */
155 FAIL_EXIT1 ("One or more conversions failed.");
160 #include <support/test-driver.c>