Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src/tests/lib/libc/locale Pull up following revision(s) (requ...
details: https://anonhg.NetBSD.org/src/rev/4ab66f97452d
branches: netbsd-8
changeset: 434741:4ab66f97452d
user: martin <martin%NetBSD.org@localhost>
date: Thu Mar 15 09:55:23 2018 +0000
description:
Pull up following revision(s) (requested by maya in ticket #608):
tests/lib/libc/locale/t_sprintf.c: revision 1.3
tests/lib/libc/locale/t_wctomb.c: revision 1.5
tests/lib/libc/locale/t_io.c: revision 1.5
tests/lib/libc/locale/t_wcstod.c: revision 1.4
tests/lib/libc/locale/t_mbstowcs.c: revision 1.2
tests/lib/libc/locale/t_wctype.c: revision 1.2
tests/lib/libc/locale/t_mbrtowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.3
Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.
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.
diffstat:
tests/lib/libc/locale/t_btowc.c | 60 ++++++++++++++++++++++++++++++-------
tests/lib/libc/locale/t_io.c | 54 ++++++++++++++++++++++++++-------
tests/lib/libc/locale/t_mbrtowc.c | 24 ++++++++++++--
tests/lib/libc/locale/t_mbstowcs.c | 20 +++++++++++-
tests/lib/libc/locale/t_sprintf.c | 7 +---
tests/lib/libc/locale/t_wcstod.c | 44 +++++++++++++++++++++------
tests/lib/libc/locale/t_wctomb.c | 6 ++-
tests/lib/libc/locale/t_wctype.c | 25 ++++++++++++++-
8 files changed, 191 insertions(+), 49 deletions(-)
diffs (truncated from 543 to 300 lines):
diff -r 02afc0be6ad7 -r 4ab66f97452d tests/lib/libc/locale/t_btowc.c
--- a/tests/lib/libc/locale/t_btowc.c Wed Mar 14 18:37:48 2018 +0000
+++ b/tests/lib/libc/locale/t_btowc.c Thu Mar 15 09:55:23 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_btowc.c,v 1.1 2017/06/01 15:45:02 perseant Exp $ */
+/* $NetBSD: t_btowc.c,v 1.1.2.1 2018/03/15 09:55:23 martin Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -32,11 +32,12 @@
#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 $");
+__RCSID("$NetBSD: t_btowc.c,v 1.1.2.1 2018/03/15 09:55:23 martin Exp $");
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
#include <string.h>
#include <wchar.h>
@@ -51,13 +52,6 @@
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",
@@ -85,18 +79,28 @@
h_iso10646(struct test *t)
{
const char *cp;
- unsigned char c;
+ int c, wc;
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);
+ ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL);
+ (void)printf("Using locale: %s\n", str);
+
/* These should have valid wchar representations */
for (cp = t->legal, wcp = t->wlegal; *cp != '\0'; ++cp, ++wcp) {
- c = (unsigned char)*cp;
+ c = (int)(unsigned char)*cp;
printf("Checking legal character 0x%x\n", c);
+ wc = btowc(c);
+
+ if (errno != 0)
+ printf(" btowc() failed with errno=%d\n", errno);
/* It should map to the known Unicode equivalent */
printf("btowc(0x%2.2x) = 0x%x, expecting 0x%x\n",
- c, btowc(c), *wcp);
+ c, wc, *wcp);
ATF_REQUIRE(btowc(c) == *wcp);
}
@@ -120,6 +124,8 @@
ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C");
printf("Trying locale: %s\n", t->locale);
ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL);
+ ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL);
+ (void)printf("Using locale: %s\n", str);
/* btowc(EOF) -> WEOF */
ATF_REQUIRE_EQ(btowc(EOF), WEOF);
@@ -180,9 +186,39 @@
#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();
diff -r 02afc0be6ad7 -r 4ab66f97452d tests/lib/libc/locale/t_io.c
--- a/tests/lib/libc/locale/t_io.c Wed Mar 14 18:37:48 2018 +0000
+++ b/tests/lib/libc/locale/t_io.c Thu Mar 15 09:55:23 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_io.c,v 1.4 2014/01/21 00:32:16 yamt Exp $ */
+/* $NetBSD: t_io.c,v 1.4.20.1 2018/03/15 09:55:23 martin Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2011\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_io.c,v 1.4 2014/01/21 00:32:16 yamt Exp $");
+__RCSID("$NetBSD: t_io.c,v 1.4.20.1 2018/03/15 09:55:23 martin Exp $");
#include <sys/param.h>
#include <errno.h>
@@ -53,8 +53,14 @@
ATF_TC_BODY(bad_big5_wprintf, tc)
{
- /* XXX implementation detail knowledge (wchar_t encoding) */
- wchar_t ibuf[] = { 0xcf10, 0 };
+ wchar_t ibuf[] = {
+#ifdef __STDC_ISO_10646__
+ 0x0978, 0 /* An arbitrarily chosen Devangari symbol */
+#else
+ /* XXX implementation detail knowledge (wchar_t encoding) */
+ 0xcf10, 0
+#endif
+ };
setlocale(LC_CTYPE, "zh_TW.Big5");
ATF_REQUIRE_ERRNO(EILSEQ, wprintf(L"%ls\n", ibuf) < 0);
ATF_REQUIRE(ferror(stdout));
@@ -68,8 +74,14 @@
ATF_TC_BODY(bad_big5_swprintf, tc)
{
- /* XXX implementation detail knowledge (wchar_t encoding) */
- wchar_t ibuf[] = { 0xcf10, 0 };
+ wchar_t ibuf[] = {
+#ifdef __STDC_ISO_10646__
+ 0x0978, 0 /* An arbitrarily chosen Devangari symbol */
+#else
+ /* XXX implementation detail knowledge (wchar_t encoding) */
+ 0xcf10, 0
+#endif
+ };
wchar_t obuf[20];
setlocale(LC_CTYPE, "zh_TW.Big5");
ATF_REQUIRE_ERRNO(EILSEQ,
@@ -84,8 +96,14 @@
ATF_TC_BODY(good_big5_wprintf, tc)
{
- /* XXX implementation detail knowledge (wchar_t encoding) */
- wchar_t ibuf[] = { 0xcf40, 0 };
+ wchar_t ibuf[] = {
+#ifdef __STDC_ISO_10646__
+ 0x67DC, 0
+#else
+ /* XXX implementation detail knowledge (wchar_t encoding) */
+ 0xcf40, 0
+#endif
+ };
setlocale(LC_CTYPE, "zh_TW.Big5");
ATF_REQUIRE_EQ(wprintf(L"%ls\n", ibuf), 2);
}
@@ -98,8 +116,14 @@
ATF_TC_BODY(good_big5_swprintf, tc)
{
- /* XXX implementation detail knowledge (wchar_t encoding) */
- wchar_t ibuf[] = { 0xcf40, 0 };
+ wchar_t ibuf[] = {
+#ifdef __STDC_ISO_10646__
+ 0x67DC, 0
+#else
+ /* XXX implementation detail knowledge (wchar_t encoding) */
+ 0xcf40, 0
+#endif
+ };
wchar_t obuf[20];
setlocale(LC_CTYPE, "zh_TW.Big5");
ATF_REQUIRE_EQ(swprintf(obuf, sizeof(obuf), L"%ls\n", ibuf), 2);
@@ -139,8 +163,14 @@
ATF_REQUIRE(fp != NULL);
setlocale(LC_CTYPE, "zh_TW.Big5");
- /* XXX implementation detail knowledge (wchar_t encoding) */
- ATF_REQUIRE_EQ(getwc(fp), 0xcf40);
+ ATF_REQUIRE_EQ(getwc(fp),
+#ifdef __STDC_ISO_10646__
+ 0x67DC
+#else
+ /* XXX implementation detail knowledge (wchar_t encoding) */
+ 0xcf40
+#endif
+ );
fclose(fp);
}
diff -r 02afc0be6ad7 -r 4ab66f97452d tests/lib/libc/locale/t_mbrtowc.c
--- a/tests/lib/libc/locale/t_mbrtowc.c Wed Mar 14 18:37:48 2018 +0000
+++ b/tests/lib/libc/locale/t_mbrtowc.c Thu Mar 15 09:55:23 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mbrtowc.c,v 1.1 2011/07/15 07:35:21 jruoho Exp $ */
+/* $NetBSD: t_mbrtowc.c,v 1.1.34.1 2018/03/15 09:55:23 martin Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2011\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mbrtowc.c,v 1.1 2011/07/15 07:35:21 jruoho Exp $");
+__RCSID("$NetBSD: t_mbrtowc.c,v 1.1.34.1 2018/03/15 09:55:23 martin Exp $");
#include <errno.h>
#include <locale.h>
@@ -98,19 +98,31 @@
}, {
"ja_JP.ISO2022-JP2",
"\033$BF|K\1348l\033(BA\033$B$\"\033(BB\033$B$$\033(B",
+#ifdef __STDC_ISO_10646__
+ { 0x65E5, 0x672C, 0x8A9E, 0x41, 0x3042, 0x42, 0x3044 },
+#else
{ 0x4200467c, 0x42004b5c, 0x4200386c, 0x41, 0x42002422, 0x42, 0x42002424 },
+#endif
{ 5, 2, 2, 4, 5, 4, 5 },
7
}, {
"ja_JP.SJIS",
"\223\372\226{\214\352A\202\240B\202\242",
- { 0x93fa, 0x967b, 0x8cea, 0x41, 0x82a0, 0x42, 0x82a2 },
+#ifdef __STDC_ISO_10646__
+ { 0x65E5, 0x672C, 0x8A9E, 0x41, 0x3042, 0x42, 0x3044 },
+#else
+ { 0x93FA, 0x967B, 0x8CEA, 0x41, 0x82A0, 0x42, 0x82A2 },
+#endif
{ 2, 2, 2, 1, 2, 1, 2 },
7
}, {
"ja_JP.eucJP",
"\306\374\313\334\270\354A\244\242B\244\244",
- { 0xc6fc, 0xcbdc, 0xb8ec, 0x41, 0xa4a2, 0x42, 0xa4a4 },
+#ifdef __STDC_ISO_10646__
+ { 0x65E5, 0x672C, 0x8A9E, 0x41, 0x3042, 0x42, 0x3044 },
+#else
+ { 0xC6FC, 0xCBDC, 0xB8EC, 0x41, 0xA4A2, 0x42, 0xA4A4 },
+#endif
{ 2, 2, 2, 1, 2, 1, 2 },
7
}, {
@@ -146,6 +158,8 @@
// mbrtowc(0, 0, 0, &st); /* XXX for ISO2022-JP */
stp = use_mbstate ? &st : 0;
+ printf("First using repeated mbrtowc\n");
+
for (n = 9; n > 0; n--) {
const char *src = t->data;
wchar_t dst;
@@ -196,6 +210,8 @@
"%zd (expected: %zd)", nchar, t->length);
}
+ printf("Now using mbsrtowcs\n");
+
{
wchar_t wbuf[SIZE];
size_t rv;
diff -r 02afc0be6ad7 -r 4ab66f97452d tests/lib/libc/locale/t_mbstowcs.c
--- a/tests/lib/libc/locale/t_mbstowcs.c Wed Mar 14 18:37:48 2018 +0000
+++ b/tests/lib/libc/locale/t_mbstowcs.c Thu Mar 15 09:55:23 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mbstowcs.c,v 1.1 2011/07/15 07:35:21 jruoho Exp $ */
+/* $NetBSD: t_mbstowcs.c,v 1.1.34.1 2018/03/15 09:55:23 martin Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
Home |
Main Index |
Thread Index |
Old Index