diff options
Diffstat (limited to 'src/regress/lib/libc')
| -rw-r--r-- | src/regress/lib/libc/locale/uselocale/uselocale.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/regress/lib/libc/locale/uselocale/uselocale.c b/src/regress/lib/libc/locale/uselocale/uselocale.c index 1688f07257..445bb64876 100644 --- a/src/regress/lib/libc/locale/uselocale/uselocale.c +++ b/src/regress/lib/libc/locale/uselocale/uselocale.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: uselocale.c,v 1.4 2017/08/16 13:23:56 schwarze Exp $ */ | 1 | /* $OpenBSD: uselocale.c,v 1.5 2017/08/16 13:52:50 schwarze Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> | 3 | * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> |
| 4 | * | 4 | * |
| @@ -264,6 +264,14 @@ child_func(void *arg) | |||
| 264 | TEST_ER(uselocale, EINVAL, _LOCALE_NONE, _LOCALE_BAD); | 264 | TEST_ER(uselocale, EINVAL, _LOCALE_NONE, _LOCALE_BAD); |
| 265 | TEST_R(MB_CUR_MAX, 1); | 265 | TEST_R(MB_CUR_MAX, 1); |
| 266 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); | 266 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); |
| 267 | TEST_R(nl_langinfo, "US-ASCII", CODESET); | ||
| 268 | TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); | ||
| 269 | TEST_R(iswalpha, 0, 0x00E9); | ||
| 270 | TEST_R(iswalpha_l, 1, 0x00E9, _LOCALE_UTF8); | ||
| 271 | TEST_R(towupper, 0x00E9, 0x00E9); | ||
| 272 | TEST_R(towupper_l, 0x00C9, 0x00E9, _LOCALE_UTF8); | ||
| 273 | TEST_R(wcscasecmp, *s1 - *s2, s1, s2); | ||
| 274 | TEST_R(wcscasecmp_l, 0, s1, s2, _LOCALE_UTF8); | ||
| 267 | 275 | ||
| 268 | /* Test switching the thread locale. */ | 276 | /* Test switching the thread locale. */ |
| 269 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_UTF8); | 277 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_UTF8); |
| @@ -375,6 +383,12 @@ child_func(void *arg) | |||
| 375 | errx(1, "child: main clobbered strerror_l"); | 383 | errx(1, "child: main clobbered strerror_l"); |
| 376 | free(selc); | 384 | free(selc); |
| 377 | 385 | ||
| 386 | /* Check that the C locale works even while all is set to UTF-8. */ | ||
| 387 | TEST_R(nl_langinfo_l, "US-ASCII", CODESET, _LOCALE_C); | ||
| 388 | TEST_R(iswalpha_l, 0, 0x00E9, _LOCALE_C); | ||
| 389 | TEST_R(towupper_l, 0x00E9, 0x00E9, _LOCALE_C); | ||
| 390 | TEST_R(wcscasecmp_l, *s1 - *s2, s1, s2, _LOCALE_C); | ||
| 391 | |||
| 378 | /* Test displaying the global locale while a local one is set. */ | 392 | /* Test displaying the global locale while a local one is set. */ |
| 379 | TEST_R(setlocale, "C/C.UTF-8/C/C/C/C", LC_ALL, NULL); | 393 | TEST_R(setlocale, "C/C.UTF-8/C/C/C/C", LC_ALL, NULL); |
| 380 | 394 | ||
| @@ -385,11 +399,27 @@ child_func(void *arg) | |||
| 385 | TEST_R(MB_CUR_MAX, 1); | 399 | TEST_R(MB_CUR_MAX, 1); |
| 386 | TEST_R(uselocale, _LOCALE_C, _LOCALE_NONE); | 400 | TEST_R(uselocale, _LOCALE_C, _LOCALE_NONE); |
| 387 | 401 | ||
| 402 | /* Check that UTF-8 works even with a C thread locale. */ | ||
| 403 | TEST_R(nl_langinfo, "US-ASCII", CODESET); | ||
| 404 | TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); | ||
| 405 | TEST_R(iswalpha, 0, 0x0153); | ||
| 406 | TEST_R(iswalpha_l, 1, 0x0153, _LOCALE_UTF8); | ||
| 407 | TEST_R(towupper, 0x0153, 0x0153); | ||
| 408 | TEST_R(towupper_l, 0x0152, 0x0153, _LOCALE_UTF8); | ||
| 409 | TEST_R(wcsncasecmp, *s3 - *s4, s3, s4, 2); | ||
| 410 | TEST_R(wcsncasecmp_l, 0, s3, s4, 2, _LOCALE_UTF8); | ||
| 411 | |||
| 388 | /* Test switching back to the global locale. */ | 412 | /* Test switching back to the global locale. */ |
| 389 | TEST_R(uselocale, _LOCALE_C, LC_GLOBAL_LOCALE); | 413 | TEST_R(uselocale, _LOCALE_C, LC_GLOBAL_LOCALE); |
| 390 | TEST_R(MB_CUR_MAX, 4); | 414 | TEST_R(MB_CUR_MAX, 4); |
| 391 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); | 415 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); |
| 392 | 416 | ||
| 417 | /* Check that the global locale takes effect even in a thread. */ | ||
| 418 | TEST_R(nl_langinfo, "UTF-8", CODESET); | ||
| 419 | TEST_R(iswalpha, 1, 0x0153); | ||
| 420 | TEST_R(towupper, 0x0152, 0x0153); | ||
| 421 | TEST_R(wcscasecmp, 0, s1, s2); | ||
| 422 | |||
| 393 | /* Hand control back to the main thread. */ | 423 | /* Hand control back to the main thread. */ |
| 394 | switch_thread(4, SWITCH_SIGNAL); | 424 | switch_thread(4, SWITCH_SIGNAL); |
| 395 | return NULL; | 425 | return NULL; |
| @@ -421,6 +451,11 @@ main(void) | |||
| 421 | TEST_R(setlocale, "C", LC_ALL, NULL); | 451 | TEST_R(setlocale, "C", LC_ALL, NULL); |
| 422 | TEST_R(MB_CUR_MAX, 1); | 452 | TEST_R(MB_CUR_MAX, 1); |
| 423 | 453 | ||
| 454 | /* Check that *_l(3) works without any locale installed. */ | ||
| 455 | TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); | ||
| 456 | TEST_R(iswalpha_l, 1, 0x00E9, _LOCALE_UTF8); | ||
| 457 | TEST_R(towupper_l, 0x00C9, 0x00E9, _LOCALE_UTF8); | ||
| 458 | |||
| 424 | /* Test setting the globale locale. */ | 459 | /* Test setting the globale locale. */ |
| 425 | TEST_R(setlocale, "C.UTF-8", LC_CTYPE, "C.UTF-8"); | 460 | TEST_R(setlocale, "C.UTF-8", LC_CTYPE, "C.UTF-8"); |
| 426 | TEST_R(MB_CUR_MAX, 4); | 461 | TEST_R(MB_CUR_MAX, 4); |
