1 /* Test of conversion of 32-bit wide string to string.
2 Copyright (C) 2008-2020 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>, 2008. */
23 #include "signature.h"
24 SIGNATURE_CHECK (c32stombs
, size_t,
25 (char *, const char32_t
*, size_t));
34 main (int argc
, char *argv
[])
36 /* configure should already have checked that the locale is supported. */
37 if (setlocale (LC_ALL
, "") == NULL
)
50 for (i
= 0; i
< BUFSIZE
; i
++)
57 /* Locale encoding is ISO-8859-1 or ISO-8859-15. */
59 const char original
[] = "B\374\337er"; /* "Büßer" */
61 ret
= mbstoc32s (input
, original
, 10);
64 for (n
= 0; n
< 10; n
++)
66 ret
= c32stombs (NULL
, input
, n
);
69 ret
= c32stombs (buf
, input
, n
);
70 ASSERT (ret
== (n
<= 5 ? n
: 5));
71 ASSERT (memcmp (buf
, original
, ret
) == 0);
73 ASSERT (buf
[ret
] == '\0');
74 ASSERT (buf
[ret
+ (n
> 5) + 0] == '_');
75 ASSERT (buf
[ret
+ (n
> 5) + 1] == '_');
76 ASSERT (buf
[ret
+ (n
> 5) + 2] == '_');
82 /* Locale encoding is UTF-8. */
84 const char original
[] = "s\303\274\303\237\360\237\230\213!"; /* "süß😋!" */
86 ret
= mbstoc32s (input
, original
, 10);
89 for (n
= 0; n
< 15; n
++)
91 ret
= c32stombs (NULL
, input
, n
);
94 ret
= c32stombs (buf
, input
, n
);
95 ASSERT (ret
== (n
< 1 ? n
:
100 ASSERT (memcmp (buf
, original
, ret
) == 0);
102 ASSERT (buf
[ret
] == '\0');
103 ASSERT (buf
[ret
+ (n
> 10) + 0] == '_');
104 ASSERT (buf
[ret
+ (n
> 10) + 1] == '_');
105 ASSERT (buf
[ret
+ (n
> 10) + 2] == '_');
111 /* Locale encoding is EUC-JP. */
113 const char original
[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */
115 ret
= mbstoc32s (input
, original
, 10);
118 for (n
= 0; n
< 10; n
++)
120 ret
= c32stombs (NULL
, input
, n
);
123 ret
= c32stombs (buf
, input
, n
);
124 ASSERT (ret
== (n
< 1 ? n
:
129 ASSERT (memcmp (buf
, original
, ret
) == 0);
131 ASSERT (buf
[ret
] == '\0');
132 ASSERT (buf
[ret
+ (n
> 8) + 0] == '_');
133 ASSERT (buf
[ret
+ (n
> 8) + 1] == '_');
134 ASSERT (buf
[ret
+ (n
> 8) + 2] == '_');
141 /* Locale encoding is GB18030. */
143 const char original
[] = "s\250\271\201\060\211\070\224\071\375\067!"; /* "süß😋!" */
145 ret
= mbstoc32s (input
, original
, 10);
148 for (n
= 0; n
< 15; n
++)
150 ret
= c32stombs (NULL
, input
, n
);
153 ret
= c32stombs (buf
, input
, n
);
154 ASSERT (ret
== (n
< 1 ? n
:
159 ASSERT (memcmp (buf
, original
, ret
) == 0);
161 ASSERT (buf
[ret
] == '\0');
162 ASSERT (buf
[ret
+ (n
> 12) + 0] == '_');
163 ASSERT (buf
[ret
+ (n
> 12) + 1] == '_');
164 ASSERT (buf
[ret
+ (n
> 12) + 2] == '_');