Imported Upstream version 1.4.19
[platform/upstream/m4.git] / tests / test-mbrtowc.c
index f7fed6a..404128b 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of conversion of multibyte character to wide character.
-   Copyright (C) 2008-2016 Free Software Foundation, Inc.
+   Copyright (C) 2008-2021 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
@@ -12,7 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2008.  */
 
@@ -75,7 +75,7 @@ main (int argc, char *argv[])
         default:
           if (! (c && 1 < argc && argv[1][0] == '5'))
             break;
-          /* Fall through.  */
+          FALLTHROUGH;
         case '\t': case '\v': case '\f':
         case ' ': case '!': case '"': case '#': case '%':
         case '&': case '\'': case '(': case ')': case '*':
@@ -103,7 +103,15 @@ main (int argc, char *argv[])
           wc = (wchar_t) 0xBADFACE;
           ret = mbrtowc (&wc, buf, 1, &state);
           ASSERT (ret == 1);
-          ASSERT (wc == c);
+          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 (mbsinit (&state));
           ret = mbrtowc (NULL, buf, 1, &state);
           ASSERT (ret == 1);
@@ -330,7 +338,7 @@ main (int argc, char *argv[])
           ASSERT (ret == 1);
           ASSERT (wc == 'e');
           ASSERT (mbsinit (&state));
-          input[5] = '\0';
+          input[7] = '\0';
 
           wc = (wchar_t) 0xBADFACE;
           ret = mbrtowc (&wc, input + 8, 1, &state);