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 2, or (at your option)
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, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
22 #include "localename.h"
31 #define ASSERT(expr) \
36 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
45 /* Check that gl_locale_name returns non-NULL. */
46 ASSERT (gl_locale_name (LC_MESSAGES, "LC_MESSAGES") != NULL);
48 /* Check that when all environment variables are unset,
49 gl_locale_name_posix returns NULL. */
51 unsetenv ("LC_CTYPE");
52 unsetenv ("LC_MESSAGES");
53 unsetenv ("LC_NUMERIC");
55 setlocale (LC_ALL, "");
56 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
57 gl_locale_name_default ()) == 0);
58 ASSERT (strcmp (gl_locale_name (LC_NUMERIC, "LC_NUMERIC"),
59 gl_locale_name_default ()) == 0);
61 /* Check that an empty environment variable is treated like an unset
62 environment variable. */
64 setenv ("LC_ALL", "", 1);
65 unsetenv ("LC_CTYPE");
66 unsetenv ("LC_MESSAGES");
68 setlocale (LC_ALL, "");
69 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
70 gl_locale_name_default ()) == 0);
73 setenv ("LC_CTYPE", "", 1);
74 unsetenv ("LC_MESSAGES");
76 setlocale (LC_ALL, "");
77 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
78 gl_locale_name_default ()) == 0);
81 unsetenv ("LC_CTYPE");
82 setenv ("LC_MESSAGES", "", 1);
84 setlocale (LC_ALL, "");
85 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
86 gl_locale_name_default ()) == 0);
89 unsetenv ("LC_CTYPE");
90 unsetenv ("LC_MESSAGES");
91 setenv ("LANG", "", 1);
92 setlocale (LC_ALL, "");
93 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
94 gl_locale_name_default ()) == 0);
96 /* Check that LC_ALL overrides the others, and LANG is overridden by the
99 setenv ("LC_ALL", "C", 1);
100 unsetenv ("LC_CTYPE");
101 unsetenv ("LC_MESSAGES");
103 setlocale (LC_ALL, "");
104 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
105 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
108 setenv ("LC_CTYPE", "C", 1);
109 setenv ("LC_MESSAGES", "C", 1);
111 setlocale (LC_ALL, "");
112 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
113 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
116 unsetenv ("LC_CTYPE");
117 unsetenv ("LC_MESSAGES");
118 setenv ("LANG", "C", 1);
119 setlocale (LC_ALL, "");
120 ASSERT (strcmp (gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);
121 ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), "C") == 0);