Date: Sun, 15 Nov 2015 04:50:09 +0000 (UTC) From: Garrett Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290844 - head/lib/libc/tests/locale Message-ID: <201511150450.tAF4o9un098067@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Sun Nov 15 04:50:08 2015 New Revision: 290844 URL: https://svnweb.freebsd.org/changeset/base/290844 Log: Polish up iswctype_test - Split up the testcases into C locale and ja_JP.eucJP testcases. - Avoid a segfault in the event that setlocale fails, similar to r290843 - Replace `sizeof(x) / sizeof(*x)` pattern with `nitems(x)` MFC after: 1 week X-MFC with: r290532 Sponsored by: EMC / Isilon Storage Division Modified: head/lib/libc/tests/locale/iswctype_test.c Modified: head/lib/libc/tests/locale/iswctype_test.c ============================================================================== --- head/lib/libc/tests/locale/iswctype_test.c Sun Nov 15 04:33:14 2015 (r290843) +++ head/lib/libc/tests/locale/iswctype_test.c Sun Nov 15 04:50:08 2015 (r290844) @@ -34,6 +34,8 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include <sys/param.h> +#include <errno.h> #include <locale.h> #include <stdio.h> #include <string.h> @@ -42,31 +44,45 @@ __FBSDID("$FreeBSD$"); #include <atf-c.h> -ATF_TC_WITHOUT_HEAD(iswctype_test); -ATF_TC_BODY(iswctype_test, tc) +static void +require_lc_ctype(const char *locale_name) { - wctype_t t; - int i, j; - struct { - const char *name; - int (*func)(wint_t); - } cls[] = { - { "alnum", iswalnum }, - { "alpha", iswalpha }, - { "blank", iswblank }, - { "cntrl", iswcntrl }, - { "digit", iswdigit }, - { "graph", iswgraph }, - { "lower", iswlower }, - { "print", iswprint }, - { "punct", iswpunct }, - { "space", iswspace }, - { "upper", iswupper }, - { "xdigit", iswxdigit } - }; + char *lc_ctype_set; - /* C/POSIX locale. */ - for (i = 0; i < sizeof(cls) / sizeof(*cls); i++) { + lc_ctype_set = setlocale(LC_CTYPE, locale_name); + if (lc_ctype_set == NULL) + atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d", + locale_name, errno); + + ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0); +} + +static wctype_t t; +static int i, j; +static struct { + const char *name; + int (*func)(wint_t); +} cls[] = { + { "alnum", iswalnum }, + { "alpha", iswalpha }, + { "blank", iswblank }, + { "cntrl", iswcntrl }, + { "digit", iswdigit }, + { "graph", iswgraph }, + { "lower", iswlower }, + { "print", iswprint }, + { "punct", iswpunct }, + { "space", iswspace }, + { "upper", iswupper }, + { "xdigit", iswxdigit } +}; + +ATF_TC_WITHOUT_HEAD(iswctype_c_locale_test); +ATF_TC_BODY(iswctype_c_locale_test, tc) +{ + + require_lc_ctype("C"); + for (i = 0; i < nitems(cls); i++) { t = wctype(cls[i].name); ATF_REQUIRE(t != 0); for (j = 0; j < 256; j++) @@ -76,10 +92,15 @@ ATF_TC_BODY(iswctype_test, tc) ATF_REQUIRE(t == 0); for (i = 0; i < 256; i++) ATF_REQUIRE(iswctype(i, t) == 0); +} + +ATF_TC_WITHOUT_HEAD(iswctype_euc_jp_test); +ATF_TC_BODY(iswctype_euc_jp_test, tc) +{ + + require_lc_ctype("ja_JP.eucJP"); - /* Japanese (EUC) locale. */ - ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0); - for (i = 0; i < sizeof(cls) / sizeof(*cls); i++) { + for (i = 0; i < nitems(cls); i++) { t = wctype(cls[i].name); ATF_REQUIRE(t != 0); for (j = 0; j < 65536; j++) @@ -94,7 +115,8 @@ ATF_TC_BODY(iswctype_test, tc) ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, iswctype_test); + ATF_TP_ADD_TC(tp, iswctype_c_locale_test); + ATF_TP_ADD_TC(tp, iswctype_euc_jp_test); return (atf_no_error()); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201511150450.tAF4o9un098067>