diff --git a/tests/lib/libc/locale/t_mbtowc.c b/tests/lib/libc/locale/t_mbtowc.c index 62f62b10d50e..4e3d80ca463b 100644 --- a/tests/lib/libc/locale/t_mbtowc.c +++ b/tests/lib/libc/locale/t_mbtowc.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_mbtowc.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $ */ +/* $NetBSD: t_mbtowc.c,v 1.2 2017/05/25 18:28:54 perseant Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -56,7 +56,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2011\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_mbtowc.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $"); +__RCSID("$NetBSD: t_mbtowc.c,v 1.2 2017/05/25 18:28:54 perseant Exp $"); #include #include @@ -69,21 +69,20 @@ __RCSID("$NetBSD: t_mbtowc.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $"); #include static void -h_mbtowc(const char *locale, const char *illegal, const char *legal) +h_mbtowc(const char *locale, const char *illegal, const char *legal, size_t stateful) { char buf[64]; - size_t stateful, ret; + size_t ret; char *str; ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); + (void)printf("Trying locale: %s\n", locale); ATF_REQUIRE(setlocale(LC_CTYPE, locale) != NULL); ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL); (void)printf("Using locale: %s\n", str); - - stateful = wctomb(NULL, L'\0'); (void)printf("Locale is state-%sdependent\n", - stateful ? "in" : ""); + !stateful ? "in" : ""); /* initialize internal state */ ret = mbtowc(NULL, NULL, 0); @@ -101,8 +100,7 @@ h_mbtowc(const char *locale, const char *illegal, const char *legal) /* if this is stateless encoding, this re-initialization is not required. */ if (stateful) { /* re-initialize internal state */ - ret = mbtowc(NULL, NULL, 0); - ATF_REQUIRE(stateful ? ret : !ret); + mbtowc(NULL, NULL, 0); } /* valid multibyte sequence case */ @@ -126,13 +124,13 @@ ATF_TC_HEAD(mbtowc, tc) } ATF_TC_BODY(mbtowc, tc) { - h_mbtowc("en_US.UTF-8", "\240", "\302\240"); - h_mbtowc("ja_JP.ISO2022-JP", "\033$B", "\033$B$\"\033(B"); - h_mbtowc("ja_JP.SJIS", "\202", "\202\240"); - h_mbtowc("ja_JP.eucJP", "\244", "\244\242"); - h_mbtowc("zh_CN.GB18030", "\241", "\241\241"); - h_mbtowc("zh_TW.Big5", "\241", "\241@"); - h_mbtowc("zh_TW.eucTW", "\241", "\241\241"); + h_mbtowc("en_US.UTF-8", "\240", "\302\240", 0); + h_mbtowc("ja_JP.ISO2022-JP", "\033$B", "\033$B$\"\033(B", 1); + h_mbtowc("ja_JP.SJIS", "\202", "\202\240", 0); + h_mbtowc("ja_JP.eucJP", "\244", "\244\242", 0); + h_mbtowc("zh_CN.GB18030", "\241", "\241\241", 0); + h_mbtowc("zh_TW.Big5", "\241", "\241@", 0); + h_mbtowc("zh_TW.eucTW", "\241", "\241\241", 0); } ATF_TP_ADD_TCS(tp) diff --git a/tests/lib/libc/locale/t_wctomb.c b/tests/lib/libc/locale/t_wctomb.c index f553c8c511f1..4e343a5dc507 100644 --- a/tests/lib/libc/locale/t_wctomb.c +++ b/tests/lib/libc/locale/t_wctomb.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_wctomb.c,v 1.3 2013/03/25 15:31:03 gson Exp $ */ +/* $NetBSD: t_wctomb.c,v 1.4 2017/05/25 18:28:54 perseant Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -55,7 +55,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2011\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_wctomb.c,v 1.3 2013/03/25 15:31:03 gson Exp $"); +__RCSID("$NetBSD: t_wctomb.c,v 1.4 2017/05/25 18:28:54 perseant Exp $"); #include #include @@ -76,6 +76,7 @@ static struct test { const char *data; size_t wclen; size_t mblen[16]; + size_t stateful; } tests[] = { { "ja_JP.ISO2022-JP", @@ -87,13 +88,15 @@ static struct test { "\xb1\xb2\xb3" /* "aiu" */ "\x1b(B", /* ISO 646 */ 3 + 3 + 3, - { 3+2, 2, 2, 3+1, 1, 1, 3+1, 1, 1, 3+1 } + { 3+2, 2, 2, 3+1, 1, 1, 3+1, 1, 1, 3+1 }, + 1, }, { "C", "ABC", 3, - { 1, 1, 1, 1 } -}, { NULL, NULL, 0, { } } + { 1, 1, 1, 1 }, + 0, +}, { NULL, NULL, 0, { }, 0 } }; static void @@ -109,19 +112,24 @@ h_wctomb(const struct test *t, char tc) size_t sz, ret, i; ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); + (void)printf("Trying locale: %s\n", t->locale); ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL); + if (tc == TC_WCRTOMB_ST) { + (void)memset(&st, 0, sizeof(st)); + stp = &st; + } else { + (void)printf("Checking correct reporting of statefulness\n"); + ret = wctomb(NULL, 0); + ATF_REQUIRE_EQ(t->stateful, !!ret); + } + (void)strvis(buf, t->data, VIS_WHITE | VIS_OCTAL); (void)printf("Checking sequence: \"%s\"\n", buf); ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL); (void)printf("Using locale: %s\n", str); - if (tc == TC_WCRTOMB_ST) { - (void)memset(&st, 0, sizeof(st)); - stp = &st; - } - wcs[t->wclen] = L'X'; /* poison */ pcs = t->data; sz = mbsrtowcs(wcs, &pcs, t->wclen + 2, NULL);