1 /* Test that gettext() in multithreaded applications works correctly if
2 different threads operate in different locales referring to the same
3 catalog file but with different encodings.
4 Copyright (C) 2005 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
6 Contributed by Bruno Haible <bruno@clisp.org>, 2005.
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, write to the Free
20 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
30 /* Set to 1 if the program is not behaving correctly. */
33 /* Denotes which thread should run next. */
35 /* Lock and wait queue used to switch between the threads. */
37 pthread_cond_t waitqueue
;
39 /* Waits until the flipflop has a given value.
40 Before the call, the lock is unlocked. After the call, it is locked. */
44 if (pthread_mutex_lock (&lock
))
46 while (flipflop
!= value
)
47 if (pthread_cond_wait (&waitqueue
, &lock
))
51 /* Sets the flipflop to a given value.
52 Before the call, the lock is locked. After the call, it is unlocked. */
57 if (pthread_cond_signal (&waitqueue
))
59 if (pthread_mutex_unlock (&lock
))
64 thread1_execution (void *arg
)
69 uselocale (newlocale (LC_ALL_MASK
, "de_DE.ISO-8859-1", NULL
));
72 /* Here we expect output in ISO-8859-1. */
75 s
= gettext ("cheese");
77 if (strcmp (s
, "K\344se"))
79 fprintf (stderr
, "thread 1 call 1 returned: %s\n", s
);
85 s
= gettext ("cheese");
87 if (strcmp (s
, "K\344se"))
89 fprintf (stderr
, "thread 1 call 2 returned: %s\n", s
);
98 thread2_execution (void *arg
)
103 uselocale (newlocale (LC_ALL_MASK
, "de_DE.UTF-8", NULL
));
106 /* Here we expect output in UTF-8. */
109 s
= gettext ("cheese");
111 if (strcmp (s
, "K\303\244se"))
113 fprintf (stderr
, "thread 2 call 1 returned: %s\n", s
);
119 s
= gettext ("cheese");
121 if (strcmp (s
, "K\303\244se"))
123 fprintf (stderr
, "thread 2 call 2 returned: %s\n", s
);
137 unsetenv ("LANGUAGE");
138 unsetenv ("OUTPUT_CHARSET");
139 textdomain ("codeset");
140 bindtextdomain ("codeset", OBJPFX
"domaindir");
144 if (pthread_mutex_init (&lock
, NULL
))
146 if (pthread_cond_init (&waitqueue
, NULL
))
148 if (pthread_create (&thread1
, NULL
, &thread1_execution
, NULL
))
150 if (pthread_create (&thread2
, NULL
, &thread2_execution
, NULL
))
152 if (pthread_join (thread2
, NULL
))