Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/regress/lib/libc/locale a simple regression test for wcrtomb...
details: https://anonhg.NetBSD.org/src/rev/e09869bd7a33
branches: trunk
changeset: 570161:e09869bd7a33
user: yamt <yamt%NetBSD.org@localhost>
date: Sun Sep 26 03:45:10 2004 +0000
description:
a simple regression test for wcrtomb and wctomb.
diffstat:
regress/lib/libc/locale/Makefile | 4 +-
regress/lib/libc/locale/wctomb/Makefile | 5 +
regress/lib/libc/locale/wctomb/Makefile.inc | 13 +++
regress/lib/libc/locale/wctomb/iso2022-jp/Makefile | 5 +
regress/lib/libc/locale/wctomb/iso2022-jp/iso2022-jp.c | 16 ++++
regress/lib/libc/locale/wctomb/iso646/Makefile | 5 +
regress/lib/libc/locale/wctomb/iso646/iso646.c | 10 ++
regress/lib/libc/locale/wctomb/test.c | 68 ++++++++++++++++++
8 files changed, 124 insertions(+), 2 deletions(-)
diffs (161 lines):
diff -r 26e8176327ab -r e09869bd7a33 regress/lib/libc/locale/Makefile
--- a/regress/lib/libc/locale/Makefile Sun Sep 26 03:03:17 2004 +0000
+++ b/regress/lib/libc/locale/Makefile Sun Sep 26 03:45:10 2004 +0000
@@ -1,5 +1,5 @@
-# $NetBSD: Makefile,v 1.1 2002/09/11 14:54:33 minoura Exp $
+# $NetBSD: Makefile,v 1.2 2004/09/26 03:45:10 yamt Exp $
-SUBDIR+= ctype1 ctype2 ctype3
+SUBDIR+= ctype1 ctype2 ctype3 wctomb
.include <bsd.subdir.mk>
diff -r 26e8176327ab -r e09869bd7a33 regress/lib/libc/locale/wctomb/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/locale/wctomb/Makefile Sun Sep 26 03:45:10 2004 +0000
@@ -0,0 +1,5 @@
+# $NetBSD: Makefile,v 1.1 2004/09/26 03:45:10 yamt Exp $
+
+SUBDIR= iso646 iso2022-jp
+
+.include <bsd.subdir.mk>
diff -r 26e8176327ab -r e09869bd7a33 regress/lib/libc/locale/wctomb/Makefile.inc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/locale/wctomb/Makefile.inc Sun Sep 26 03:45:10 2004 +0000
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile.inc,v 1.1 2004/09/26 03:45:10 yamt Exp $
+
+NOMAN= # defined
+WARNS= 3
+
+CPPFLAGS+= -I${.CURDIR}/..
+
+regress:
+ @if ./${PROG}; then \
+ echo PASSED; exit 0; \
+ else \
+ echo FAILED; exit 1; \
+ fi
diff -r 26e8176327ab -r e09869bd7a33 regress/lib/libc/locale/wctomb/iso2022-jp/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/locale/wctomb/iso2022-jp/Makefile Sun Sep 26 03:45:10 2004 +0000
@@ -0,0 +1,5 @@
+# $Id: Makefile,v 1.1 2004/09/26 03:45:10 yamt Exp $
+
+PROG= iso2022-jp
+
+.include <bsd.prog.mk>
diff -r 26e8176327ab -r e09869bd7a33 regress/lib/libc/locale/wctomb/iso2022-jp/iso2022-jp.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/locale/wctomb/iso2022-jp/iso2022-jp.c Sun Sep 26 03:45:10 2004 +0000
@@ -0,0 +1,16 @@
+/* $Id: iso2022-jp.c,v 1.1 2004/09/26 03:45:10 yamt Exp $ */
+
+const char teststring[] =
+ "\x1b$B" /* JIS X 0208-1983 */
+ "\x46\x7c\x4b\x5c\x38\x6c" /* "nihongo" */
+ "\x1b(B" /* ISO 646 */
+ "ABC"
+ "\x1b(I" /* JIS X 0201 katakana */
+ "\xb1\xb2\xb3" /* "aiu" */
+ "\x1b(B" /* ISO 646 */
+ ;
+const int teststring_wclen = 3 + 3 + 3;
+const char teststring_loc[] = "ja_JP.ISO2022-JP";
+const int teststring_mblen[] = { 3+2, 2, 2, 3+1, 1, 1, 3+1, 1, 1, 3+1 };
+
+#include "test.c"
diff -r 26e8176327ab -r e09869bd7a33 regress/lib/libc/locale/wctomb/iso646/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/locale/wctomb/iso646/Makefile Sun Sep 26 03:45:10 2004 +0000
@@ -0,0 +1,5 @@
+# $Id: Makefile,v 1.1 2004/09/26 03:45:10 yamt Exp $
+
+PROG= iso646
+
+.include <bsd.prog.mk>
diff -r 26e8176327ab -r e09869bd7a33 regress/lib/libc/locale/wctomb/iso646/iso646.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/locale/wctomb/iso646/iso646.c Sun Sep 26 03:45:10 2004 +0000
@@ -0,0 +1,10 @@
+/* $Id: iso646.c,v 1.1 2004/09/26 03:45:10 yamt Exp $ */
+
+const char teststring[] =
+ "ABC"
+ ;
+const int teststring_wclen = 3;
+const char teststring_loc[] = "C";
+const int teststring_mblen[] = { 1, 1, 1, 1 };
+
+#include "test.c"
diff -r 26e8176327ab -r e09869bd7a33 regress/lib/libc/locale/wctomb/test.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/locale/wctomb/test.c Sun Sep 26 03:45:10 2004 +0000
@@ -0,0 +1,68 @@
+/* $Id: test.c,v 1.1 2004/09/26 03:45:10 yamt Exp $ */
+
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+typedef size_t wcrtomb_t(char *, wchar_t, mbstate_t *);
+
+wcrtomb_t _wctomb;
+void dotest1(const char *, wcrtomb_t, wchar_t *, mbstate_t *);
+
+size_t
+_wctomb(char *s, wchar_t wc, mbstate_t *ps)
+{
+
+ return wctomb(s, wc);
+}
+
+int
+main(int argc, char *argv[])
+{
+ wchar_t wcs[teststring_wclen + 2];
+ const char *pcs;
+ size_t sz;
+ mbstate_t st;
+
+ if (setlocale(LC_CTYPE, teststring_loc) == NULL)
+ exit(1);
+
+ pcs = teststring;
+ wcs[teststring_wclen] = L'X'; /* poison */
+ sz = mbsrtowcs(wcs, &pcs, teststring_wclen + 2, NULL);
+ if (sz != teststring_wclen)
+ exit(3);
+ if (wcs[teststring_wclen])
+ exit(4);
+
+ dotest1("wctomb", _wctomb, wcs, NULL);
+ memset(&st, 0, sizeof(st));
+ dotest1("wcrtomb", wcrtomb, wcs, &st);
+ dotest1("wcrtomb (internal state)", wcrtomb, wcs, NULL);
+
+ exit(0);
+}
+
+void
+dotest1(const char *text, wcrtomb_t fn, wchar_t *wcs, mbstate_t *stp)
+{
+ char cs[MB_CUR_MAX];
+ int ret;
+ int i;
+
+ printf("testing %s\n", text);
+
+ for (i = 0; i < teststring_wclen + 1; i++) {
+ ret = fn(cs, wcs[i], stp);
+ if (ret != teststring_mblen[i]) {
+ printf("\t[%d] %d != %d BAD\n",
+ i, ret, teststring_mblen[i]);
+ exit(5);
+ }
+#if 0
+ printf("\t[%d] %d ok\n", i, ret);
+#endif
+ }
+}
Home |
Main Index |
Thread Index |
Old Index