diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2024-03-24 08:54:48 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2024-03-24 08:54:48 +0100 |
commit | 163a663518f33bab48b28431972e580b366b4d49 (patch) | |
tree | f518ffabaca4a0b93f0103d617e803792d3b0b43 /tests/test-mbrtowc.c | |
parent | 1b3a8d5ad2ea2f099d514d9dd51ebf926a628076 (diff) | |
parent | dd0000f7e25abe6c28d4329d324fd7fcab54094f (diff) |
Merge branch 'release/debian/1.2-1'HEADdebian/1.2-1master
Diffstat (limited to 'tests/test-mbrtowc.c')
-rw-r--r-- | tests/test-mbrtowc.c | 80 |
1 files changed, 57 insertions, 23 deletions
diff --git a/tests/test-mbrtowc.c b/tests/test-mbrtowc.c index 0e86bd49..f45f90e4 100644 --- a/tests/test-mbrtowc.c +++ b/tests/test-mbrtowc.c @@ -1,5 +1,5 @@ /* Test of conversion of multibyte character to wide character. - Copyright (C) 2008-2022 Free Software Foundation, Inc. + Copyright (C) 2008-2024 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ SIGNATURE_CHECK (mbrtowc, size_t, (wchar_t *, char const *, size_t, #include <locale.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "macros.h" @@ -72,10 +73,6 @@ main (int argc, char *argv[]) for (c = 0; c < 0x100; c++) switch (c) { - default: - if (! (c && 1 < argc && argv[1][0] == '5')) - break; - FALLTHROUGH; case '\t': case '\v': case '\f': case ' ': case '!': case '"': case '#': case '%': case '&': case '\'': case '(': case ')': case '*': @@ -97,25 +94,23 @@ main (int argc, char *argv[]) case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': case '{': case '|': case '}': case '~': - /* c is in the ISO C "basic character set", or argv[1] starts - with '5' so we are testing all nonnull bytes. */ + /* c is in the ISO C "basic character set". */ + ASSERT (c < 0x80); + /* c is an ASCII character. */ buf[0] = c; + wc = (wchar_t) 0xBADFACE; ret = mbrtowc (&wc, buf, 1, &state); ASSERT (ret == 1); - if (c < 0x80) - /* c is an ASCII character. */ - ASSERT (wc == c); - else - /* argv[1] starts with '5', that is, we are testing the C or POSIX - locale. - On most platforms, the bytes 0x80..0xFF map to U+0080..U+00FF. - But on musl libc, the bytes 0x80..0xFF map to U+DF80..U+DFFF. */ - ASSERT (wc == (btowc (c) == 0xDF00 + c ? btowc (c) : c)); + ASSERT (wc == c); ASSERT (mbsinit (&state)); + ret = mbrtowc (NULL, buf, 1, &state); ASSERT (ret == 1); ASSERT (mbsinit (&state)); + + break; + default: break; } } @@ -130,10 +125,53 @@ main (int argc, char *argv[]) ASSERT (mbsinit (&state)); } +#ifdef __ANDROID__ + /* On Android ≥ 5.0, the default locale is the "C.UTF-8" locale, not the + "C" locale. Furthermore, when you attempt to set the "C" or "POSIX" + locale via setlocale(), what you get is a "C" locale with UTF-8 encoding, + that is, effectively the "C.UTF-8" locale. */ + if (argc > 1 && strcmp (argv[1], "1") == 0 && MB_CUR_MAX > 1) + argv[1] = "3"; +#endif + if (argc > 1) switch (argv[1][0]) { case '1': + /* C or POSIX locale. */ + { + int c; + char buf[1]; + + memset (&state, '\0', sizeof (mbstate_t)); + for (c = 0; c < 0x100; c++) + if (c != 0) + { + /* We are testing all nonnull bytes. */ + buf[0] = c; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, buf, 1, &state); + /* POSIX:2018 says: "In the POSIX locale an [EILSEQ] error + cannot occur since all byte values are valid characters." */ + ASSERT (ret == 1); + if (c < 0x80) + /* c is an ASCII character. */ + ASSERT (wc == c); + else + /* On most platforms, the bytes 0x80..0xFF map to U+0080..U+00FF. + But on musl libc, the bytes 0x80..0xFF map to U+DF80..U+DFFF. */ + ASSERT (wc == (btowc (c) == 0xDF00 + c ? btowc (c) : c)); + ASSERT (mbsinit (&state)); + + ret = mbrtowc (NULL, buf, 1, &state); + ASSERT (ret == 1); + ASSERT (mbsinit (&state)); + } + } + return 0; + + case '2': /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ { char input[] = "B\374\337er"; /* "Büßer" */ @@ -180,7 +218,7 @@ main (int argc, char *argv[]) } return 0; - case '2': + case '3': /* Locale encoding is UTF-8. */ { char input[] = "B\303\274\303\237er"; /* "Büßer" */ @@ -235,7 +273,7 @@ main (int argc, char *argv[]) } return 0; - case '3': + case '4': /* Locale encoding is EUC-JP. */ { char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ @@ -291,7 +329,7 @@ main (int argc, char *argv[]) } return 0; - case '4': + case '5': /* Locale encoding is GB18030. */ { char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ @@ -347,10 +385,6 @@ main (int argc, char *argv[]) ASSERT (mbsinit (&state)); } return 0; - - case '5': - /* C locale; tested above. */ - return 0; } return 1; |