"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "bootstrapped/tests/test-localename.c" between
gnuastro-0.7.tar.lz and gnuastro-0.8.tar.lz

About: Gnuastro (GNU Astronomy Utilities) consists of separate command line programs for the manipulation and analysis of astronomical data.

test-localename.c  (gnuastro-0.7.tar.lz):test-localename.c  (gnuastro-0.8.tar.lz)
skipping to change at line 29 skipping to change at line 29
#include <config.h> #include <config.h>
#include "localename.h" #include "localename.h"
#include <locale.h> #include <locale.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "macros.h" #include "macros.h"
#if HAVE_NEWLOCALE && HAVE_USELOCALE #if HAVE_NEWLOCALE && HAVE_WORKING_USELOCALE && !HAVE_FAKE_LOCALES
# define HAVE_GOOD_USELOCALE 1
#endif
#if HAVE_GOOD_USELOCALE
static struct { int cat; int mask; const char *string; } const categories[] = static struct { int cat; int mask; const char *string; } const categories[] =
{ {
{ LC_CTYPE, LC_CTYPE_MASK, "LC_CTYPE" }, { LC_CTYPE, LC_CTYPE_MASK, "LC_CTYPE" },
{ LC_NUMERIC, LC_NUMERIC_MASK, "LC_NUMERIC" }, { LC_NUMERIC, LC_NUMERIC_MASK, "LC_NUMERIC" },
{ LC_TIME, LC_TIME_MASK, "LC_TIME" }, { LC_TIME, LC_TIME_MASK, "LC_TIME" },
{ LC_COLLATE, LC_COLLATE_MASK, "LC_COLLATE" }, { LC_COLLATE, LC_COLLATE_MASK, "LC_COLLATE" },
{ LC_MONETARY, LC_MONETARY_MASK, "LC_MONETARY" }, { LC_MONETARY, LC_MONETARY_MASK, "LC_MONETARY" },
{ LC_MESSAGES, LC_MESSAGES_MASK, "LC_MESSAGES" } { LC_MESSAGES, LC_MESSAGES_MASK, "LC_MESSAGES" }
# ifdef LC_PAPER # ifdef LC_PAPER
skipping to change at line 65 skipping to change at line 69
, { LC_IDENTIFICATION, LC_IDENTIFICATION_MASK, "LC_IDENTIFICATION" } , { LC_IDENTIFICATION, LC_IDENTIFICATION_MASK, "LC_IDENTIFICATION" }
# endif # endif
}; };
#endif #endif
/* Test the gl_locale_name() function. */ /* Test the gl_locale_name() function. */
static void static void
test_locale_name (void) test_locale_name (void)
{ {
const char *ret;
const char *name; const char *name;
/* Check that gl_locale_name returns non-NULL. */ /* Check that gl_locale_name returns non-NULL. */
ASSERT (gl_locale_name (LC_MESSAGES, "LC_MESSAGES") != NULL); ASSERT (gl_locale_name (LC_MESSAGES, "LC_MESSAGES") != NULL);
/* Get into a defined state, */ /* Get into a defined state, */
setlocale (LC_ALL, "en_US.UTF-8"); setlocale (LC_ALL, "en_US.UTF-8");
#if HAVE_NEWLOCALE && HAVE_USELOCALE #if HAVE_GOOD_USELOCALE
uselocale (LC_GLOBAL_LOCALE); uselocale (LC_GLOBAL_LOCALE);
#endif #endif
/* Check that when all environment variables are unset, /* Check that when all environment variables are unset,
gl_locale_name returns the default locale. */ gl_locale_name returns the default locale. */
unsetenv ("LC_ALL"); unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE"); unsetenv ("LC_CTYPE");
unsetenv ("LC_MESSAGES"); unsetenv ("LC_MESSAGES");
unsetenv ("LC_NUMERIC"); unsetenv ("LC_NUMERIC");
unsetenv ("LANG"); unsetenv ("LANG");
setlocale (LC_ALL, ""); /* Need also to unset all environment variables that specify standard or
non-standard locale categories. Otherwise, on glibc systems, when some
of these variables are set and reference a nonexistent locale, the
setlocale (LC_ALL, "") call below would fail. */
unsetenv ("LC_COLLATE");
unsetenv ("LC_MONETARY");
unsetenv ("LC_TIME");
unsetenv ("LC_ADDRESS");
unsetenv ("LC_IDENTIFICATION");
unsetenv ("LC_MEASUREMENT");
unsetenv ("LC_NAME");
unsetenv ("LC_PAPER");
unsetenv ("LC_TELEPHONE");
ret = setlocale (LC_ALL, "");
ASSERT (ret != NULL);
ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
gl_locale_name_default ()) == 0); gl_locale_name_default ()) == 0);
ASSERT (strcmp (gl_locale_name (LC_NUMERIC, "LC_NUMERIC"), ASSERT (strcmp (gl_locale_name (LC_NUMERIC, "LC_NUMERIC"),
gl_locale_name_default ()) == 0); gl_locale_name_default ()) == 0);
/* Check that an empty environment variable is treated like an unset /* Check that an empty environment variable is treated like an unset
environment variable. */ environment variable. */
setenv ("LC_ALL", "", 1); setenv ("LC_ALL", "", 1);
unsetenv ("LC_CTYPE"); unsetenv ("LC_CTYPE");
skipping to change at line 183 skipping to change at line 202
setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1); setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1);
unsetenv ("LANG"); unsetenv ("LANG");
if (setlocale (LC_ALL, "") != NULL) if (setlocale (LC_ALL, "") != NULL)
{ {
name = gl_locale_name (LC_CTYPE, "LC_CTYPE"); name = gl_locale_name (LC_CTYPE, "LC_CTYPE");
ASSERT (strcmp (name, gl_locale_name_default ()) == 0); ASSERT (strcmp (name, gl_locale_name_default ()) == 0);
name = gl_locale_name (LC_MESSAGES, "LC_MESSAGES"); name = gl_locale_name (LC_MESSAGES, "LC_MESSAGES");
ASSERT (strcmp (name, "fr_FR.UTF-8") == 0); ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
} }
#if HAVE_NEWLOCALE && HAVE_USELOCALE #if HAVE_GOOD_USELOCALE
/* Check that gl_locale_name considers the thread locale. */ /* Check that gl_locale_name considers the thread locale. */
{ {
locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL); locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
if (locale != NULL) if (locale != NULL)
{ {
uselocale (locale); uselocale (locale);
name = gl_locale_name (LC_CTYPE, "LC_CTYPE"); name = gl_locale_name (LC_CTYPE, "LC_CTYPE");
ASSERT (strcmp (name, "fr_FR.UTF-8") == 0); ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
name = gl_locale_name (LC_MESSAGES, "LC_MESSAGES"); name = gl_locale_name (LC_MESSAGES, "LC_MESSAGES");
ASSERT (strcmp (name, "fr_FR.UTF-8") == 0); ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
skipping to change at line 243 skipping to change at line 262
#endif #endif
} }
/* Test the gl_locale_name_thread() function. */ /* Test the gl_locale_name_thread() function. */
static void static void
test_locale_name_thread (void) test_locale_name_thread (void)
{ {
/* Get into a defined state, */ /* Get into a defined state, */
setlocale (LC_ALL, "en_US.UTF-8"); setlocale (LC_ALL, "en_US.UTF-8");
#if HAVE_NEWLOCALE && HAVE_USELOCALE #if HAVE_GOOD_USELOCALE
/* Check that gl_locale_name_thread returns NULL when no thread locale is /* Check that gl_locale_name_thread returns NULL when no thread locale is
set. */ set. */
uselocale (LC_GLOBAL_LOCALE); uselocale (LC_GLOBAL_LOCALE);
ASSERT (gl_locale_name_thread (LC_CTYPE, "LC_CTYPE") == NULL); ASSERT (gl_locale_name_thread (LC_CTYPE, "LC_CTYPE") == NULL);
ASSERT (gl_locale_name_thread (LC_MESSAGES, "LC_MESSAGES") == NULL); ASSERT (gl_locale_name_thread (LC_MESSAGES, "LC_MESSAGES") == NULL);
/* Check that gl_locale_name_thread considers the thread locale. */ /* Check that gl_locale_name_thread considers the thread locale. */
{ {
locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL); locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
if (locale != NULL) if (locale != NULL)
skipping to change at line 494 skipping to change at line 513
/* Check that gl_locale_name_thread always returns NULL. */ /* Check that gl_locale_name_thread always returns NULL. */
ASSERT (gl_locale_name_thread (LC_CTYPE, "LC_CTYPE") == NULL); ASSERT (gl_locale_name_thread (LC_CTYPE, "LC_CTYPE") == NULL);
ASSERT (gl_locale_name_thread (LC_MESSAGES, "LC_MESSAGES") == NULL); ASSERT (gl_locale_name_thread (LC_MESSAGES, "LC_MESSAGES") == NULL);
#endif #endif
} }
/* Test the gl_locale_name_posix() function. */ /* Test the gl_locale_name_posix() function. */
static void static void
test_locale_name_posix (void) test_locale_name_posix (void)
{ {
const char *ret;
const char *name; const char *name;
/* Get into a defined state, */ /* Get into a defined state, */
setlocale (LC_ALL, "en_US.UTF-8"); setlocale (LC_ALL, "en_US.UTF-8");
#if HAVE_NEWLOCALE && HAVE_USELOCALE #if HAVE_GOOD_USELOCALE
uselocale (LC_GLOBAL_LOCALE); uselocale (LC_GLOBAL_LOCALE);
#endif #endif
/* Check that when all environment variables are unset, /* Check that when all environment variables are unset,
gl_locale_name_posix returns either NULL or the default locale. */ gl_locale_name_posix returns either NULL or the default locale. */
unsetenv ("LC_ALL"); unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE"); unsetenv ("LC_CTYPE");
unsetenv ("LC_MESSAGES"); unsetenv ("LC_MESSAGES");
unsetenv ("LC_NUMERIC"); unsetenv ("LC_NUMERIC");
unsetenv ("LANG"); unsetenv ("LANG");
setlocale (LC_ALL, ""); /* Need also to unset all environment variables that specify standard or
non-standard locale categories. Otherwise, on glibc systems, when some
of these variables are set and reference a nonexistent locale, the
setlocale (LC_ALL, "") call below would fail. */
unsetenv ("LC_COLLATE");
unsetenv ("LC_MONETARY");
unsetenv ("LC_TIME");
unsetenv ("LC_ADDRESS");
unsetenv ("LC_IDENTIFICATION");
unsetenv ("LC_MEASUREMENT");
unsetenv ("LC_NAME");
unsetenv ("LC_PAPER");
unsetenv ("LC_TELEPHONE");
ret = setlocale (LC_ALL, "");
ASSERT (ret != NULL);
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"); name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0); ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0);
name = gl_locale_name_posix (LC_NUMERIC, "LC_NUMERIC"); name = gl_locale_name_posix (LC_NUMERIC, "LC_NUMERIC");
ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0); ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0);
/* Check that an empty environment variable is treated like an unset /* Check that an empty environment variable is treated like an unset
environment variable. */ environment variable. */
setenv ("LC_ALL", "", 1); setenv ("LC_ALL", "", 1);
unsetenv ("LC_CTYPE"); unsetenv ("LC_CTYPE");
skipping to change at line 607 skipping to change at line 641
setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1); setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1);
unsetenv ("LANG"); unsetenv ("LANG");
if (setlocale (LC_ALL, "") != NULL) if (setlocale (LC_ALL, "") != NULL)
{ {
name = gl_locale_name_posix (LC_CTYPE, "LC_CTYPE"); name = gl_locale_name_posix (LC_CTYPE, "LC_CTYPE");
ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0); ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0);
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"); name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
ASSERT (strcmp (name, "fr_FR.UTF-8") == 0); ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
} }
#if HAVE_NEWLOCALE && HAVE_USELOCALE #if HAVE_GOOD_USELOCALE
/* Check that gl_locale_name_posix ignores the thread locale. */ /* Check that gl_locale_name_posix ignores the thread locale. */
{ {
locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL); locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
if (locale != NULL) if (locale != NULL)
{ {
unsetenv ("LC_ALL"); unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE"); unsetenv ("LC_CTYPE");
unsetenv ("LC_MESSAGES"); unsetenv ("LC_MESSAGES");
setenv ("LANG", "C", 1); setenv ("LANG", "C", 1);
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
skipping to change at line 636 skipping to change at line 670
} }
/* Test the gl_locale_name_environ() function. */ /* Test the gl_locale_name_environ() function. */
static void static void
test_locale_name_environ (void) test_locale_name_environ (void)
{ {
const char *name; const char *name;
/* Get into a defined state, */ /* Get into a defined state, */
setlocale (LC_ALL, "en_US.UTF-8"); setlocale (LC_ALL, "en_US.UTF-8");
#if HAVE_NEWLOCALE && HAVE_USELOCALE #if HAVE_GOOD_USELOCALE
uselocale (LC_GLOBAL_LOCALE); uselocale (LC_GLOBAL_LOCALE);
#endif #endif
/* Check that when all environment variables are unset, /* Check that when all environment variables are unset,
gl_locale_name_environ returns NULL. */ gl_locale_name_environ returns NULL. */
unsetenv ("LC_ALL"); unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE"); unsetenv ("LC_CTYPE");
unsetenv ("LC_MESSAGES"); unsetenv ("LC_MESSAGES");
unsetenv ("LC_NUMERIC"); unsetenv ("LC_NUMERIC");
unsetenv ("LANG"); unsetenv ("LANG");
skipping to change at line 721 skipping to change at line 755
unsetenv ("LC_ALL"); unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE"); unsetenv ("LC_CTYPE");
setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1); setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1);
unsetenv ("LANG"); unsetenv ("LANG");
name = gl_locale_name_environ (LC_CTYPE, "LC_CTYPE"); name = gl_locale_name_environ (LC_CTYPE, "LC_CTYPE");
ASSERT (name == NULL); ASSERT (name == NULL);
name = gl_locale_name_environ (LC_MESSAGES, "LC_MESSAGES"); name = gl_locale_name_environ (LC_MESSAGES, "LC_MESSAGES");
ASSERT (strcmp (name, "fr_FR.UTF-8") == 0); ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
#if HAVE_NEWLOCALE && HAVE_USELOCALE #if HAVE_GOOD_USELOCALE
/* Check that gl_locale_name_environ ignores the thread locale. */ /* Check that gl_locale_name_environ ignores the thread locale. */
{ {
locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL); locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
if (locale != NULL) if (locale != NULL)
{ {
unsetenv ("LC_ALL"); unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE"); unsetenv ("LC_CTYPE");
unsetenv ("LC_MESSAGES"); unsetenv ("LC_MESSAGES");
setenv ("LANG", "C", 1); setenv ("LANG", "C", 1);
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
skipping to change at line 756 skipping to change at line 790
const char *name = gl_locale_name_default (); const char *name = gl_locale_name_default ();
ASSERT (name != NULL); ASSERT (name != NULL);
/* Only Mac OS X and Windows have a facility for the user to set the default /* Only Mac OS X and Windows have a facility for the user to set the default
locale. */ locale. */
#if !((defined __APPLE__ && defined __MACH__) || (defined _WIN32 || defined __CY GWIN__)) #if !((defined __APPLE__ && defined __MACH__) || (defined _WIN32 || defined __CY GWIN__))
ASSERT (strcmp (name, "C") == 0); ASSERT (strcmp (name, "C") == 0);
#endif #endif
#if HAVE_NEWLOCALE && HAVE_USELOCALE #if HAVE_GOOD_USELOCALE
/* Check that gl_locale_name_default ignores the thread locale. */ /* Check that gl_locale_name_default ignores the thread locale. */
{ {
locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL); locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
if (locale != NULL) if (locale != NULL)
{ {
uselocale (locale); uselocale (locale);
ASSERT (strcmp (gl_locale_name_default (), name) == 0); ASSERT (strcmp (gl_locale_name_default (), name) == 0);
uselocale (LC_GLOBAL_LOCALE); uselocale (LC_GLOBAL_LOCALE);
freelocale (locale); freelocale (locale);
} }
 End of changes. 13 change blocks. 
11 lines changed or deleted 45 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)