Module Name:    src
Committed By:   perseant
Date:           Thu Jun  1 15:45:02 UTC 2017

Modified Files:
        src/distrib/sets/lists/debug: mi
        src/distrib/sets/lists/tests: mi
        src/tests/lib/libc/locale: Makefile t_digittoint.c
Added Files:
        src/tests/lib/libc/locale: t_btowc.c

Log Message:
Add tests for btowc(3)/wctob(3) and enable compilation of the test for
digittoint(3).

The digittoint(3) test is skipped since we don't provide that function yet.

One of the test cases for btowc(3) is also skipped, since it tests conversion
to Unicode---whereas our wchar_t representation is locale-dependent.


To generate a diff of this commit:
cvs rdiff -u -r1.215 -r1.216 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.751 -r1.752 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/locale/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/locale/t_btowc.c
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/locale/t_digittoint.c

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

Modified files:

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.215 src/distrib/sets/lists/debug/mi:1.216
--- src/distrib/sets/lists/debug/mi:1.215	Wed May 31 00:22:06 2017
+++ src/distrib/sets/lists/debug/mi	Thu Jun  1 15:45:02 2017
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.215 2017/05/31 00:22:06 pgoyette Exp $
+# $NetBSD: mi,v 1.216 2017/06/01 15:45:02 perseant Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib					comp-sys-usr		compatdir
 ./usr/lib/i18n/libBIG5_g.a			comp-c-debuglib		debuglib,compatfile
@@ -1943,6 +1943,8 @@
 ./usr/libdata/debug/usr/tests/lib/libc/inet/t_inet_network.debug	tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_ctype1.debug		tests-obsolete		obsolete,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_ctype2.debug		tests-obsolete		obsolete,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/locale/t_btowc.debug		tests-lib-debug		debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/locale/t_digittoint.debug	tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_io.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_mbrtowc.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_mbsnrtowcs.debug	tests-lib-debug		debug,atf,compattestfile

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.751 src/distrib/sets/lists/tests/mi:1.752
--- src/distrib/sets/lists/tests/mi:1.751	Wed May 31 00:18:21 2017
+++ src/distrib/sets/lists/tests/mi	Thu Jun  1 15:45:02 2017
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.751 2017/05/31 00:18:21 perseant Exp $
+# $NetBSD: mi,v 1.752 2017/06/01 15:45:02 perseant Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2541,6 +2541,8 @@
 ./usr/tests/lib/libc/locale/Kyuafile		tests-lib-tests		compattestfile,atf,kyua
 ./usr/tests/lib/libc/locale/t_ctype1		tests-obsolete		obsolete
 ./usr/tests/lib/libc/locale/t_ctype2		tests-obsolete		obsolete
+./usr/tests/lib/libc/locale/t_btowc		tests-lib-tests		compattestfile,atf
+./usr/tests/lib/libc/locale/t_digittoint	tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/locale/t_io		tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/locale/t_mbrtowc		tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/locale/t_mbsnrtowcs	tests-lib-tests		compattestfile,atf

Index: src/tests/lib/libc/locale/Makefile
diff -u src/tests/lib/libc/locale/Makefile:1.8 src/tests/lib/libc/locale/Makefile:1.9
--- src/tests/lib/libc/locale/Makefile:1.8	Tue May 30 23:44:02 2017
+++ src/tests/lib/libc/locale/Makefile	Thu Jun  1 15:45:02 2017
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.8 2017/05/30 23:44:02 perseant Exp $
+# $NetBSD: Makefile,v 1.9 2017/06/01 15:45:02 perseant Exp $
 
 .include <bsd.own.mk>
 
@@ -15,10 +15,13 @@ TESTS_C+=	t_wcstod
 TESTS_C+=	t_wctomb
 TESTS_C+=	t_io
 TESTS_C+=	t_toupper
-#TESTS_C+=	t_digittoint
+TESTS_C+=	t_digittoint
 TESTS_C+=	t_sprintf
 TESTS_C+=	t_wctype
+TESTS_C+=	t_btowc
 
 COPTS.t_wctomb.c += -Wno-stack-protector
+COPTS.t_digittoint.c += -Wno-unused-variable
+COPTS.t_btowc.c += -Wno-unused-variable
 
 .include <bsd.test.mk>

Index: src/tests/lib/libc/locale/t_digittoint.c
diff -u src/tests/lib/libc/locale/t_digittoint.c:1.1 src/tests/lib/libc/locale/t_digittoint.c:1.2
--- src/tests/lib/libc/locale/t_digittoint.c:1.1	Tue May 30 23:44:02 2017
+++ src/tests/lib/libc/locale/t_digittoint.c	Thu Jun  1 15:45:02 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_digittoint.c,v 1.1 2017/05/30 23:44:02 perseant Exp $ */
+/* $NetBSD: t_digittoint.c,v 1.2 2017/06/01 15:45:02 perseant Exp $ */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2017\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_digittoint.c,v 1.1 2017/05/30 23:44:02 perseant Exp $");
+__RCSID("$NetBSD: t_digittoint.c,v 1.2 2017/06/01 15:45:02 perseant Exp $");
 
 #include <locale.h>
 #include <stdio.h>
@@ -42,6 +42,11 @@ __RCSID("$NetBSD: t_digittoint.c,v 1.1 2
 
 #include <atf-c.h>
 
+/* Use this until we have a better way to tell if it is defined */
+#ifdef digittoint
+# define DIGITTOINT_DEFINED
+#endif
+
 static struct test {
 	const char *locale;
 	const char *digits;
@@ -61,6 +66,7 @@ static struct test {
 	}
 };
 
+#ifdef DIGITTOINT_DEFINED
 static void
 h_digittoint(const struct test *t)
 {
@@ -75,6 +81,7 @@ h_digittoint(const struct test *t)
 		ATF_REQUIRE_EQ(digittoint(t->digits[i]), i);
 	}
 }
+#endif /* DIGITTOINT_DEFINED */
 
 ATF_TC(digittoint);
 
@@ -88,8 +95,12 @@ ATF_TC_BODY(digittoint, tc)
 {
 	struct test *t;
 
+#ifdef DIGITTOINT_DEFINED
 	for (t = &tests[0]; t->locale != NULL; ++t)
 		h_digittoint(t);
+#else /* ! DIGITTOINT_DEFINED */
+	atf_tc_skip("digittoint(3) not present to test");
+#endif /* DIGITTOINT_DEFINED */
 }
 
 ATF_TP_ADD_TCS(tp)

Added files:

Index: src/tests/lib/libc/locale/t_btowc.c
diff -u /dev/null src/tests/lib/libc/locale/t_btowc.c:1.1
--- /dev/null	Thu Jun  1 15:45:02 2017
+++ src/tests/lib/libc/locale/t_btowc.c	Thu Jun  1 15:45:02 2017
@@ -0,0 +1,189 @@
+/* $NetBSD: t_btowc.c,v 1.1 2017/06/01 15:45:02 perseant Exp $ */
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Konrad Schroder.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2017\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_btowc.c,v 1.1 2017/06/01 15:45:02 perseant Exp $");
+
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+struct test {
+	const char *locale;
+	const char *illegal; /* Illegal single-byte characters, if any */
+	const char *legal;   /* Legal single-byte characters */
+	/* The next two are only used if __STDC_ISO_10646__ is defined */
+	const wchar_t wlegal[8]; /* The same characters, but in ISO-10646 */
+	const wchar_t willegal[8]; /* ISO-10646 that do not map into charset */
+} tests[] = {
+	{
+		"C",
+		"\377",
+		"ABC123@\t",
+		{ 'A', 'B', 'C', '1', '2', '3', '@', '\t' },
+		{ 0x0430, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
+	},
+	{
+		"en_US.UTF-8",
+		"\200",
+		"ABC123@\t",
+		{ 'A', 'B', 'C', '1', '2', '3', '@', '\t' },
+		{ 0xfdd0, 0x10fffe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
+	},
+	{
+                "ru_RU.KOI8-R",
+		"", /* No illegal characters in KOI8-R */
+                "A\xc2\xd7\xc7\xc4\xc5\xa3",
+		{ 'A', 0x0431, 0x432, 0x0433, 0x0434, 0x0435, 0x0451, 0x0 },
+		{ 0x00c5, 0x00e6, 0x00fe, 0x0630, 0x06fc, 0x56cd, 0x0, 0x0 }
+	},
+	{
+		NULL,
+                NULL,
+                NULL,
+		{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
+		{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }
+	},
+};
+
+#ifdef __STDC_ISO_10646__
+static void
+h_iso10646(struct test *t)
+{
+	const char *cp;
+	unsigned char c;
+	char *str;
+	const wchar_t *wcp;
+
+	/* These should have valid wchar representations */
+	for (cp = t->legal, wcp = t->wlegal; *cp != '\0'; ++cp, ++wcp) {
+		c = (unsigned char)*cp;
+		printf("Checking legal character 0x%x\n", c);
+
+		/* It should map to the known Unicode equivalent */
+		printf("btowc(0x%2.2x) = 0x%x, expecting 0x%x\n",
+			c, btowc(c), *wcp);
+		ATF_REQUIRE(btowc(c) == *wcp);
+	}
+
+	/* These are invalid characters in the target set */
+	for (wcp = t->willegal; *wcp != '\0'; ++wcp) {
+		printf("Checking illegal wide character 0x%lx\n",
+			(unsigned long)*wcp);
+		ATF_REQUIRE_EQ(wctob(*wcp), EOF);
+	}
+}
+#endif
+
+static void
+h_btowc(struct test *t)
+{
+	const char *cp;
+	unsigned char c;
+	char *str;
+	const wchar_t *wcp;
+
+	ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C");
+	printf("Trying locale: %s\n", t->locale);
+	ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL);
+
+	/* btowc(EOF) -> WEOF */
+	ATF_REQUIRE_EQ(btowc(EOF), WEOF);
+
+	/* wctob(WEOF) -> EOF */
+	ATF_REQUIRE_EQ(wctob(WEOF), EOF);
+
+	/* Invalid in initial shift state -> WEOF */
+	for (cp = t->illegal; *cp != '\0'; ++cp) {
+		printf("Checking illegal character 0x%x\n",
+			(unsigned char)*cp);
+		ATF_REQUIRE_EQ(btowc(*cp), WEOF);
+	}
+
+	/* These should have valid wchar representations */
+	for (cp = t->legal; *cp != '\0'; ++cp) {
+		c = (unsigned char)*cp;
+		printf("Checking legal character 0x%x\n", c);
+
+		/* A legal character never maps to EOF */
+		ATF_REQUIRE(btowc(c) != WEOF);
+
+		/* And the mapping should be reversible */
+		printf("0x%x -> wide 0x%x -> 0x%x\n",
+			c, btowc(c), (unsigned char)wctob(btowc(c)));
+		ATF_REQUIRE_EQ(wctob(btowc(c)), c);
+	}
+}
+
+ATF_TC(btowc);
+ATF_TC_HEAD(btowc, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Checks btowc(3) and wctob(3)");
+}
+ATF_TC_BODY(btowc, tc)
+{
+	struct test *t;
+
+	for (t = tests; t->locale != NULL; ++t)
+		h_btowc(t);
+}
+
+ATF_TC(stdc_iso_10646);
+ATF_TC_HEAD(stdc_iso_10646, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+		"Checks btowc(3) conversion to ISO10646");
+}
+ATF_TC_BODY(stdc_iso_10646, tc)
+{
+	struct test *t;
+
+#ifdef __STDC_ISO_10646__
+	for (t = tests; t->locale != NULL; ++t)
+		h_iso10646(t);
+#else /* ! __STDC_ISO_10646__ */
+	atf_tc_skip("__STDC_ISO_10646__ not defined");
+#endif /* ! __STDC_ISO_10646__ */
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, btowc);
+	ATF_TP_ADD_TC(tp, stdc_iso_10646);
+
+	return atf_no_error();
+}

Reply via email to