1 /* Test of gl_locale_name function.
2 Copyright (C) 2007 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
21 #include "localename.h"
30 #define ASSERT(expr) \
35 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
44 /* Check that gl_locale_name returns non-NULL. */
45 ASSERT (gl_locale_name (LC_MESSAGES, "LC_MESSAGES") != NULL);
47 /* Check that when all environment variables are unset,
48 gl_locale_name_posix returns NULL. */
50 unsetenv ("LC_CTYPE");
51 unsetenv ("LC_MESSAGES");
52 unsetenv ("LC_NUMERIC");
54 setlocale (LC_ALL, "");
55 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
56 gl_locale_name_default ()) == 0);
57 ASSERT (strcmp (gl_locale_name (LC_NUMERIC, "LC_NUMERIC"),
58 gl_locale_name_default ()) == 0);
60 /* Check that an empty environment variable is treated like an unset
61 environment variable. */
63 setenv ("LC_ALL", "", 1);
64 unsetenv ("LC_CTYPE");
65 unsetenv ("LC_MESSAGES");
67 setlocale (LC_ALL, "");
68 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
69 gl_locale_name_default ()) == 0);
72 setenv ("LC_CTYPE", "", 1);
73 unsetenv ("LC_MESSAGES");
75 setlocale (LC_ALL, "");
76 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
77 gl_locale_name_default ()) == 0);
80 unsetenv ("LC_CTYPE");
81 setenv ("LC_MESSAGES", "", 1);
83 setlocale (LC_ALL, "");
84 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
85 gl_locale_name_default ()) == 0);
88 unsetenv ("LC_CTYPE");
89 unsetenv ("LC_MESSAGES");
90 setenv ("LANG", "", 1);
91 setlocale (LC_ALL, "");
92 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
93 gl_locale_name_default ()) == 0);
95 /* Check that LC_ALL overrides the others, and LANG is overridden by the
98 setenv ("LC_ALL", "C", 1);
99 unsetenv ("LC_CTYPE");
100 unsetenv ("LC_MESSAGES");
102 setlocale (LC_ALL, "");
103 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
104 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
107 setenv ("LC_CTYPE", "C", 1);
108 setenv ("LC_MESSAGES", "C", 1);
110 setlocale (LC_ALL, "");
111 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
112 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
115 unsetenv ("LC_CTYPE");
116 unsetenv ("LC_MESSAGES");
117 setenv ("LANG", "C", 1);
118 setlocale (LC_ALL, "");
119 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
120 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);