From c8340962dd098eb092bb9ebaad3d239c613e28f1 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 28 Aug 2023 12:07:18 +0200 Subject: [PATCH] tests: avoid test failure on Android * gl/tests/test-mbsalign.c (main): Skip the unibyte truncation test on Android, when the "C" locale in fact is multibyte. --- gl/tests/test-mbsalign.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gl/tests/test-mbsalign.c b/gl/tests/test-mbsalign.c index d7b50b470..151dbef13 100644 --- a/gl/tests/test-mbsalign.c +++ b/gl/tests/test-mbsalign.c @@ -29,10 +29,19 @@ main (void) char dest[4 * 16 + 1]; size_t width, n; - /* Test unibyte truncation. */ - width = 4; - n = mbsalign ("t\tés", dest, sizeof dest, &width, MBS_ALIGN_LEFT, 0); - ASSERT (n == 4); +#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 (MB_CUR_MAX == 1) +#endif + { + /* Test unibyte truncation. */ + width = 4; + n = mbsalign ("t\tés", dest, sizeof dest, &width, MBS_ALIGN_LEFT, 0); + ASSERT (n == 4); + } /* Test center alignment. */ width = 4; -- 2.11.4.GIT