From eb8dd9dca1228af0cd132f515509051ecfabf6f6 Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Mon, 14 Apr 2025 17:32:06 +0000 Subject: This commit was manufactured by cvs2git to create tag 'tb_20250414'. --- src/regress/lib/libc/locale/Makefile | 5 - src/regress/lib/libc/locale/check_isw/Makefile | 8 - src/regress/lib/libc/locale/check_isw/check_isw.c | 147 ------- src/regress/lib/libc/locale/mbrtowc/Makefile | 5 - src/regress/lib/libc/locale/mbrtowc/test_mbrtowc.c | 85 ---- src/regress/lib/libc/locale/setlocale/Makefile | 8 - src/regress/lib/libc/locale/setlocale/setlocale.c | 125 ------ src/regress/lib/libc/locale/uselocale/Makefile | 10 - src/regress/lib/libc/locale/uselocale/uselocale.c | 481 --------------------- src/regress/lib/libc/locale/wcrtomb/Makefile | 5 - src/regress/lib/libc/locale/wcrtomb/test_wcrtomb.c | 85 ---- 11 files changed, 964 deletions(-) delete mode 100644 src/regress/lib/libc/locale/Makefile delete mode 100644 src/regress/lib/libc/locale/check_isw/Makefile delete mode 100644 src/regress/lib/libc/locale/check_isw/check_isw.c delete mode 100644 src/regress/lib/libc/locale/mbrtowc/Makefile delete mode 100644 src/regress/lib/libc/locale/mbrtowc/test_mbrtowc.c delete mode 100644 src/regress/lib/libc/locale/setlocale/Makefile delete mode 100644 src/regress/lib/libc/locale/setlocale/setlocale.c delete mode 100644 src/regress/lib/libc/locale/uselocale/Makefile delete mode 100644 src/regress/lib/libc/locale/uselocale/uselocale.c delete mode 100644 src/regress/lib/libc/locale/wcrtomb/Makefile delete mode 100644 src/regress/lib/libc/locale/wcrtomb/test_wcrtomb.c (limited to 'src/regress/lib/libc/locale') diff --git a/src/regress/lib/libc/locale/Makefile b/src/regress/lib/libc/locale/Makefile deleted file mode 100644 index 550f176d4c..0000000000 --- a/src/regress/lib/libc/locale/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# $OpenBSD: Makefile,v 1.7 2020/01/13 15:35:57 bluhm Exp $ - -SUBDIR = check_isw mbrtowc setlocale uselocale wcrtomb - -.include diff --git a/src/regress/lib/libc/locale/check_isw/Makefile b/src/regress/lib/libc/locale/check_isw/Makefile deleted file mode 100644 index cd79d6cb7f..0000000000 --- a/src/regress/lib/libc/locale/check_isw/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ - -PROG = check_isw - -run-regress-${PROG}: ${PROG} - ./${PROG} >/dev/null - -.include diff --git a/src/regress/lib/libc/locale/check_isw/check_isw.c b/src/regress/lib/libc/locale/check_isw/check_isw.c deleted file mode 100644 index 718f387883..0000000000 --- a/src/regress/lib/libc/locale/check_isw/check_isw.c +++ /dev/null @@ -1,147 +0,0 @@ -/* $OpenBSD: check_isw.c,v 1.2 2017/07/27 15:08:37 bluhm Exp $ */ -/* - * Copyright (c) 2005 Marc Espie - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* This checks consistency of the isw* functions with the default - * functions. - */ - -#include -#include -#include -#include -#include - -int bad = 0; - -void -check_bool(int v1, int v2, char msg) -{ - if (!v1 != !v2) { - printf("%c", msg); - bad++; - } -} - -void -check_value(int v1, int v2, char msg) -{ - if (v1 != v2) { - printf("%c", msg); - bad++; - } -} - -void -test1() -{ - int i; - - for (i = 0; i < 256; i++) { - printf(" %02x: ", i); - check_bool(isalnum(i), iswalnum(i), '1'); - check_bool(isalpha(i), iswalpha(i), '2'); - check_bool(isblank(i), iswblank(i), '3'); - check_bool(iscntrl(i), iswcntrl(i), '4'); - check_bool(isdigit(i), iswdigit(i), '5'); - check_bool(isgraph(i), iswgraph(i), '6'); - check_bool(islower(i), iswlower(i), '6'); - check_bool(isprint(i), iswprint(i), '7'); - check_bool(ispunct(i), iswpunct(i), '8'); - check_bool(isspace(i), iswspace(i), '9'); - check_bool(isupper(i), iswupper(i), 'a'); - check_bool(isxdigit(i), iswxdigit(i), 'b'); - check_value(tolower(i), towlower(i), 'c'); - check_value(toupper(i), towupper(i), 'd'); - if (i % 8 == 7) - printf("\n"); - } - printf("\n"); -} - -void -test2() -{ - unsigned char *s; - unsigned char *buf; - int i, j; - size_t n; - wchar_t c, d; - mbstate_t state; - - s = malloc(256); - if (!s) { - bad++; - return; - } - buf = malloc(MB_CUR_MAX); - if (!buf) { - bad++; - free(s); - return; - } - for (i = 0; i < 256; i++) - s[i] = i+1; - - j = 0; - mbrtowc(NULL, NULL, 1, &state); - printf(" %02x: ", 0); - - while ((n = mbrtowc(&c, s+j, 256-j, &state)) == 1) { - printf(" %02x: ", s[j]); - check_bool(isalnum(s[j]), iswalnum(c), '1'); - check_bool(isalpha(s[j]), iswalpha(c), '2'); - check_bool(isblank(s[j]), iswblank(c), '3'); - check_bool(iscntrl(s[j]), iswcntrl(c), '4'); - check_bool(isdigit(s[j]), iswdigit(c), '5'); - check_bool(isgraph(s[j]), iswgraph(c), '6'); - check_bool(islower(s[j]), iswlower(c), '6'); - check_bool(isprint(s[j]), iswprint(c), '7'); - check_bool(ispunct(s[j]), iswpunct(c), '8'); - check_bool(isspace(s[j]), iswspace(c), '9'); - check_bool(isupper(s[j]), iswupper(c), 'a'); - check_bool(isxdigit(s[j]), iswxdigit(c), 'b'); - d = towlower(c); - if (wctomb(buf, d) == 1) { - check_value(tolower(s[j]), buf[0], 'c'); - } else { - bad++; - } - d = towupper(c); - if (wctomb(buf, d) == 1) { - check_value(toupper(s[j]), buf[0], 'c'); - } else { - bad++; - } - if (s[j] % 8 == 7) - printf("\n"); - j++; - } - if (n != 0 || j != 255) { - bad++; - } - free(s); - free(buf); -} - - -int -main() -{ - test1(); - test2(); - return bad !=0; -} diff --git a/src/regress/lib/libc/locale/mbrtowc/Makefile b/src/regress/lib/libc/locale/mbrtowc/Makefile deleted file mode 100644 index 5436383911..0000000000 --- a/src/regress/lib/libc/locale/mbrtowc/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ - -PROG = test_mbrtowc - -.include diff --git a/src/regress/lib/libc/locale/mbrtowc/test_mbrtowc.c b/src/regress/lib/libc/locale/mbrtowc/test_mbrtowc.c deleted file mode 100644 index 7455f68439..0000000000 --- a/src/regress/lib/libc/locale/mbrtowc/test_mbrtowc.c +++ /dev/null @@ -1,85 +0,0 @@ -/* $OpenBSD: test_mbrtowc.c,v 1.3 2020/03/09 09:29:10 dlg Exp $ */ -/* - * Copyright (c) 2016 Ingo Schwarze - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include - -static mbstate_t mbs; - -void -onetest(const char *name, const char *in, size_t insz, - int outerr, size_t outsz, wint_t out) -{ - wchar_t wc; - size_t sz; - - sz = mbrtowc(&wc, in, insz, &mbs); - if (errno != outerr) - err(1, "%zu %s(%zd)", MB_CUR_MAX, name, insz); - if (sz != outsz || (out != WEOF && wc != out)) - errx(1, "%zu %s(%zd) = (%zd, %d) != (%zd, %d)", - MB_CUR_MAX, name, insz, sz, wc, outsz, out); - if (mbsinit(&mbs) == (insz && outsz == (size_t)-2)) - errx(1, "%zu %s(%zd) mbsinit", MB_CUR_MAX, name, insz); - if (errno == 0 && outerr == 0) - return; - errno = 0; - memset(&mbs, 0, sizeof(mbs)); -} - -int -main(void) -{ - onetest("NUL", "", 0, 0, -2, WEOF); - onetest("NUL", "", 2, 0, 0, L'\0'); - onetest("BEL", "\a", 2, 0, 1, L'\a'); - onetest("A", "A", 2, 0, 1, L'A'); - onetest("DEL", "\177", 2, 0, 1, L'\177'); - onetest("CSI", "\233", 2, 0, 1, L'\233'); - - if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) - errx(1, "setlocale(UTF-8) failed"); - - onetest("NUL", "", 0, 0, -2, WEOF); - onetest("NUL", "", 8, 0, 0, L'\0'); - onetest("BEL", "\a", 8, 0, 1, L'\a'); - onetest("A", "A", 8, 0, 1, L'A'); - onetest("DEL", "\177", 8, 0, 1, L'\177'); - onetest("0x80", "\200", 8, EILSEQ, -1, WEOF); - onetest("0xc3", "\303", 1, 0, -2, WEOF); - onetest("U+00E9", "\251", 8, 0, 1, 0xe9); - onetest("0xec", "\354", 1, 0, -2, WEOF); - onetest("0xecbf", "\277", 1, 0, -2, WEOF); - onetest("U+CFFF", "\277", 8, 0, 1, 0xcfff); - - if (setlocale(LC_CTYPE, "POSIX") == NULL) - errx(1, "setlocale(POSIX) failed"); - - onetest("0xff", "\277", 2, 0, 1, L'\277'); - - if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) - errx(1, "second setlocale(UTF-8) failed"); - - onetest("U+13000", "\360\223\200\200", 8, 0, 4, 0x13000); - - return 0; -} diff --git a/src/regress/lib/libc/locale/setlocale/Makefile b/src/regress/lib/libc/locale/setlocale/Makefile deleted file mode 100644 index 966f7926e5..0000000000 --- a/src/regress/lib/libc/locale/setlocale/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ - -PROG = setlocale - -run-regress-${PROG}: ${PROG} - env -i LC_ALL=fr_FR.UTF-8 ./${PROG} - -.include diff --git a/src/regress/lib/libc/locale/setlocale/setlocale.c b/src/regress/lib/libc/locale/setlocale/setlocale.c deleted file mode 100644 index 82245df5c5..0000000000 --- a/src/regress/lib/libc/locale/setlocale/setlocale.c +++ /dev/null @@ -1,125 +0,0 @@ -/* $OpenBSD: setlocale.c,v 1.4 2018/03/29 16:34:25 schwarze Exp $ */ -/* - * Copyright (c) 2015 Sebastien Marie - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include - -/* - * test helpers for __LINE__ - */ -#define test_setlocale(_e, _c, _l) _test_setlocale(_e, _c, _l, __LINE__) -#define test_MB_CUR_MAX(_e) _test_MB_CUR_MAX(_e, __LINE__) -#define test_isalpha(_e, _c) _test_isalpha(_e, _c, __LINE__) - - -static void -_test_setlocale(char *expected, int category, char *locale, int line) -{ - char *result = setlocale(category, locale); - - if ((expected == NULL) || (result == NULL)) { - if (expected == result) - return; - - errx(1, "[%d] setlocale(%d, \"%s\")=\"%s\" [expected: \"%s\"]", - line, category, locale, result, expected); - } - - if (strcmp(expected, result) != 0) - errx(1, "[%d] setlocale(%d, \"%s\")=\"%s\" [expected: \"%s\"]", - line, category, locale, result, expected); -} - -static void -_test_MB_CUR_MAX(size_t expected, int line) -{ - if (MB_CUR_MAX != expected) - errx(1, "[%d] MB_CUR_MAX=%ld [expected %ld]", - line, MB_CUR_MAX, expected); -} - -static void -_test_isalpha(int expected, int c, int line) -{ - int result = isalpha(c); - if (!!result != expected) - errx(1, "[%d] isalpha(%d)=%d [expected %d]", - line, c, result, expected); -} - -int -main(int argc, char *argv[]) -{ - /* check initial state (should be "C") */ - test_setlocale("C", LC_ALL, NULL); /* check */ - test_MB_CUR_MAX(1); - test_isalpha(0, 0xe9); /* iso-8859-1 eacute */ - - /* load from env */ - /* NOTE: we don't support non-C locales for some categories */ - test_setlocale("fr_FR.UTF-8", LC_CTYPE, ""); /* set */ - test_setlocale("fr_FR.UTF-8", LC_MESSAGES, ""); /* set */ - test_MB_CUR_MAX(4); - test_isalpha(0, 0xe9); /* iso-8859-1 eacute */ - - test_setlocale("C", LC_MESSAGES, "C"); /* set */ - test_MB_CUR_MAX(4); - test_setlocale("C/fr_FR.UTF-8/C/C/C/C", LC_ALL, NULL); /* check */ - - test_setlocale("C", LC_CTYPE, "C"); /* set */ - test_MB_CUR_MAX(1); - test_setlocale("C", LC_ALL, NULL); /* check */ - - /* check for errors on checking */ - test_setlocale("C", LC_ALL, "C"); /* reset */ - test_setlocale(NULL, -1, NULL); - test_setlocale(NULL, _LC_LAST, NULL); - test_setlocale(NULL, _LC_LAST+0xff, NULL); - test_setlocale("C", LC_ALL, NULL); /* check */ - - /* check for errors on setting */ - test_setlocale(NULL, -1, ""); - test_setlocale(NULL, _LC_LAST, ""); - test_setlocale(NULL, _LC_LAST+0xff, ""); - test_setlocale("C", LC_ALL, NULL); /* check */ - - /* no codeset, fallback to ASCII */ - test_setlocale("C", LC_ALL, "C"); /* reset */ - test_setlocale("invalid", LC_CTYPE, "invalid"); /* set */ - test_setlocale("invalid", LC_CTYPE, NULL); - test_MB_CUR_MAX(1); - test_isalpha(0, 0xe9); /* iso-8859-1 eacute */ - - /* with codeset */ - test_setlocale("C", LC_ALL, "C"); /* reset */ - test_setlocale("invalid.UTF-8", LC_CTYPE, "invalid.UTF-8"); /* set */ - test_setlocale("invalid.UTF-8", LC_CTYPE, NULL); - test_setlocale("C/invalid.UTF-8/C/C/C/C", LC_ALL, NULL); - test_MB_CUR_MAX(4); - - /* with invalid codeset (is an error) */ - test_setlocale("C", LC_ALL, "C"); /* reset */ - test_setlocale(NULL, LC_CTYPE, "fr_FR.invalid"); /* set */ - test_setlocale("C", LC_CTYPE, NULL); - test_MB_CUR_MAX(1); - - return (EXIT_SUCCESS); -} diff --git a/src/regress/lib/libc/locale/uselocale/Makefile b/src/regress/lib/libc/locale/uselocale/Makefile deleted file mode 100644 index a10471bcf6..0000000000 --- a/src/regress/lib/libc/locale/uselocale/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# $OpenBSD: Makefile,v 1.3 2017/08/16 01:40:30 schwarze Exp $ - -PROG = uselocale -CFLAGS += -Wno-macro-redefined -Wno-int-to-pointer-cast -LDFLAGS += -pthread - -run-regress-${PROG}: ${PROG} - ./${PROG} - -.include diff --git a/src/regress/lib/libc/locale/uselocale/uselocale.c b/src/regress/lib/libc/locale/uselocale/uselocale.c deleted file mode 100644 index 4759eff46c..0000000000 --- a/src/regress/lib/libc/locale/uselocale/uselocale.c +++ /dev/null @@ -1,481 +0,0 @@ -/* $OpenBSD: uselocale.c,v 1.9 2024/02/05 06:48:04 anton Exp $ */ -/* - * Copyright (c) 2017, 2022 Ingo Schwarze - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Keep in sync with /usr/src/lib/libc/locale/rune.h. */ -#define _LOCALE_NONE (locale_t)0 -#define _LOCALE_C (locale_t)1 -#define _LOCALE_UTF8 (locale_t)2 -#define _LOCALE_BAD (locale_t)3 - -/* Options for switch_thread() below. */ -#define SWITCH_SIGNAL 1 /* Call pthread_cond_signal(3). */ -#define SWITCH_WAIT 2 /* Call pthread_cond_timedwait(3). */ - -/* Options for TESTFUNC(). */ -#define TOPT_ERR (1 << 0) - -/* - * Generate one test function for a specific interface. - * Fn = function name - * Ft = function return type - * FUNCPARA = function parameter list with types and names - * FUNCARGS = function argument list, names only, no types - * Af = format string to print the arguments - * Rf = format string to print the return value - * Op = options for the test function, see above - * line = source code line number in this test file - * ee = expected error number - * er = expected return value - * ar = actual return value - * errno = actual error number (global) - */ -#define TESTFUNC(Fn, Ft, Af, Rf, Op) \ -static void \ -_test_##Fn(int line, int ee, Ft er, FUNCPARA) \ -{ \ - Ft ar; \ - errno = 0; \ - ar = Fn(FUNCARGS); \ - if (ar != er) \ - errx(1, "[%d] %s(" Af ")=" Rf " [exp: " Rf "]", \ - line, #Fn, FUNCARGS, ar, er); \ - if (Op & TOPT_ERR && errno != ee) \ - errx(1, "[%d] %s(" Af ") errno=%d [exp: %d]", \ - line, #Fn, FUNCARGS, errno, ee); \ -} - -#define STRTESTFUNC(Fn, Af) \ -static void \ -_test_##Fn(int line, int ee, const char *er, FUNCPARA) \ -{ \ - const char *ar; \ - errno = 0; \ - ar = Fn(FUNCARGS); \ - if (er == NULL) \ - er = "NULL"; \ - if (ar == NULL) \ - ar = "NULL"; \ - if (strcmp((const char *)er, (const char *)ar) != 0) \ - errx(1, "[%d] %s(" Af ")=%s [exp: %s]", \ - line, #Fn, FUNCARGS, ar, er); \ -} - -/* - * Test functions for all tested interfaces. - */ -#define FUNCPARA int mask, const char *locname -#define FUNCARGS mask, locname, _LOCALE_NONE -TESTFUNC(newlocale, locale_t, "%d, %s, %p", "%p", TOPT_ERR) - -#define FUNCPARA locale_t locale -#define FUNCARGS locale -TESTFUNC(duplocale, locale_t, "%p", "%p", TOPT_ERR) -TESTFUNC(uselocale, locale_t, "%p", "%p", TOPT_ERR) - -#define FUNCPARA int category, char *locname -#define FUNCARGS category, locname -STRTESTFUNC(setlocale, "%d, %s") - -#define FUNCPARA nl_item item -#define FUNCARGS item -STRTESTFUNC(nl_langinfo, "%ld") - -#define FUNCPARA nl_item item, locale_t locale -#define FUNCARGS item, locale -STRTESTFUNC(nl_langinfo_l, "%ld, %p") - -#define FUNCPARA int c -#define FUNCARGS c -TESTFUNC(isalpha, int, "0x%.2x", "%d", 0) -TESTFUNC(tolower, int, "0x%.2x", "0x%.2x", 0) - -#define FUNCPARA int c, locale_t locale -#define FUNCARGS c, locale -TESTFUNC(isalpha_l, int, "0x%.2x, %p", "%d", 0) -TESTFUNC(tolower_l, int, "0x%.2x, %p", "0x%.2x", 0) - -#define FUNCPARA wint_t wc -#define FUNCARGS wc -TESTFUNC(iswalpha, int, "U+%.4X", "%d", 0) -TESTFUNC(towupper, wint_t, "U+%.4X", "U+%.4X", 0) - -#define FUNCPARA wint_t wc, locale_t locale -#define FUNCARGS wc, locale -TESTFUNC(iswalpha_l, int, "U+%.4X, %p", "%d", 0) -TESTFUNC(towupper_l, wint_t, "U+%.4X, %p", "U+%.4X", 0) - -#define FUNCPARA wint_t wc, wctype_t charclass -#define FUNCARGS wc, charclass -TESTFUNC(iswctype, int, "U+%.4X, %p", "%d", 0) - -#define FUNCPARA wint_t wc, wctype_t charclass, locale_t locale -#define FUNCARGS wc, charclass, locale -TESTFUNC(iswctype_l, int, "U+%.4X, %p, %p", "%d", 0) - -#define FUNCPARA wint_t wc, wctrans_t charmap -#define FUNCARGS wc, charmap -TESTFUNC(towctrans, wint_t, "U+%.4X, %p", "U+%.4X", 0) - -#define FUNCPARA wint_t wc, wctrans_t charmap, locale_t locale -#define FUNCARGS wc, charmap, locale -TESTFUNC(towctrans_l, wint_t, "U+%.4X, %p, %p", "U+%.4X", 0) - -#define FUNCPARA const wchar_t *s1, const wchar_t *s2 -#define FUNCARGS s1, s2 -TESTFUNC(wcscasecmp, int, "%ls, %ls", "%d", 0) - -#define FUNCPARA const wchar_t *s1, const wchar_t *s2, locale_t locale -#define FUNCARGS s1, s2, locale -TESTFUNC(wcscasecmp_l, int, "%ls, %ls, %p", "%d", 0) - -#define FUNCPARA const wchar_t *s1, const wchar_t *s2, size_t len -#define FUNCARGS s1, s2, len -TESTFUNC(wcsncasecmp, int, "%ls, %ls, %zu", "%d", 0) - -#define FUNCPARA const wchar_t *s1, const wchar_t *s2, size_t len, \ - locale_t locale -#define FUNCARGS s1, s2, len, locale -TESTFUNC(wcsncasecmp_l, int, "%ls, %ls, %zu, %p", "%d", 0) - -static void -_test_MB_CUR_MAX(int line, int ee, size_t ar) -{ - if (MB_CUR_MAX != ar) - errx(1, "[%d] MB_CUR_MAX=%zd [exp: %zd]", - line, MB_CUR_MAX, ar); -} - -/* - * Test macros: - * TEST_R(funcname, er, arguments) if you expect errno == 0. - * TEST_ER(funcname, ee, er, arguments) otherwise. - */ -#define TEST_R(Fn, ...) _test_##Fn(__LINE__, 0, __VA_ARGS__) -#define TEST_ER(Fn, ...) _test_##Fn(__LINE__, __VA_ARGS__) - -static pthread_mutex_t mtx; -static pthread_mutexattr_t mtxattr; -static pthread_cond_t cond; - -/* - * SWITCH_SIGNAL wakes the other thread. - * SWITCH_WAIT goes to sleep. - * Both can be combined. - * The step argument is used for error reporting only. - */ -static void -switch_thread(int step, int flags) -{ - struct timespec t; - int irc; - - if (flags & SWITCH_SIGNAL) { - if ((irc = pthread_cond_signal(&cond)) != 0) - errc(1, irc, "pthread_cond_signal(%d)", step); - } - if (flags & SWITCH_WAIT) { - if ((irc = pthread_mutex_trylock(&mtx)) != 0) - errc(1, irc, "pthread_mutex_trylock(%d)", step); - t.tv_sec = time(NULL) + 2; - t.tv_nsec = 0; - if ((irc = pthread_cond_timedwait(&cond, &mtx, &t)) != 0) - errc(1, irc, "pthread_cond_timedwait(%d)", step); - if ((irc = pthread_mutex_unlock(&mtx)) != 0) - errc(1, irc, "pthread_mutex_unlock(%d)", step); - } -} - -static void * -child_func(void *arg) -{ - const wchar_t s1[] = { 0x00C7, 0x00E0, 0x0000 }; - const wchar_t s2[] = { 0x00E7, 0x00C0, 0x0000 }; - const wchar_t s3[] = { 0x00C9, 0x0074, 0x00C9, 0x0000 }; - const wchar_t s4[] = { 0x00E9, 0x0054, 0x00CC, 0x0000 }; - wctype_t wctyg, wctyu, wctyc; - wctrans_t wctrg, wctru, wctrc; - char *sego, *segc, *selo, *selc; - - /* Test invalid newlocale(3) arguments. */ - TEST_ER(newlocale, EINVAL, _LOCALE_NONE, LC_CTYPE_MASK, NULL); - TEST_R(MB_CUR_MAX, 1); - TEST_ER(newlocale, EINVAL, _LOCALE_NONE, LC_ALL_MASK + 1, "C.UTF-8"); - TEST_R(MB_CUR_MAX, 1); - TEST_ER(newlocale, ENOENT, _LOCALE_NONE, LC_COLLATE_MASK, "C.INV"); - TEST_R(MB_CUR_MAX, 1); - setenv("LC_TIME", "C.INV", 1); - TEST_ER(newlocale, ENOENT, _LOCALE_NONE, LC_TIME_MASK, ""); - unsetenv("LC_TIME"); - TEST_R(MB_CUR_MAX, 1); - setenv("LC_CTYPE", "C.INV", 1); - TEST_ER(newlocale, ENOENT, _LOCALE_NONE, LC_CTYPE_MASK, ""); - TEST_R(MB_CUR_MAX, 1); - - /* Test duplocale(3). */ - TEST_ER(duplocale, EINVAL, _LOCALE_NONE, _LOCALE_UTF8); - TEST_R(duplocale, _LOCALE_C, _LOCALE_C); - TEST_R(duplocale, _LOCALE_C, LC_GLOBAL_LOCALE); - - /* Test premature UTF-8 uselocale(3). */ - TEST_ER(uselocale, EINVAL, _LOCALE_NONE, _LOCALE_UTF8); - TEST_R(MB_CUR_MAX, 1); - TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); - - /* Test UTF-8 initialization. */ - setenv("LC_CTYPE", "C.UTF-8", 1); - TEST_R(newlocale, _LOCALE_UTF8, LC_CTYPE_MASK, ""); - unsetenv("LC_CTYPE"); - TEST_R(MB_CUR_MAX, 1); - TEST_R(duplocale, _LOCALE_UTF8, _LOCALE_UTF8); - - /* Test invalid uselocale(3) argument. */ - TEST_ER(uselocale, EINVAL, _LOCALE_NONE, _LOCALE_BAD); - TEST_R(MB_CUR_MAX, 1); - TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); - TEST_R(nl_langinfo, "US-ASCII", CODESET); - TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); - TEST_R(iswalpha, 0, 0x00E9); - TEST_R(iswalpha_l, 1, 0x00E9, _LOCALE_UTF8); - TEST_R(towupper, 0x00E9, 0x00E9); - TEST_R(towupper_l, 0x00C9, 0x00E9, _LOCALE_UTF8); - TEST_R(wcscasecmp, *s1 - *s2, s1, s2); - TEST_R(wcscasecmp_l, 0, s1, s2, _LOCALE_UTF8); - - /* Test switching the thread locale. */ - TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_UTF8); - TEST_R(MB_CUR_MAX, 4); - TEST_R(uselocale, _LOCALE_UTF8, _LOCALE_NONE); - TEST_R(nl_langinfo, "UTF-8", CODESET); - TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); - TEST_R(nl_langinfo_l, "US-ASCII", CODESET, _LOCALE_C); - TEST_R(isalpha, _CTYPE_L, 0x65); /* e */ - TEST_R(isalpha_l, _CTYPE_L, 0x65, _LOCALE_UTF8); - TEST_R(isalpha_l, _CTYPE_L, 0x65, _LOCALE_C); - TEST_R(isalpha_l, _CTYPE_L, 0x65, _LOCALE_C); - TEST_R(isalpha, 0, 0x30); /* 0 */ - TEST_R(isalpha_l, 0, 0x30, _LOCALE_UTF8); - TEST_R(isalpha_l, 0, 0x30, _LOCALE_C); - TEST_R(tolower, 0x61, 0x41); /* A */ - TEST_R(tolower_l, 0x61, 0x41, _LOCALE_UTF8); - TEST_R(tolower_l, 0x61, 0x41, _LOCALE_C); - TEST_R(tolower, 0x40, 0x40); /* @ */ - TEST_R(tolower_l, 0x40, 0x40, _LOCALE_UTF8); - TEST_R(tolower_l, 0x40, 0x40, _LOCALE_C); - TEST_R(iswalpha, 1, 0x00E9); /* e accent aigu */ - TEST_R(iswalpha_l, 1, 0x00E9, _LOCALE_UTF8); - TEST_R(iswalpha_l, 0, 0x00E9, _LOCALE_C); - TEST_R(iswalpha, 1, 0x0153); /* ligature oe */ - TEST_R(iswalpha_l, 1, 0x0153, _LOCALE_UTF8); - TEST_R(iswalpha_l, 0, 0x0153, _LOCALE_C); - TEST_R(iswalpha, 0, 0x2200); /* for all */ - TEST_R(iswalpha_l, 0, 0x2200, _LOCALE_UTF8); - TEST_R(iswalpha_l, 0, 0x2200, _LOCALE_C); - TEST_R(towupper, 0x00C9, 0x00E9); - TEST_R(towupper_l, 0x00C9, 0x00E9, _LOCALE_UTF8); - TEST_R(towupper_l, 0x00E9, 0x00E9, _LOCALE_C); - TEST_R(towupper, 0x0152, 0x0153); - TEST_R(towupper_l, 0x0152, 0x0153, _LOCALE_UTF8); - TEST_R(towupper_l, 0x0153, 0x0153, _LOCALE_C); - TEST_R(towupper, 0x2205, 0x2205); - TEST_R(towupper_l, 0x2205, 0x2205, _LOCALE_UTF8); - TEST_R(towupper_l, 0x2205, 0x2205, _LOCALE_C); - wctyg = wctype("upper"); - if (wctyg == NULL) - errx(1, "wctype(upper) == NULL"); - wctyu = wctype_l("upper", _LOCALE_UTF8); - if (wctyu == NULL) - errx(1, "wctype_l(upper, UTF-8) == NULL"); - if (wctyg != wctyu) - errx(1, "wctype global != UTF-8"); - wctyc = wctype_l("upper", _LOCALE_C); - if (wctyc == NULL) - errx(1, "wctype_l(upper, C) == NULL"); - TEST_R(iswctype, 1, 0x00D0, wctyg); /* Eth */ - TEST_R(iswctype_l, 1, 0x00D0, wctyu, _LOCALE_UTF8); - TEST_R(iswctype_l, 0, 0x00D0, wctyc, _LOCALE_C); - TEST_R(iswctype, 1, 0x0393, wctyg); /* Gamma */ - TEST_R(iswctype_l, 1, 0x0393, wctyu, _LOCALE_UTF8); - TEST_R(iswctype_l, 0, 0x0393, wctyc, _LOCALE_C); - TEST_R(iswctype, 0, 0x2205, wctyg); /* empty set */ - TEST_R(iswctype_l, 0, 0x2205, wctyu, _LOCALE_UTF8); - TEST_R(iswctype_l, 0, 0x2205, wctyc, _LOCALE_C); - wctrg = wctrans("tolower"); - if (wctrg == NULL) - errx(1, "wctrans(tolower) == NULL"); - wctru = wctrans_l("tolower", _LOCALE_UTF8); - if (wctru == NULL) - errx(1, "wctrans(tolower, UTF-8) == NULL"); - if (wctrg != wctru) - errx(1, "wctrans global != UTF-8"); - wctrc = wctrans_l("tolower", _LOCALE_C); - if (wctrc == NULL) - errx(1, "wctrans(tolower, C) == NULL"); - TEST_R(towctrans, 0x00FE, 0x00DE, wctrg); /* Thorn */ - TEST_R(towctrans_l, 0x00FE, 0x00DE, wctru, _LOCALE_UTF8); - TEST_R(towctrans_l, 0x00DE, 0x00DE, wctrc, _LOCALE_C); - TEST_R(towctrans, 0x03C6, 0x03A6, wctrg); /* Phi */ - TEST_R(towctrans_l, 0x03C6, 0x03A6, wctru, _LOCALE_UTF8); - TEST_R(towctrans_l, 0x03A6, 0x03A6, wctrc, _LOCALE_C); - TEST_R(towctrans, 0x2207, 0x2207, wctrg); /* Nabla */ - TEST_R(towctrans_l, 0x2207, 0x2207, wctru, _LOCALE_UTF8); - TEST_R(towctrans_l, 0x2207, 0x2207, wctrc, _LOCALE_C); - TEST_R(wcscasecmp, 0, s1, s2); - TEST_R(wcscasecmp_l, 0, s1, s2, _LOCALE_UTF8); - TEST_R(wcscasecmp_l, *s1 - *s2, s1, s2, _LOCALE_C); - TEST_R(wcsncasecmp, 0, s3, s4, 2); - TEST_R(wcsncasecmp_l, 0, s3, s4, 2, _LOCALE_UTF8); - TEST_R(wcsncasecmp_l, *s3 - *s4, s3, s4, 2, _LOCALE_C); - - /* Test non-ctype newlocale(3). */ - TEST_R(newlocale, _LOCALE_C, LC_MESSAGES_MASK, "en_US.UTF-8"); - - /* Test strerror(3). */ - sego = strerror(EPERM); - segc = strdup(sego); - selo = strerror_l(ENOENT, _LOCALE_C); - selc = strdup(selo); - if (strcmp(sego, segc) != 0) - errx(1, "child: strerror_l clobbered strerror"); - free(segc); - sego = strerror(ESRCH); - if (strcmp(selo, selc) != 0) - errx(1, "child: strerror clobbered strerror_l"); - - /* Temporarily switch to the main thread. */ - switch_thread(2, SWITCH_SIGNAL | SWITCH_WAIT); - if (strcmp(selo, selc) != 0) - errx(1, "child: main clobbered strerror_l"); - free(selc); - - /* Check that the C locale works even while all is set to UTF-8. */ - TEST_R(nl_langinfo_l, "US-ASCII", CODESET, _LOCALE_C); - TEST_R(iswalpha_l, 0, 0x00E9, _LOCALE_C); - TEST_R(towupper_l, 0x00E9, 0x00E9, _LOCALE_C); - TEST_R(wcscasecmp_l, *s1 - *s2, s1, s2, _LOCALE_C); - - /* Test displaying the global locale while a local one is set. */ - TEST_R(setlocale, "C/C.UTF-8/C/C/C/C", LC_ALL, NULL); - - /* Test switching the thread locale back. */ - TEST_R(MB_CUR_MAX, 4); - TEST_R(duplocale, _LOCALE_UTF8, LC_GLOBAL_LOCALE); - TEST_R(uselocale, _LOCALE_UTF8, _LOCALE_C); - TEST_R(MB_CUR_MAX, 1); - TEST_R(uselocale, _LOCALE_C, _LOCALE_NONE); - - /* Check that UTF-8 works even with a C thread locale. */ - TEST_R(nl_langinfo, "US-ASCII", CODESET); - TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); - TEST_R(iswalpha, 0, 0x0153); - TEST_R(iswalpha_l, 1, 0x0153, _LOCALE_UTF8); - TEST_R(towupper, 0x0153, 0x0153); - TEST_R(towupper_l, 0x0152, 0x0153, _LOCALE_UTF8); - TEST_R(wcsncasecmp, *s3 - *s4, s3, s4, 2); - TEST_R(wcsncasecmp_l, 0, s3, s4, 2, _LOCALE_UTF8); - - /* Test switching back to the global locale. */ - TEST_R(uselocale, _LOCALE_C, LC_GLOBAL_LOCALE); - TEST_R(MB_CUR_MAX, 4); - TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); - - /* Check that the global locale takes effect even in a thread. */ - TEST_R(nl_langinfo, "UTF-8", CODESET); - TEST_R(iswalpha, 1, 0x0153); - TEST_R(towupper, 0x0152, 0x0153); - TEST_R(wcscasecmp, 0, s1, s2); - - /* Hand control back to the main thread. */ - switch_thread(4, SWITCH_SIGNAL); - return NULL; -} - -int -main(void) -{ - pthread_t child_thread; - char *sego, *segc, *selo, *selc; - int irc; - - /* Initialize environment. */ - unsetenv("LC_ALL"); - unsetenv("LC_COLLATE"); - unsetenv("LC_CTYPE"); - unsetenv("LC_MONETARY"); - unsetenv("LC_NUMERIC"); - unsetenv("LC_TIME"); - unsetenv("LC_MESSAGES"); - unsetenv("LANG"); - - if ((irc = pthread_mutexattr_init(&mtxattr)) != 0) - errc(1, irc, "pthread_mutexattr_init"); - if ((irc = pthread_mutexattr_settype(&mtxattr, - PTHREAD_MUTEX_STRICT_NP)) != 0) - errc(1, irc, "pthread_mutexattr_settype"); - if ((irc = pthread_mutex_init(&mtx, &mtxattr)) != 0) - errc(1, irc, "pthread_mutex_init"); - if ((irc = pthread_cond_init(&cond, NULL)) != 0) - errc(1, irc, "pthread_cond_init"); - - /* First let the child do some tests. */ - if ((irc = pthread_create(&child_thread, NULL, child_func, NULL)) != 0) - errc(1, irc, "pthread_create"); - switch_thread(1, SWITCH_WAIT); - - /* Check that the global locale is undisturbed. */ - TEST_R(setlocale, "C", LC_ALL, NULL); - TEST_R(MB_CUR_MAX, 1); - - /* Check that *_l(3) works without any locale installed. */ - TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); - TEST_R(iswalpha_l, 1, 0x00E9, _LOCALE_UTF8); - TEST_R(towupper_l, 0x00C9, 0x00E9, _LOCALE_UTF8); - - /* Test setting the globale locale. */ - TEST_R(setlocale, "C.UTF-8", LC_CTYPE, "C.UTF-8"); - TEST_R(MB_CUR_MAX, 4); - TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); - - /* Test strerror(3). */ - sego = strerror(EINTR); - segc = strdup(sego); - selo = strerror_l(EIO, _LOCALE_C); - selc = strdup(selo); - if (strcmp(sego, segc) != 0) - errx(1, "main: strerror_l clobbered strerror"); - free(segc); - sego = strerror(ENXIO); - if (strcmp(selo, selc) != 0) - errx(1, "main: strerror clobbered strerror_l"); - free(selc); - - /* Let the child do some more tests, then clean up. */ - switch_thread(3, SWITCH_SIGNAL); - if ((irc = pthread_join(child_thread, NULL)) != 0) - errc(1, irc, "pthread_join"); - return 0; -} diff --git a/src/regress/lib/libc/locale/wcrtomb/Makefile b/src/regress/lib/libc/locale/wcrtomb/Makefile deleted file mode 100644 index b09cecc454..0000000000 --- a/src/regress/lib/libc/locale/wcrtomb/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ - -PROG = test_wcrtomb - -.include diff --git a/src/regress/lib/libc/locale/wcrtomb/test_wcrtomb.c b/src/regress/lib/libc/locale/wcrtomb/test_wcrtomb.c deleted file mode 100644 index ee0e14b69d..0000000000 --- a/src/regress/lib/libc/locale/wcrtomb/test_wcrtomb.c +++ /dev/null @@ -1,85 +0,0 @@ -/* $OpenBSD: test_wcrtomb.c,v 1.3 2021/07/03 12:04:53 schwarze Exp $ */ -/* - * Copyright (c) 2016 Ingo Schwarze - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -static mbstate_t mbs; - -void -onetest(const char *name, const wchar_t wcin, int outerr, const char *out) -{ - char buf[MB_LEN_MAX]; - size_t sz, outsz; - - memset(buf, 0, MB_LEN_MAX); - outsz = out == NULL ? (size_t)-1 : *out == '\0' ? 1 : strlen(out); - sz = wcrtomb(buf, wcin, &mbs); - if (errno != outerr) - err(1, "%zu %s U+%04X", MB_CUR_MAX, name, wcin); - if (sz != outsz || (out != NULL && strncmp(buf, out, sz))) - errx(1, "%zu %s U+%04X: %4.4s(%zd) != %4.4s(%zd)", - MB_CUR_MAX, name, wcin, buf, sz, - out == NULL ? "(NULL)" : out, outsz); - if (mbsinit(&mbs) == 0) - errx(1, "%zu %s U+%04X mbsinit", MB_CUR_MAX, name, wcin); - if (errno == 0 && outerr == 0) - return; - errno = 0; - memset(&mbs, 0, sizeof(mbs)); -} - -int -main(void) -{ - onetest("NUL", L'\0', 0, ""); - onetest("BEL", L'\a', 0, "\a"); - onetest("A", L'A', 0, "A"); - onetest("DEL", L'\177', 0, "\177"); - onetest("CSI", L'\233', 0, "\233"); - onetest("0x100", 0x100, EILSEQ, NULL); - - if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) - errx(1, "setlocale(UTF-8) failed"); - - onetest("NUL", L'\0', 0, ""); - onetest("BEL", L'\a', 0, "\a"); - onetest("A", L'A', 0, "A"); - onetest("DEL", L'\177', 0, "\177"); - onetest("CSI", L'\233', 0, "\302\233"); - onetest("0xe9", 0xe9, 0, "\303\251"); - onetest("0xcfff", 0xcfff, 0, "\354\277\277"); - onetest("0xd800", 0xd800, EILSEQ, NULL); - - if (setlocale(LC_CTYPE, "POSIX") == NULL) - errx(1, "setlocale(POSIX) failed"); - - onetest("0xff", L'\377', 0, "\377"); - - if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) - errx(1, "second setlocale(UTF-8) failed"); - - onetest("U+13000", 0x13000, 0, "\360\223\200\200"); - - return 0; -} -- cgit v1.2.3-55-g6feb