Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc/locale Add a member to the test data structur...
details: https://anonhg.NetBSD.org/src/rev/356cd6f203ca
branches: trunk
changeset: 824137:356cd6f203ca
user: perseant <perseant%NetBSD.org@localhost>
date: Thu May 25 18:28:54 2017 +0000
description:
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.
diffstat:
tests/lib/libc/locale/t_mbtowc.c | 30 ++++++++++++++----------------
tests/lib/libc/locale/t_wctomb.c | 28 ++++++++++++++++++----------
2 files changed, 32 insertions(+), 26 deletions(-)
diffs (150 lines):
diff -r 75b4833c53c0 -r 356cd6f203ca tests/lib/libc/locale/t_mbtowc.c
--- a/tests/lib/libc/locale/t_mbtowc.c Thu May 25 10:02:15 2017 +0000
+++ b/tests/lib/libc/locale/t_mbtowc.c Thu May 25 18:28:54 2017 +0000
@@ -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 @@
#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 @@
/* 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_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 -r 75b4833c53c0 -r 356cd6f203ca tests/lib/libc/locale/t_wctomb.c
--- a/tests/lib/libc/locale/t_wctomb.c Thu May 25 10:02:15 2017 +0000
+++ b/tests/lib/libc/locale/t_wctomb.c Thu May 25 18:28:54 2017 +0000
@@ -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 @@
const char *data;
size_t wclen;
size_t mblen[16];
+ size_t stateful;
} tests[] = {
{
"ja_JP.ISO2022-JP",
@@ -87,13 +88,15 @@
"\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 @@
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);
Home |
Main Index |
Thread Index |
Old Index