1 /* Test program, used by the gettext-7 test.
2 Copyright (C) 2005-2007, 2009-2010 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 __UCLIBC__) || (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 locale in ISO-8859-1 or ISO-8859-15 encoding. */
38 # define LOCALE_DE_ISO8859 "de_DE.ISO-8859-1"
39 #elif defined __APPLE__ && defined __MACH__ /* MacOS X */
40 # define LOCALE_DE_ISO8859 "de_DE.ISO8859-1"
42 # define LOCALE_DE_ISO8859 "de_DE"
45 /* Name of German locale in UTF-8 encoding. */
46 #define LOCALE_DE_UTF8 "de_DE.UTF-8"
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));
90 /* Here we expect output in ISO-8859-1. */
93 s = gettext ("cheese");
95 if (strcmp (s, "K\344se"))
97 fprintf (stderr, "thread 1 call 1 returned: %s\n", s);
103 s = gettext ("cheese");
105 if (strcmp (s, "K\344se"))
107 fprintf (stderr, "thread 1 call 2 returned: %s\n", s);
116 thread2_execution (void *arg)
121 uselocale (newlocale (LC_ALL_MASK, LOCALE_DE_UTF8, NULL));
124 /* Here we expect output in UTF-8. */
127 s = gettext ("cheese");
129 if (strcmp (s, "K\303\244se"))
131 fprintf (stderr, "thread 2 call 1 returned: %s\n", s);
137 s = gettext ("cheese");
139 if (strcmp (s, "K\303\244se"))
141 fprintf (stderr, "thread 2 call 2 returned: %s\n", s);
150 check_locale_exists (const char *name)
152 if (newlocale (LC_ALL_MASK, name, NULL) == NULL)
154 printf ("%s\n", name);
160 main (int argc, char *argv[])
166 arg = (argc > 1 ? atoi (argv[1]) : 0);
170 /* Check for the existence of the first locale. */
171 check_locale_exists (LOCALE_DE_ISO8859);
172 /* Check for the existence of the second locale. */
173 check_locale_exists (LOCALE_DE_UTF8);
179 unsetenv ("LANGUAGE");
180 unsetenv ("OUTPUT_CHARSET");
181 textdomain ("tstthread");
182 bindtextdomain ("tstthread", "gt-7");
186 if (pthread_mutex_init (&lock, NULL))
188 if (pthread_cond_init (&waitqueue, NULL))
190 if (pthread_create (&thread1, NULL, &thread1_execution, NULL))
192 if (pthread_create (&thread2, NULL, &thread2_execution, NULL))
194 if (pthread_join (thread2, NULL))
202 /* This test is not executed. */