Module Name:    src
Committed By:   perseant
Date:           Thu Aug 10 19:08:43 UTC 2017

Modified Files:
        src/tests/lib/libc/locale: t_btowc.c

Log Message:
Separate the C/POSIX locale test from the rest; make it more thorough
and more correct.  This fixes a problem reported by martin@ when the
test is compiled with -funsigned-char.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/locale/t_btowc.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_btowc.c
diff -u src/tests/lib/libc/locale/t_btowc.c:1.2 src/tests/lib/libc/locale/t_btowc.c:1.3
--- src/tests/lib/libc/locale/t_btowc.c:1.2	Wed Jul 12 17:32:51 2017
+++ src/tests/lib/libc/locale/t_btowc.c	Thu Aug 10 19:08:43 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_btowc.c,v 1.2 2017/07/12 17:32:51 perseant Exp $ */
+/* $NetBSD: t_btowc.c,v 1.3 2017/08/10 19:08:43 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_btowc.c,v 1.2 2017/07/12 17:32:51 perseant Exp $");
+__RCSID("$NetBSD: t_btowc.c,v 1.3 2017/08/10 19:08:43 perseant Exp $");
 
 #include <locale.h>
 #include <stdio.h>
@@ -52,13 +52,6 @@ struct test {
 	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",
@@ -193,9 +186,39 @@ ATF_TC_BODY(stdc_iso_10646, tc)
 #endif /* ! __STDC_ISO_10646__ */
 }
 
+ATF_TC(btowc_posix);
+ATF_TC_HEAD(btowc_posix, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Checks btowc(3) and wctob(3) for POSIX locale");
+}
+ATF_TC_BODY(btowc_posix, tc)
+{
+	const char *cp;
+	unsigned char c;
+	char *str;
+	const wchar_t *wcp;
+	int i;
+
+	ATF_REQUIRE_STREQ(setlocale(LC_ALL, "POSIX"), "POSIX");
+
+	/* btowc(EOF) -> WEOF */
+	ATF_REQUIRE_EQ(btowc(EOF), WEOF);
+
+	/* wctob(WEOF) -> EOF */
+	ATF_REQUIRE_EQ(wctob(WEOF), EOF);
+
+	/* All characters from 0 to 255, inclusive, map
+	   onto their unsigned char equivalent */
+	for (i = 0; i <= 255; i++) {
+		ATF_REQUIRE_EQ(btowc(i), (wchar_t)(unsigned char)(i));
+		ATF_REQUIRE_EQ((unsigned char)wctob(i), (wchar_t)i);
+	}
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, btowc);
+	ATF_TP_ADD_TC(tp, btowc_posix);
 	ATF_TP_ADD_TC(tp, stdc_iso_10646);
 
 	return atf_no_error();

Reply via email to