Module Name:    src
Committed By:   perseant
Date:           Thu May 25 18:28:54 UTC 2017

Modified Files:
        src/tests/lib/libc/locale: t_mbtowc.c t_wctomb.c

Log Message:
Add a member to the test data structure that indicates whether the given
encoding is state-dependent, and test the results of wctomb(NULL, '\0') and
mbtowc(NULL, NULL, 0) against this instead of against each other.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/locale/t_mbtowc.c
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/locale/t_wctomb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/locale/t_mbtowc.c
diff -u src/tests/lib/libc/locale/t_mbtowc.c:1.1 src/tests/lib/libc/locale/t_mbtowc.c:1.2
--- src/tests/lib/libc/locale/t_mbtowc.c:1.1	Sat Apr  9 17:45:25 2011
+++ src/tests/lib/libc/locale/t_mbtowc.c	Thu May 25 18:28:54 2017
@@ -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 <sys/cdefs.h>
 __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 <errno.h>
 #include <locale.h>
@@ -69,21 +69,20 @@ __RCSID("$NetBSD: t_mbtowc.c,v 1.1 2011/
 #include <atf-c.h>
 
 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 
 	/* 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)

Index: src/tests/lib/libc/locale/t_wctomb.c
diff -u src/tests/lib/libc/locale/t_wctomb.c:1.3 src/tests/lib/libc/locale/t_wctomb.c:1.4
--- src/tests/lib/libc/locale/t_wctomb.c:1.3	Mon Mar 25 15:31:03 2013
+++ src/tests/lib/libc/locale/t_wctomb.c	Thu May 25 18:28:54 2017
@@ -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 <sys/cdefs.h>
 __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 <stdio.h>
 #include <stdlib.h>
@@ -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);

Reply via email to