1 /* Test of gl_locale_name function.
2 Copyright (C) 2007, 2008 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"
28 #define ASSERT(expr) \
33 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
43 /* Check that gl_locale_name returns non-NULL. */
44 ASSERT (gl_locale_name (LC_MESSAGES, "LC_MESSAGES") != NULL);
46 /* Check that when all environment variables are unset,
47 gl_locale_name_posix returns NULL. */
49 unsetenv ("LC_CTYPE");
50 unsetenv ("LC_MESSAGES");
51 unsetenv ("LC_NUMERIC");
53 setlocale (LC_ALL, "");
54 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
55 gl_locale_name_default ()) == 0);
56 ASSERT (strcmp (gl_locale_name (LC_NUMERIC, "LC_NUMERIC"),
57 gl_locale_name_default ()) == 0);
59 /* Check that an empty environment variable is treated like an unset
60 environment variable. */
62 setenv ("LC_ALL", "", 1);
63 unsetenv ("LC_CTYPE");
64 unsetenv ("LC_MESSAGES");
66 setlocale (LC_ALL, "");
67 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
68 gl_locale_name_default ()) == 0);
71 setenv ("LC_CTYPE", "", 1);
72 unsetenv ("LC_MESSAGES");
74 setlocale (LC_ALL, "");
75 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
76 gl_locale_name_default ()) == 0);
79 unsetenv ("LC_CTYPE");
80 setenv ("LC_MESSAGES", "", 1);
82 setlocale (LC_ALL, "");
83 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
84 gl_locale_name_default ()) == 0);
87 unsetenv ("LC_CTYPE");
88 unsetenv ("LC_MESSAGES");
89 setenv ("LANG", "", 1);
90 setlocale (LC_ALL, "");
91 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
92 gl_locale_name_default ()) == 0);
94 /* Check that LC_ALL overrides the others, and LANG is overridden by the
97 setenv ("LC_ALL", "C", 1);
98 unsetenv ("LC_CTYPE");
99 unsetenv ("LC_MESSAGES");
101 setlocale (LC_ALL, "");
102 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
103 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
106 setenv ("LC_CTYPE", "C", 1);
107 setenv ("LC_MESSAGES", "C", 1);
109 setlocale (LC_ALL, "");
110 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
111 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
114 unsetenv ("LC_CTYPE");
115 unsetenv ("LC_MESSAGES");
116 setenv ("LANG", "C", 1);
117 setlocale (LC_ALL, "");
118 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
119 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);