1 /* Test program, used by the gettext-6 test.
2 Copyright (C) 2005-2007, 2009-2010, 2015 Free Software Foundation,
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Written by Bruno Haible <haible@clisp.cons.org>, 2005. */
29 #if USE_POSIX_THREADS && ((__GLIBC__ >= 2 && !defined __UCLIBC__) || (defined __APPLE__ && defined __MACH__)) && HAVE_USELOCALE
33 /* Make sure we use the included libintl, not the system's one. */
35 #include "libgnuintl.h"
37 /* Name of German and French locale in ISO-8859-1 or ISO-8859-15 encoding. */
39 # define LOCALE_DE_ISO8859 "de_DE.ISO-8859-1"
40 # define LOCALE_FR_ISO8859 "fr_FR.ISO-8859-1"
41 #elif defined __APPLE__ && defined __MACH__ /* MacOS X */
42 # define LOCALE_DE_ISO8859 "de_DE.ISO8859-1"
43 # define LOCALE_FR_ISO8859 "fr_FR.ISO8859-1"
45 # define LOCALE_DE_ISO8859 "de_DE"
46 # define LOCALE_FR_ISO8859 "fr_FR"
49 /* Set to 1 if the program is not behaving correctly. */
52 /* Denotes which thread should run next. */
54 /* Lock and wait queue used to switch between the threads. */
56 pthread_cond_t waitqueue;
58 /* Waits until the flipflop has a given value.
59 Before the call, the lock is unlocked. After the call, it is locked. */
63 if (pthread_mutex_lock (&lock))
65 while (flipflop != value)
66 if (pthread_cond_wait (&waitqueue, &lock))
70 /* Sets the flipflop to a given value.
71 Before the call, the lock is locked. After the call, it is unlocked. */
76 if (pthread_cond_signal (&waitqueue))
78 if (pthread_mutex_unlock (&lock))
83 thread1_execution (void *arg)
88 uselocale (newlocale (LC_ALL_MASK, LOCALE_DE_ISO8859, NULL));
92 s = gettext ("beauty");
94 if (strcmp (s, "Sch\366nheit"))
96 fprintf (stderr, "thread 1 call 1 returned: %s\n", s);
102 s = gettext ("beauty");
104 if (strcmp (s, "Sch\366nheit"))
106 fprintf (stderr, "thread 1 call 2 returned: %s\n", s);
115 thread2_execution (void *arg)
120 uselocale (newlocale (LC_ALL_MASK, LOCALE_FR_ISO8859, NULL));
124 s = gettext ("beauty");
126 if (strcmp (s, "beaut\351"))
128 fprintf (stderr, "thread 2 call 1 returned: %s\n", s);
134 s = gettext ("beauty");
136 if (strcmp (s, "beaut\351"))
138 fprintf (stderr, "thread 2 call 2 returned: %s\n", s);
147 check_locale_exists (const char *name)
149 if (newlocale (LC_ALL_MASK, name, NULL) == NULL)
151 printf ("%s\n", name);
157 main (int argc, char *argv[])
163 arg = (argc > 1 ? atoi (argv[1]) : 0);
167 /* Check for the existence of the first locale. */
168 check_locale_exists (LOCALE_DE_ISO8859);
169 /* Check for the existence of the second locale. */
170 check_locale_exists (LOCALE_FR_ISO8859);
176 unsetenv ("LANGUAGE");
177 unsetenv ("OUTPUT_CHARSET");
178 textdomain ("tstthread");
179 bindtextdomain ("tstthread", "gt-6");
183 if (pthread_mutex_init (&lock, NULL))
185 if (pthread_cond_init (&waitqueue, NULL))
187 if (pthread_create (&thread1, NULL, &thread1_execution, NULL))
189 if (pthread_create (&thread2, NULL, &thread2_execution, NULL))
191 if (pthread_join (thread2, NULL))
199 /* This test is not executed. */