1 /* Test program, used by the gettext-6 test.
2 Copyright (C) 2005-2007, 2009 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 <haible@clisp.cons.org>, 2005. */
28 #if USE_POSIX_THREADS && (__GLIBC__ >= 2 || (defined __APPLE__ && defined __MACH__)) && HAVE_USELOCALE
32 /* Make sure we use the included libintl, not the system's one. */
34 #include "libgnuintl.h"
36 /* Name of German and French locale in ISO-8859-1 or ISO-8859-15 encoding. */
38 # define LOCALE_DE_ISO8859 "de_DE.ISO-8859-1"
39 # define LOCALE_FR_ISO8859 "fr_FR.ISO-8859-1"
40 #elif defined __APPLE__ && defined __MACH__ /* MacOS X */
41 # define LOCALE_DE_ISO8859 "de_DE.ISO8859-1"
42 # define LOCALE_FR_ISO8859 "fr_FR.ISO8859-1"
44 # define LOCALE_DE_ISO8859 "de_DE"
45 # define LOCALE_FR_ISO8859 "fr_FR"
48 /* Set to 1 if the program is not behaving correctly. */
51 /* Denotes which thread should run next. */
53 /* Lock and wait queue used to switch between the threads. */
55 pthread_cond_t waitqueue;
57 /* Waits until the flipflop has a given value.
58 Before the call, the lock is unlocked. After the call, it is locked. */
62 if (pthread_mutex_lock (&lock))
64 while (flipflop != value)
65 if (pthread_cond_wait (&waitqueue, &lock))
69 /* Sets the flipflop to a given value.
70 Before the call, the lock is locked. After the call, it is unlocked. */
75 if (pthread_cond_signal (&waitqueue))
77 if (pthread_mutex_unlock (&lock))
82 thread1_execution (void *arg)
87 uselocale (newlocale (LC_ALL_MASK, LOCALE_DE_ISO8859, NULL));
91 s = gettext ("beauty");
93 if (strcmp (s, "Sch\366nheit"))
95 fprintf (stderr, "thread 1 call 1 returned: %s\n", s);
101 s = gettext ("beauty");
103 if (strcmp (s, "Sch\366nheit"))
105 fprintf (stderr, "thread 1 call 2 returned: %s\n", s);
114 thread2_execution (void *arg)
119 uselocale (newlocale (LC_ALL_MASK, LOCALE_FR_ISO8859, NULL));
123 s = gettext ("beauty");
125 if (strcmp (s, "beaut\351"))
127 fprintf (stderr, "thread 2 call 1 returned: %s\n", s);
133 s = gettext ("beauty");
135 if (strcmp (s, "beaut\351"))
137 fprintf (stderr, "thread 2 call 2 returned: %s\n", s);
146 check_locale_exists (const char *name)
148 if (newlocale (LC_ALL_MASK, name, NULL) == NULL)
150 printf ("%s\n", name);
156 main (int argc, char *argv[])
162 arg = (argc > 1 ? atoi (argv[1]) : 0);
166 /* Check for the existence of the first locale. */
167 check_locale_exists (LOCALE_DE_ISO8859);
168 /* Check for the existence of the second locale. */
169 check_locale_exists (LOCALE_FR_ISO8859);
175 unsetenv ("LANGUAGE");
176 unsetenv ("OUTPUT_CHARSET");
177 textdomain ("tstthread");
178 bindtextdomain ("tstthread", ".");
182 if (pthread_mutex_init (&lock, NULL))
184 if (pthread_cond_init (&waitqueue, NULL))
186 if (pthread_create (&thread1, NULL, &thread1_execution, NULL))
188 if (pthread_create (&thread2, NULL, &thread2_execution, NULL))
190 if (pthread_join (thread2, NULL))
198 /* This test is not executed. */