]> Savannah Git Hosting - gnulib.git/commitdiff
mbrtowc, mbrtoc32 tests: Avoid test failure on Android ≥ 5.0.
authorBruno Haible <bruno@clisp.org>
Mon, 16 Jan 2023 13:34:56 +0000 (14:34 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 16 Jan 2023 14:53:45 +0000 (15:53 +0100)
* tests/test-mbrtowc.c (main): On Android 5.0 or newer, when testing
the "C" locale, verify that the encoding is UTF-8.
* tests/test-mbrtoc32.c (main): Likewise.
* doc/posix-functions/setlocale.texi: Mention the Android problems.

ChangeLog
doc/posix-functions/setlocale.texi
tests/test-mbrtoc32.c
tests/test-mbrtowc.c

index 045e1c62471ab7f097f92f85f61ac6aea297b95b..0051e3237fa764c01a0343f530611035940f9496 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2023-01-16  Bruno Haible  <bruno@clisp.org>
 
+       mbrtowc, mbrtoc32 tests: Avoid test failure on Android ≥ 5.0.
+       * tests/test-mbrtowc.c (main): On Android 5.0 or newer, when testing
+       the "C" locale, verify that the encoding is UTF-8.
+       * tests/test-mbrtoc32.c (main): Likewise.
+       * doc/posix-functions/setlocale.texi: Mention the Android problems.
+
        mbrtowc, mbrtoc32 tests: Refactor.
        * tests/test-mbrtowc.c (main): Straighten convoluted code.
        * tests/test-mbrtoc32.c (main): Likewise.
index 11364d3901a959d5f6f5790431efef8e2fd85751..6e232200f82125a0fb1e7af7536320a7fe34a6bb 100644 (file)
@@ -21,7 +21,7 @@ On Windows platforms (excluding Cygwin), @code{setlocale} understands different
 locale names, that are not based on ISO 639 language names and ISO 3166 country
 names.
 @item
-On Android 4.3, which which doesn't have locales, the @code{setlocale} function
+On Android < 5.0, which doesn't have locales, the @code{setlocale} function
 always fails.  The replacement, however, supports only the locale names
 @code{"C"} and @code{"POSIX"}.
 @end itemize
@@ -52,4 +52,10 @@ In addition any value is accepted for @code{LC_CTYPE}, and so NULL
 is never returned to indicate a failure to set locale.
 To verify category values, each category must be set individually
 with @code{setlocale(LC_COLLATE,"")} etc.
+@item
+On Android 5.0 and newer, the default locale (i.e.@: the locale in use when
+@code{setlocale} was not called) is the @code{"C.UTF-8"} locale, not the
+@code{"C"} locale.  Additionally, a @code{setlocale} call that is meant to set
+the @code{"C"} or @code{"POSIX"} locale actually sets an equivalent of the
+@code{"C.UTF-8"} locale.
 @end itemize
index 36b520f7b8547c7cc4f21ee84640cecae88ad561..0d75c3db14b07c6e342ee976a75688e0663080d4 100644 (file)
@@ -26,6 +26,7 @@ SIGNATURE_CHECK (mbrtoc32, size_t,
 
 #include <locale.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "macros.h"
@@ -124,6 +125,15 @@ 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], "5") == 0 && MB_CUR_MAX > 1)
+    argv[1] = "2";
+#endif
+
   if (argc > 1)
     switch (argv[1][0])
       {
index b358d8d583bc02337091fcfb64f9f81c4c8c0c51..1fdf039c428c28fe8738ea241434d3e16282b462 100644 (file)
@@ -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"
@@ -124,6 +125,15 @@ 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], "5") == 0 && MB_CUR_MAX > 1)
+    argv[1] = "2";
+#endif
+
   if (argc > 1)
     switch (argv[1][0])
       {