| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <config.h> |
| 20 |
|
| 21 |
#if USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS |
| 22 |
|
| 23 |
|
| 24 |
#include <langinfo.h> |
| 25 |
|
| 26 |
#include <locale.h> |
| 27 |
#include <stdio.h> |
| 28 |
#include <stdlib.h> |
| 29 |
#include <string.h> |
| 30 |
#include <time.h> |
| 31 |
|
| 32 |
#include "glthread/thread.h" |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
#if defined _WIN32 && !defined __CYGWIN__ |
| 38 |
# define ENGLISH "English_United States" |
| 39 |
# define FRENCH "French_France" |
| 40 |
# define GERMAN "German_Germany" |
| 41 |
# define ENCODING ".1252" |
| 42 |
#else |
| 43 |
# define ENGLISH "en_US" |
| 44 |
# define FRENCH "fr_FR" |
| 45 |
# define GERMAN "de_DE" |
| 46 |
# if defined __sgi |
| 47 |
# define ENCODING ".ISO8859-15" |
| 48 |
# elif defined __hpux |
| 49 |
# define ENCODING ".utf8" |
| 50 |
# else |
| 51 |
# define ENCODING ".UTF-8" |
| 52 |
# endif |
| 53 |
#endif |
| 54 |
|
| 55 |
static const char LOCALE1[] = ENGLISH ENCODING; |
| 56 |
static const char LOCALE2[] = FRENCH ENCODING; |
| 57 |
static const char LOCALE3[] = GERMAN ENCODING; |
| 58 |
|
| 59 |
static char *expected1; |
| 60 |
|
| 61 |
static void * |
| 62 |
thread1_func (void *arg) |
| 63 |
{ |
| 64 |
for (;;) |
| 65 |
{ |
| 66 |
const char *value = nl_langinfo (CODESET); |
| 67 |
if (strcmp (expected1, value) != 0) |
| 68 |
{ |
| 69 |
fprintf (stderr, "thread1 disturbed by threadN!\n"); fflush (stderr); |
| 70 |
abort (); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
return NULL; |
| 76 |
} |
| 77 |
|
| 78 |
static char *expected2; |
| 79 |
|
| 80 |
static void * |
| 81 |
thread2_func (void *arg) |
| 82 |
{ |
| 83 |
for (;;) |
| 84 |
{ |
| 85 |
const char *value = nl_langinfo (PM_STR); |
| 86 |
if (strcmp (expected2, value) != 0) |
| 87 |
{ |
| 88 |
fprintf (stderr, "thread2 disturbed by threadN!\n"); fflush (stderr); |
| 89 |
abort (); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
return NULL; |
| 95 |
} |
| 96 |
|
| 97 |
static char *expected3; |
| 98 |
|
| 99 |
static void * |
| 100 |
thread3_func (void *arg) |
| 101 |
{ |
| 102 |
for (;;) |
| 103 |
{ |
| 104 |
const char *value = nl_langinfo (DAY_2); |
| 105 |
if (strcmp (expected3, value) != 0) |
| 106 |
{ |
| 107 |
fprintf (stderr, "thread3 disturbed by threadN!\n"); fflush (stderr); |
| 108 |
abort (); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
return NULL; |
| 114 |
} |
| 115 |
|
| 116 |
static char *expected4; |
| 117 |
|
| 118 |
static void * |
| 119 |
thread4_func (void *arg) |
| 120 |
{ |
| 121 |
for (;;) |
| 122 |
{ |
| 123 |
const char *value = nl_langinfo (ALTMON_2); |
| 124 |
if (strcmp (expected4, value) != 0) |
| 125 |
{ |
| 126 |
fprintf (stderr, "thread4 disturbed by threadN!\n"); fflush (stderr); |
| 127 |
abort (); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
return NULL; |
| 133 |
} |
| 134 |
|
| 135 |
static char *expected5; |
| 136 |
|
| 137 |
static void * |
| 138 |
thread5_func (void *arg) |
| 139 |
{ |
| 140 |
for (;;) |
| 141 |
{ |
| 142 |
const char *value = nl_langinfo (CRNCYSTR); |
| 143 |
if (strcmp (expected5, value) != 0) |
| 144 |
{ |
| 145 |
fprintf (stderr, "thread5 disturbed by threadN!\n"); fflush (stderr); |
| 146 |
abort (); |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
return NULL; |
| 152 |
} |
| 153 |
|
| 154 |
static char *expected6; |
| 155 |
|
| 156 |
static void * |
| 157 |
thread6_func (void *arg) |
| 158 |
{ |
| 159 |
for (;;) |
| 160 |
{ |
| 161 |
const char *value = nl_langinfo (RADIXCHAR); |
| 162 |
if (strcmp (expected6, value) != 0) |
| 163 |
{ |
| 164 |
fprintf (stderr, "thread6 disturbed by threadN!\n"); fflush (stderr); |
| 165 |
abort (); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
return NULL; |
| 171 |
} |
| 172 |
|
| 173 |
static void * |
| 174 |
threadN_func (void *arg) |
| 175 |
{ |
| 176 |
for (;;) |
| 177 |
{ |
| 178 |
nl_langinfo (CODESET); |
| 179 |
nl_langinfo (AM_STR); |
| 180 |
nl_langinfo (PM_STR); |
| 181 |
nl_langinfo (DAY_2); |
| 182 |
nl_langinfo (DAY_5); |
| 183 |
nl_langinfo (ALTMON_2); |
| 184 |
nl_langinfo (ALTMON_9); |
| 185 |
nl_langinfo (CRNCYSTR); |
| 186 |
nl_langinfo (RADIXCHAR); |
| 187 |
nl_langinfo (THOUSEP); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
return NULL; |
| 192 |
} |
| 193 |
|
| 194 |
int |
| 195 |
main (int argc, char *argv[]) |
| 196 |
{ |
| 197 |
if (setlocale (LC_ALL, LOCALE1) == NULL) |
| 198 |
{ |
| 199 |
fprintf (stderr, "Skipping test: LOCALE1 not recognized\n"); |
| 200 |
return 77; |
| 201 |
} |
| 202 |
if (setlocale (LC_MONETARY, LOCALE2) == NULL) |
| 203 |
{ |
| 204 |
fprintf (stderr, "Skipping test: LOCALE2 not recognized\n"); |
| 205 |
return 77; |
| 206 |
} |
| 207 |
if (setlocale (LC_NUMERIC, LOCALE3) == NULL) |
| 208 |
{ |
| 209 |
fprintf (stderr, "Skipping test: LOCALE3 not recognized\n"); |
| 210 |
return 77; |
| 211 |
} |
| 212 |
|
| 213 |
expected1 = strdup (nl_langinfo (CODESET)); |
| 214 |
expected2 = strdup (nl_langinfo (PM_STR)); |
| 215 |
expected3 = strdup (nl_langinfo (DAY_2)); |
| 216 |
expected4 = strdup (nl_langinfo (ALTMON_2)); |
| 217 |
expected5 = strdup (nl_langinfo (CRNCYSTR)); |
| 218 |
expected6 = strdup (nl_langinfo (RADIXCHAR)); |
| 219 |
|
| 220 |
|
| 221 |
gl_thread_create (thread1_func, NULL); |
| 222 |
gl_thread_create (thread2_func, NULL); |
| 223 |
gl_thread_create (thread3_func, NULL); |
| 224 |
gl_thread_create (thread4_func, NULL); |
| 225 |
gl_thread_create (thread5_func, NULL); |
| 226 |
gl_thread_create (thread6_func, NULL); |
| 227 |
|
| 228 |
gl_thread_create (threadN_func, NULL); |
| 229 |
|
| 230 |
|
| 231 |
{ |
| 232 |
struct timespec duration; |
| 233 |
duration.tv_sec = (argc > 1 ? atoi (argv[1]) : 2); |
| 234 |
duration.tv_nsec = 0; |
| 235 |
|
| 236 |
nanosleep (&duration, NULL); |
| 237 |
} |
| 238 |
|
| 239 |
return 0; |
| 240 |
} |
| 241 |
|
| 242 |
#else |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
#include <stdio.h> |
| 247 |
|
| 248 |
int |
| 249 |
main () |
| 250 |
{ |
| 251 |
fputs ("Skipping test: multithreading not enabled\n", stderr); |
| 252 |
return 77; |
| 253 |
} |
| 254 |
|
| 255 |
#endif |