1 /* Test program, used by the gettext-7 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 locale in ISO-8859-1 or ISO-8859-15 encoding. */
39 # define LOCALE_DE_ISO8859 "de_DE.ISO-8859-1"
40 #elif defined __APPLE__ && defined __MACH__ /* MacOS X */
41 # define LOCALE_DE_ISO8859 "de_DE.ISO8859-1"
43 # define LOCALE_DE_ISO8859 "de_DE"
46 /* Name of German locale in UTF-8 encoding. */
47 #define LOCALE_DE_UTF8 "de_DE.UTF-8"
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));
91 /* Here we expect output in ISO-8859-1. */
94 s = gettext ("cheese");
96 if (strcmp (s, "K\344se"))
98 fprintf (stderr, "thread 1 call 1 returned: %s\n", s);
104 s = gettext ("cheese");
106 if (strcmp (s, "K\344se"))
108 fprintf (stderr, "thread 1 call 2 returned: %s\n", s);
117 thread2_execution (void *arg)
122 uselocale (newlocale (LC_ALL_MASK, LOCALE_DE_UTF8, NULL));
125 /* Here we expect output in UTF-8. */
128 s = gettext ("cheese");
130 if (strcmp (s, "K\303\244se"))
132 fprintf (stderr, "thread 2 call 1 returned: %s\n", s);
138 s = gettext ("cheese");
140 if (strcmp (s, "K\303\244se"))
142 fprintf (stderr, "thread 2 call 2 returned: %s\n", s);
151 check_locale_exists (const char *name)
153 if (newlocale (LC_ALL_MASK, name, NULL) == NULL)
155 printf ("%s\n", name);
161 main (int argc, char *argv[])
167 arg = (argc > 1 ? atoi (argv[1]) : 0);
171 /* Check for the existence of the first locale. */
172 check_locale_exists (LOCALE_DE_ISO8859);
173 /* Check for the existence of the second locale. */
174 check_locale_exists (LOCALE_DE_UTF8);
180 unsetenv ("LANGUAGE");
181 unsetenv ("OUTPUT_CHARSET");
182 textdomain ("tstthread");
183 bindtextdomain ("tstthread", "gt-7");
187 if (pthread_mutex_init (&lock, NULL))
189 if (pthread_cond_init (&waitqueue, NULL))
191 if (pthread_create (&thread1, NULL, &thread1_execution, NULL))
193 if (pthread_create (&thread2, NULL, &thread2_execution, NULL))
195 if (pthread_join (thread2, NULL))
203 /* This test is not executed. */