Mercurial > gnulib
changeset 39308:eec4f11d84a9
localename: Fix test failures on mingw.
* lib/localename.c (gl_locale_name_thread): Remove code specific to
native Windows.
(gl_locale_name_posix): Move code specific to native Windows here.
* tests/test-localename.c (test_locale_name, test_locale_name_posix):
Accept result without charset suffix, as it appears on mingw.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Wed, 02 May 2018 23:36:18 +0200 |
parents | dc5b9ab0285a |
children | 0f39d8831bc4 |
files | ChangeLog lib/localename.c tests/test-localename.c |
diffstat | 3 files changed, 47 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue May 01 09:38:31 2018 -0700 +++ b/ChangeLog Wed May 02 23:36:18 2018 +0200 @@ -1,3 +1,12 @@ +2018-05-02 Bruno Haible <bruno@clisp.org> + + localename: Fix test failures on mingw. + * lib/localename.c (gl_locale_name_thread): Remove code specific to + native Windows. + (gl_locale_name_posix): Move code specific to native Windows here. + * tests/test-localename.c (test_locale_name, test_locale_name_posix): + Accept result without charset suffix, as it appears on mingw. + 2018-04-28 Paul Smith <psmith@gnu.org> bootstrap: Avoid gnulib operations if not needed
--- a/lib/localename.c Tue May 01 09:38:31 2018 -0700 +++ b/lib/localename.c Wed May 02 23:36:18 2018 +0200 @@ -2786,28 +2786,10 @@ const char *name = gl_locale_name_thread_unsafe (category, categoryname); if (name != NULL) return struniq (name); -#elif defined WINDOWS_NATIVE - if (LC_MIN <= category && category <= LC_MAX) - { - char *locname = setlocale (category, NULL); - LCID lcid = 0; - - /* If CATEGORY is LC_ALL, the result might be a semi-colon - separated list of locales. We need only one, so we take the - one corresponding to LC_CTYPE, as the most important for - character translations. */ - if (strchr (locname, ';')) - locname = setlocale (LC_CTYPE, NULL); - - /* Convert locale name to LCID. We don't want to use - LocaleNameToLCID because (a) it is only available since Vista, - and (b) it doesn't accept locale names returned by 'setlocale'. */ - lcid = get_lcid (locname); - - if (lcid > 0) - return gl_locale_name_from_win32_LCID (lcid); - } #endif + /* On WINDOWS_NATIVE, don't use GetThreadLocale() here, because when + SetThreadLocale has not been called - which is a very frequent case - + the value of GetThreadLocale() ignores past calls to 'setlocale'. */ return NULL; } @@ -2824,6 +2806,28 @@ const char * gl_locale_name_posix (int category, const char *categoryname) { +#if defined WINDOWS_NATIVE + if (LC_MIN <= category && category <= LC_MAX) + { + char *locname = setlocale (category, NULL); + LCID lcid = 0; + + /* If CATEGORY is LC_ALL, the result might be a semi-colon + separated list of locales. We need only one, so we take the + one corresponding to LC_CTYPE, as the most important for + character translations. */ + if (category == LC_ALL && strchr (locname, ';')) + locname = setlocale (LC_CTYPE, NULL); + + /* Convert locale name to LCID. We don't want to use + LocaleNameToLCID because (a) it is only available since Vista, + and (b) it doesn't accept locale names returned by 'setlocale'. */ + lcid = get_lcid (locname); + + if (lcid > 0) + return gl_locale_name_from_win32_LCID (lcid); + } +#endif /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'. On some systems this can be done by the 'setlocale' function itself. */ #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
--- a/tests/test-localename.c Tue May 01 09:38:31 2018 -0700 +++ b/tests/test-localename.c Wed May 02 23:36:18 2018 +0200 @@ -155,7 +155,16 @@ if (setlocale (LC_ALL, "") != NULL) { name = gl_locale_name (LC_CTYPE, "LC_CTYPE"); +#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ + /* On native Windows, here, + gl_locale_name_thread (LC_CTYPE, "LC_CTYPE") + returns NULL and + gl_locale_name_posix (LC_CTYPE, "LC_CTYPE") + returns either "de_DE" or "de_DE.UTF-8". */ + ASSERT (strcmp (name, "de_DE") == 0 || strcmp (name, "de_DE.UTF-8") == 0); +#else ASSERT (strcmp (name, "de_DE.UTF-8") == 0); +#endif name = gl_locale_name (LC_MESSAGES, "LC_MESSAGES"); ASSERT (strcmp (name, "fr_FR.UTF-8") == 0); } @@ -575,7 +584,11 @@ if (setlocale (LC_ALL, "") != NULL) { name = gl_locale_name_posix (LC_CTYPE, "LC_CTYPE"); +#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ + ASSERT (strcmp (name, "de_DE") == 0 || strcmp (name, "de_DE.UTF-8") == 0); +#else ASSERT (strcmp (name, "de_DE.UTF-8") == 0); +#endif name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"); ASSERT (strcmp (name, "fr_FR.UTF-8") == 0); }