summaryrefslogtreecommitdiff
path: root/tests/test-localename.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2024-03-03 19:11:32 +0100
committerJörg Frings-Fürst <debian@jff.email>2024-03-03 19:11:32 +0100
commit00893e79fc62966067af1a106567db96bd170338 (patch)
tree52b35cd0b42ca28e62a2ffbecade2e13dd8332cf /tests/test-localename.c
parent26112352a774737e1ce5580c93654a26c1e82b39 (diff)
New upstream version 1.2upstream/1.2
Diffstat (limited to 'tests/test-localename.c')
-rw-r--r--tests/test-localename.c82
1 files changed, 54 insertions, 28 deletions
diff --git a/tests/test-localename.c b/tests/test-localename.c
index 9ba388f3..03b70527 100644
--- a/tests/test-localename.c
+++ b/tests/test-localename.c
@@ -1,5 +1,5 @@
/* Test of gl_locale_name function and its variants.
- Copyright (C) 2007-2022 Free Software Foundation, Inc.
+ Copyright (C) 2007-2024 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
@@ -30,6 +30,35 @@
# define HAVE_GOOD_USELOCALE 1
#endif
+#ifdef __HAIKU__
+/* Work around Haiku bug <https://dev.haiku-os.org/ticket/18344>. */
+# define freelocale(loc) ((void) (loc))
+#endif
+
+/* Suppress GCC false positive. */
+#if __GNUC__ >= 12
+# pragma GCC diagnostic ignored "-Wanalyzer-use-of-uninitialized-value"
+#endif
+
+/* The name that setlocale(,NULL) returns for the "C" locale. */
+#ifdef __HAIKU__
+# define C_CANONICALIZED "POSIX"
+#else
+# define C_CANONICALIZED "C"
+#endif
+
+static int
+is_default (const char *name)
+{
+ return strcmp (name, gl_locale_name_default ()) == 0
+ || (strcmp (name, C_CANONICALIZED) == 0
+ && strcmp (gl_locale_name_default (), "C") == 0)
+#if MUSL_LIBC
+ || (strcmp (name, "C.UTF-8") == 0
+ && strcmp (gl_locale_name_default (), "C") == 0)
+#endif
+ ;
+}
#if HAVE_GOOD_USELOCALE
@@ -101,10 +130,8 @@ test_locale_name (void)
unsetenv ("LC_TELEPHONE");
ret = setlocale (LC_ALL, "");
ASSERT (ret != NULL);
- ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
- gl_locale_name_default ()) == 0);
- ASSERT (strcmp (gl_locale_name (LC_NUMERIC, "LC_NUMERIC"),
- gl_locale_name_default ()) == 0);
+ ASSERT (is_default (gl_locale_name (LC_MESSAGES, "LC_MESSAGES")));
+ ASSERT (is_default (gl_locale_name (LC_NUMERIC, "LC_NUMERIC")));
/* Check that an empty environment variable is treated like an unset
environment variable. */
@@ -114,32 +141,28 @@ test_locale_name (void)
unsetenv ("LC_MESSAGES");
unsetenv ("LANG");
setlocale (LC_ALL, "");
- ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
- gl_locale_name_default ()) == 0);
+ ASSERT (is_default (gl_locale_name (LC_MESSAGES, "LC_MESSAGES")));
unsetenv ("LC_ALL");
setenv ("LC_CTYPE", "", 1);
unsetenv ("LC_MESSAGES");
unsetenv ("LANG");
setlocale (LC_ALL, "");
- ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
- gl_locale_name_default ()) == 0);
+ ASSERT (is_default (gl_locale_name (LC_MESSAGES, "LC_MESSAGES")));
unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE");
setenv ("LC_MESSAGES", "", 1);
unsetenv ("LANG");
setlocale (LC_ALL, "");
- ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
- gl_locale_name_default ()) == 0);
+ ASSERT (is_default (gl_locale_name (LC_MESSAGES, "LC_MESSAGES")));
unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE");
unsetenv ("LC_MESSAGES");
setenv ("LANG", "", 1);
setlocale (LC_ALL, "");
- ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
- gl_locale_name_default ()) == 0);
+ ASSERT (is_default (gl_locale_name (LC_MESSAGES, "LC_MESSAGES")));
/* Check that LC_ALL overrides the others, and LANG is overridden by the
others. */
@@ -149,21 +172,24 @@ test_locale_name (void)
unsetenv ("LC_MESSAGES");
unsetenv ("LANG");
setlocale (LC_ALL, "");
- ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
+ ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
+ C_CANONICALIZED) == 0);
unsetenv ("LC_ALL");
setenv ("LC_CTYPE", "C", 1);
setenv ("LC_MESSAGES", "C", 1);
unsetenv ("LANG");
setlocale (LC_ALL, "");
- ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
+ ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
+ C_CANONICALIZED) == 0);
unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE");
unsetenv ("LC_MESSAGES");
setenv ("LANG", "C", 1);
setlocale (LC_ALL, "");
- ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
+ ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
+ C_CANONICALIZED) == 0);
/* Check mixed situations. */
@@ -195,7 +221,7 @@ test_locale_name (void)
if (setlocale (LC_ALL, "") != NULL)
{
name = gl_locale_name (LC_CTYPE, "LC_CTYPE");
- ASSERT (strcmp (name, gl_locale_name_default ()) == 0);
+ ASSERT (is_default (name));
name = gl_locale_name (LC_MESSAGES, "LC_MESSAGES");
ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
}
@@ -543,9 +569,9 @@ test_locale_name_posix (void)
ret = setlocale (LC_ALL, "");
ASSERT (ret != NULL);
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
- ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0);
+ ASSERT (name == NULL || is_default (name));
name = gl_locale_name_posix (LC_NUMERIC, "LC_NUMERIC");
- ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0);
+ ASSERT (name == NULL || is_default (name));
/* Check that an empty environment variable is treated like an unset
environment variable. */
@@ -556,7 +582,7 @@ test_locale_name_posix (void)
unsetenv ("LANG");
setlocale (LC_ALL, "");
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
- ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0);
+ ASSERT (name == NULL || is_default (name));
unsetenv ("LC_ALL");
setenv ("LC_CTYPE", "", 1);
@@ -564,7 +590,7 @@ test_locale_name_posix (void)
unsetenv ("LANG");
setlocale (LC_ALL, "");
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
- ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0);
+ ASSERT (name == NULL || is_default (name));
unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE");
@@ -572,7 +598,7 @@ test_locale_name_posix (void)
unsetenv ("LANG");
setlocale (LC_ALL, "");
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
- ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0);
+ ASSERT (name == NULL || is_default (name));
unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE");
@@ -580,7 +606,7 @@ test_locale_name_posix (void)
setenv ("LANG", "", 1);
setlocale (LC_ALL, "");
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
- ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0);
+ ASSERT (name == NULL || is_default (name));
/* Check that LC_ALL overrides the others, and LANG is overridden by the
others. */
@@ -591,7 +617,7 @@ test_locale_name_posix (void)
unsetenv ("LANG");
setlocale (LC_ALL, "");
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
- ASSERT (strcmp (name, "C") == 0);
+ ASSERT (strcmp (name, C_CANONICALIZED) == 0);
unsetenv ("LC_ALL");
setenv ("LC_CTYPE", "C", 1);
@@ -599,7 +625,7 @@ test_locale_name_posix (void)
unsetenv ("LANG");
setlocale (LC_ALL, "");
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
- ASSERT (strcmp (name, "C") == 0);
+ ASSERT (strcmp (name, C_CANONICALIZED) == 0);
unsetenv ("LC_ALL");
unsetenv ("LC_CTYPE");
@@ -607,7 +633,7 @@ test_locale_name_posix (void)
setenv ("LANG", "C", 1);
setlocale (LC_ALL, "");
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
- ASSERT (strcmp (name, "C") == 0);
+ ASSERT (strcmp (name, C_CANONICALIZED) == 0);
/* Check mixed situations. */
@@ -634,7 +660,7 @@ test_locale_name_posix (void)
if (setlocale (LC_ALL, "") != NULL)
{
name = gl_locale_name_posix (LC_CTYPE, "LC_CTYPE");
- ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0);
+ ASSERT (name == NULL || is_default (name));
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
}
@@ -652,7 +678,7 @@ test_locale_name_posix (void)
setlocale (LC_ALL, "");
uselocale (locale);
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
- ASSERT (strcmp (name, "C") == 0);
+ ASSERT (strcmp (name, C_CANONICALIZED) == 0);
uselocale (LC_GLOBAL_LOCALE);
freelocale (locale);
}