1 /* Test of determining the number of multibyte characters in a string.
2 Copyright (C) 2007-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>, 2024. */
30 /* configure should already have checked that the locale is supported. */
31 if (setlocale (LC_ALL
, "") == NULL
)
34 ASSERT (mbslen ("") == 0);
35 ASSERT (mbslen ("Hello") == 5);
37 /* The following tests shows how mbslen() is different from strlen(). */
38 ASSERT (mbslen ("\303\244\303\266") == 2); /* "äö" */
39 ASSERT (mbslen ("7\342\202\254") == 2); /* "7€" */
40 ASSERT (mbslen ("\360\237\220\203") == 1); /* "🐃" */
42 ASSERT (mbslen ("\303") == 1); /* invalid multibyte sequence */
43 ASSERT (mbslen ("\342\202") == 2); /* 2x invalid multibyte sequence */
44 ASSERT (mbslen ("\360\237\220") == 3); /* 3x invalid multibyte sequence */
46 return test_exit_status
;