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__); \
42 /* Check that gl_locale_name returns non-NULL. */
43 ASSERT (gl_locale_name (LC_MESSAGES, "LC_MESSAGES") != NULL);
45 /* Check that when all environment variables are unset,
46 gl_locale_name_posix returns NULL. */
48 unsetenv ("LC_CTYPE");
49 unsetenv ("LC_MESSAGES");
50 unsetenv ("LC_NUMERIC");
52 setlocale (LC_ALL, "");
53 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
54 gl_locale_name_default ()) == 0);
55 ASSERT (strcmp (gl_locale_name (LC_NUMERIC, "LC_NUMERIC"),
56 gl_locale_name_default ()) == 0);
58 /* Check that an empty environment variable is treated like an unset
59 environment variable. */
61 setenv ("LC_ALL", "", 1);
62 unsetenv ("LC_CTYPE");
63 unsetenv ("LC_MESSAGES");
65 setlocale (LC_ALL, "");
66 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
67 gl_locale_name_default ()) == 0);
70 setenv ("LC_CTYPE", "", 1);
71 unsetenv ("LC_MESSAGES");
73 setlocale (LC_ALL, "");
74 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
75 gl_locale_name_default ()) == 0);
78 unsetenv ("LC_CTYPE");
79 setenv ("LC_MESSAGES", "", 1);
81 setlocale (LC_ALL, "");
82 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
83 gl_locale_name_default ()) == 0);
86 unsetenv ("LC_CTYPE");
87 unsetenv ("LC_MESSAGES");
88 setenv ("LANG", "", 1);
89 setlocale (LC_ALL, "");
90 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
91 gl_locale_name_default ()) == 0);
93 /* Check that LC_ALL overrides the others, and LANG is overridden by the
96 setenv ("LC_ALL", "C", 1);
97 unsetenv ("LC_CTYPE");
98 unsetenv ("LC_MESSAGES");
100 setlocale (LC_ALL, "");
101 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
102 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
105 setenv ("LC_CTYPE", "C", 1);
106 setenv ("LC_MESSAGES", "C", 1);
108 setlocale (LC_ALL, "");
109 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
110 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
113 unsetenv ("LC_CTYPE");
114 unsetenv ("LC_MESSAGES");
115 setenv ("LANG", "C", 1);
116 setlocale (LC_ALL, "");
117 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
118 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);