Module Name: src Committed By: pgoyette Date: Sat Apr 9 17:45:25 UTC 2011
Modified Files: src/distrib/sets/lists/tests: mi src/etc/mtree: NetBSD.dist.tests src/tests/lib/libc: Makefile Added Files: src/tests/lib/libc/locale: Makefile t_ctype1.c t_ctype2.c t_mbtowc.c t_wcstod.c t_wctomb.c Log Message: atf-ify the various locale tests To generate a diff of this commit: cvs rdiff -u -r1.300 -r1.301 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.35 -r1.36 src/etc/mtree/NetBSD.dist.tests cvs rdiff -u -r1.38 -r1.39 src/tests/lib/libc/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/locale/Makefile \ src/tests/lib/libc/locale/t_ctype1.c src/tests/lib/libc/locale/t_ctype2.c \ src/tests/lib/libc/locale/t_mbtowc.c src/tests/lib/libc/locale/t_wcstod.c \ src/tests/lib/libc/locale/t_wctomb.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/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.300 src/distrib/sets/lists/tests/mi:1.301 --- src/distrib/sets/lists/tests/mi:1.300 Fri Apr 8 06:49:20 2011 +++ src/distrib/sets/lists/tests/mi Sat Apr 9 17:45:25 2011 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.300 2011/04/08 06:49:20 jruoho Exp $ +# $NetBSD: mi,v 1.301 2011/04/09 17:45:25 pgoyette Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -370,6 +370,12 @@ ./usr/libdata/debug/usr/tests/lib/libc/ieeefp/t_nan_inf.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/ieeefp/t_round.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/ieeefp/t_subnormal.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libc/locale tests-lib-debug +./usr/libdata/debug/usr/tests/lib/libc/locale/t_ctype1 tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libc/locale/t_ctype2 tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libc/locale/t_mbtowc tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libc/locale/t_wcstod tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libc/locale/t_wctomb tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/inet tests-lib-debug ./usr/libdata/debug/usr/tests/lib/libc/inet/t_inet_network.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/net tests-lib-debug @@ -1787,6 +1793,13 @@ ./usr/tests/lib/libc/ieeefp/t_nan_inf tests-lib-tests atf ./usr/tests/lib/libc/ieeefp/t_round tests-lib-tests atf ./usr/tests/lib/libc/ieeefp/t_subnormal tests-lib-tests atf +./usr/tests/lib/libc/locale tests-lib-tests +./usr/tests/lib/libc/locale/Atffile tests-lib-tests atf +./usr/tests/lib/libc/locale/t_ctype1 tests-lib-tests atf +./usr/tests/lib/libc/locale/t_ctype2 tests-lib-tests atf +./usr/tests/lib/libc/locale/t_mbtowc tests-lib-tests atf +./usr/tests/lib/libc/locale/t_wcstod tests-lib-tests atf +./usr/tests/lib/libc/locale/t_wctomb tests-lib-tests atf ./usr/tests/lib/libc/inet tests-lib-tests ./usr/tests/lib/libc/inet/Atffile tests-lib-tests atf ./usr/tests/lib/libc/inet/t_inet_network tests-lib-tests atf Index: src/etc/mtree/NetBSD.dist.tests diff -u src/etc/mtree/NetBSD.dist.tests:1.35 src/etc/mtree/NetBSD.dist.tests:1.36 --- src/etc/mtree/NetBSD.dist.tests:1.35 Thu Apr 7 06:24:07 2011 +++ src/etc/mtree/NetBSD.dist.tests Sat Apr 9 17:45:24 2011 @@ -1,4 +1,4 @@ -# $NetBSD: NetBSD.dist.tests,v 1.35 2011/04/07 06:24:07 plunky Exp $ +# $NetBSD: NetBSD.dist.tests,v 1.36 2011/04/09 17:45:24 pgoyette Exp $ ./usr/libdata/debug/usr/tests ./usr/libdata/debug/usr/tests/atf @@ -51,6 +51,7 @@ ./usr/libdata/debug/usr/tests/lib/libc/gen ./usr/libdata/debug/usr/tests/lib/libc/hash ./usr/libdata/debug/usr/tests/lib/libc/ieeefp +./usr/libdata/debug/usr/tests/lib/libc/locale ./usr/libdata/debug/usr/tests/lib/libc/inet ./usr/libdata/debug/usr/tests/lib/libc/net ./usr/libdata/debug/usr/tests/lib/libc/net/getaddrinfo @@ -166,6 +167,7 @@ ./usr/tests/lib/libc/hash ./usr/tests/lib/libc/hash/data ./usr/tests/lib/libc/ieeefp +./usr/tests/lib/libc/locale ./usr/tests/lib/libc/inet ./usr/tests/lib/libc/net ./usr/tests/lib/libc/net/getaddrinfo Index: src/tests/lib/libc/Makefile diff -u src/tests/lib/libc/Makefile:1.38 src/tests/lib/libc/Makefile:1.39 --- src/tests/lib/libc/Makefile:1.38 Wed Mar 9 23:10:07 2011 +++ src/tests/lib/libc/Makefile Sat Apr 9 17:45:24 2011 @@ -1,11 +1,11 @@ -# $NetBSD: Makefile,v 1.38 2011/03/09 23:10:07 joerg Exp $ +# $NetBSD: Makefile,v 1.39 2011/04/09 17:45:24 pgoyette Exp $ .include <bsd.own.mk> .include <bsd.sys.mk> SUBDIR+= tls_dso .WAIT -TESTS_SUBDIRS+= db gen hash ieeefp inet net regex rpc setjmp stdlib +TESTS_SUBDIRS+= db gen hash ieeefp inet locale net regex rpc setjmp stdlib TESTS_SUBDIRS+= stdio string sys time tls ttyio .if ${HAS_SSP} == "yes" Added files: Index: src/tests/lib/libc/locale/Makefile diff -u /dev/null src/tests/lib/libc/locale/Makefile:1.1 --- /dev/null Sat Apr 9 17:45:25 2011 +++ src/tests/lib/libc/locale/Makefile Sat Apr 9 17:45:25 2011 @@ -0,0 +1,13 @@ +# $NetBSD: Makefile,v 1.1 2011/04/09 17:45:25 pgoyette Exp $ + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/lib/libc/locale + +TESTS_C+= t_ctype1 +TESTS_C+= t_ctype2 +TESTS_C+= t_mbtowc +TESTS_C+= t_wcstod +TESTS_C+= t_wctomb + +.include <bsd.test.mk> Index: src/tests/lib/libc/locale/t_ctype1.c diff -u /dev/null src/tests/lib/libc/locale/t_ctype1.c:1.1 --- /dev/null Sat Apr 9 17:45:25 2011 +++ src/tests/lib/libc/locale/t_ctype1.c Sat Apr 9 17:45:25 2011 @@ -0,0 +1,202 @@ +/* $NetBSD: t_ctype1.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * 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. + */ + +/*- + * Copyright (c)2003 Citrus Project, + * All rights reserved. + * + * 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 AUTHOR 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 AUTHOR 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) 2011\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_ctype1.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $"); + +#include <errno.h> +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <vis.h> +#include <wchar.h> + +#include <atf-c.h> + +#define REQUIRE_ERRNO(x, v) \ + ATF_REQUIRE_MSG((x) != (v), "%s: %s", #x, strerror(errno)) + +#define SIZE 256 + +static struct test { + const char *locale; + const char *data; + wchar_t wchars[64]; + int widths[64]; + int width; +} tests[] = { +{ + "en_US.UTF-8", + "[\001\177][\302\200\337\277][\340\240\200\357\277\277][\360\220\200" + "\200\367\277\277\277][\370\210\200\200\200\373\277\277\277\277][\374" + "\204\200\200\200\200\375\277\277\277\277\277]", + { + 0x5B, 0x01, 0x7F, 0x5D, 0x5B, 0x80, 0x07FF, 0x5D, 0x5B, 0x0800, + 0xFFFF, 0x5D, 0x5B, 0x10000, 0x1FFFFF, 0x5D, 0x5B, 0x200000, + 0x3FFFFFF, 0x5D, 0x5B, 0x4000000, 0x7FFFFFFF, 0x5D, 0x0A + }, + { 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, + 1, 1, -1, -1, 1, 1, -1, -1, 1, -1 + }, + -1 +}, { + "ja_JP.ISO2022-JP", + "\033$B#J#I#S$G$9!#\033(Baaaa\033$B$\"$$$&$($*\033(B", + { + 0x4200234A, 0x42002349, 0x42002353, 0x42002447, 0x42002439, + 0x42002123, 0x61, 0x61, 0x61, 0x61, 0x42002422, 0x42002424, + 0x42002426, 0x42002428, 0x4200242A, 0x0A + }, + { 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, -1 }, + 26 +}, { + "ja_JP.SJIS", + "\202r\202i\202h\202r\202\305\202\267\201Baaaa\202\240\202\242" + "\202\244\202\246\202\250", + { + 0x8272, 0x8269, 0x8268, 0x8272, 0x82C5, 0x82B7, 0x8142, 0x61, + 0x61, 0x61, 0x61, 0x82A0, 0x82A2, 0x82A4, 0x82A6, 0x82A8, 0x0A + }, + { 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, -1 }, + 28 +}, { + "ja_JP.eucJP", + "\243\305\243\325\243\303\244\307\244\271\241\243aaaa\244\242\244" + "\244\244\246\244\250\244\252", + { + 0xA3C5, 0xA3D5, 0xA3C3, 0xA4C7, 0xA4B9, 0xA1A3, 0x61, 0x61, 0x61, + 0x61, 0xA4A2, 0xA4A4, 0xA4A6, 0xA4A8, 0xA4AA, 0x0A + }, + { 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, -1 }, + 26 +}, { + NULL, + NULL, + {}, + {}, + 0 +} +}; + +ATF_TC(ctype1); +ATF_TC_HEAD(ctype1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks wide character functions with different locales"); +} +ATF_TC_BODY(ctype1, tc) +{ + struct test *t; + + for (t = &tests[0]; t->data != NULL; ++t) { + wchar_t wbuf[SIZE]; + char buf[SIZE]; + char visbuf[SIZE]; + char *str; + int i; + + ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); + ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL); + + (void)strvis(visbuf, t->data, VIS_WHITE | VIS_OCTAL); + (void)printf("Checking string: \"%s\"\n", visbuf); + + ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL); + (void)printf("Using locale: %s\n", str); + + REQUIRE_ERRNO((ssize_t)mbstowcs(wbuf, t->data, SIZE-1), -1); + REQUIRE_ERRNO((ssize_t)wcstombs(buf, wbuf, SIZE-1), -1); + + if (strcmp(buf, t->data) != 0) { + (void)strvis(visbuf, buf, VIS_WHITE | VIS_OCTAL); + (void)printf("Conversion to wcs and back failed: " + "\"%s\"\n", visbuf); + atf_tc_fail("Test failed"); + } + + /* The output here is implementation-dependent. */ + + for (i = 0; wbuf[i] != 0; ++i) { + if (wbuf[i] == t->wchars[i] && + wcwidth(wbuf[i]) == t->widths[i]) + continue; + + (void)printf("At position %d:\n", i); + (void)printf(" expected: 0x%04X (%d)\n", + t->wchars[i], t->widths[i]); + (void)printf(" got : 0x%04X (%d)\n", wbuf[i], + wcwidth(wbuf[i])); + atf_tc_fail("Test failed"); + } + + if (wcswidth(wbuf, SIZE-1) != t->width) { + (void)printf("Incorrect wcswidth:\n"); + (void)printf(" expected: %d\n", t->width); + (void)printf(" got : %d\n", wcswidth(wbuf, SIZE-1)); + atf_tc_fail("Test failed"); + } + + (void)printf("Ok.\n"); + } +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, ctype1); + + return atf_no_error(); +} Index: src/tests/lib/libc/locale/t_ctype2.c diff -u /dev/null src/tests/lib/libc/locale/t_ctype2.c:1.1 --- /dev/null Sat Apr 9 17:45:25 2011 +++ src/tests/lib/libc/locale/t_ctype2.c Sat Apr 9 17:45:25 2011 @@ -0,0 +1,266 @@ +/* $NetBSD: t_ctype2.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by YAMAMOTO Takashi + * + * 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. + */ + +/*- + * Copyright (c)2003 Citrus Project, + * All rights reserved. + * + * 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 AUTHOR 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 AUTHOR 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) 2011\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_ctype2.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $"); + +#include <errno.h> +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <vis.h> +#include <wchar.h> + +#include <atf-c.h> + +#define SIZE 256 + +static struct test { + const char *locale; + const char *data; + const wchar_t wchars[64]; + const wchar_t widths[64]; + size_t length; +} tests[] = { +{ + "C", + "ABCD01234_\\", + { 0x41, 0x42, 0x43, 0x44, 0x30, 0x31, 0x32, 0x33, 0x34, 0x5F, 0x5C }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + 11 +}, { + "en_US.UTF-8", + "[\001\177][\302\200\337\277][\340\240\200\357\277\277][\360\220\200" + "\200\367\277\277\277][\370\210\200\200\200\373\277\277\277\277][\374" + "\204\200\200\200\200\375\277\277\277\277\277]", + { 0x5b, 0x01, 0x7f, 0x5d, 0x5b, 0x80, 0x7ff, 0x5d, 0x5b, 0x800, 0xffff, + 0x5d, 0x5b, 0x10000, 0x1fffff, 0x5d, 0x5b, 0x200000, 0x3ffffff, 0x5d, + 0x5b, 0x4000000, 0x7fffffff, 0x5d }, + { 1, 1, 1, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 4, 4, 1, 1, 5, 5, 1, 1, 6, 6, 1 }, + 24 +}, { + "ja_JP.ISO2022-JP2", + "\033$BF|K\1348l\033(BA\033$B$\"\033(BB\033$B$$\033(B", + { 0x4200467c, 0x42004b5c, 0x4200386c, 0x41, 0x42002422, 0x42, 0x42002424 }, + { 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 }, + { 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 }, + { 2, 2, 2, 1, 2, 1, 2 }, + 7 +}, { + NULL, + NULL, + { }, + { }, + 0 +} +}; + +static void +h_ctype2(const struct test *t, bool use_mbstate) +{ + mbstate_t *stp; + mbstate_t st; + char buf[SIZE]; + char *str; + size_t n; + + ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); + ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL); + + (void)strvis(buf, t->data, VIS_WHITE | VIS_OCTAL); + (void)printf("Checking string: \"%s\"\n", buf); + + ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL); + (void)printf("Using locale: %s\n", str); + + (void)printf("Using mbstate: %s\n", use_mbstate ? "yes" : "no"); + + (void)memset(&st, 0, sizeof(st)); +// mbrtowc(0, 0, 0, &st); /* XXX for ISO2022-JP */ + stp = use_mbstate ? &st : 0; + + for (n = 9; n > 0; n--) { + const char *src = t->data; + wchar_t dst; + size_t nchar = 0; + int width = 0; + + ATF_REQUIRE(mbsinit(stp) != 0); + + for (;;) { + size_t rv = mbrtowc(&dst, src, n, stp); + + if (rv == 0) + break; + + if (rv == (size_t)-2) { + src += n; + width += n; + + continue; + } + if (rv == (size_t)-1) { + ATF_REQUIRE_EQ(errno, EILSEQ); + atf_tc_fail("Invalid sequence"); + /* NOTREACHED */ + } + + width += rv; + src += rv; + + if (dst != t->wchars[nchar] || + width != t->widths[nchar]) { + (void)printf("At position %zd:\n", nchar); + (void)printf(" expected: 0x%04X (%u)\n", + t->wchars[nchar], t->widths[nchar]); + (void)printf(" got : 0x%04X (%u)\n", + dst, width); + atf_tc_fail("Test failed"); + } + + nchar++; + width = 0; + } + + ATF_REQUIRE_EQ_MSG(dst, 0, "Incorrect terminating character: " + "0x%04X (expected: 0x00)", dst); + + ATF_REQUIRE_EQ_MSG(nchar, t->length, "Incorrect length: " + "%zd (expected: %zd)", nchar, t->length); + } + + { + wchar_t wbuf[SIZE]; + size_t rv; + char const *src = t->data; + int i; + + (void)memset(wbuf, 0xFF, sizeof(wbuf)); + + rv = mbsrtowcs(wbuf, &src, SIZE, stp); + + ATF_REQUIRE_EQ_MSG(rv, t->length, "Incorrect length: %zd " + "(expected: %zd)", rv, t->length); + ATF_REQUIRE_EQ(src, NULL); + + for (i = 0; wbuf[i] != 0; ++i) { + if (wbuf[i] == t->wchars[i]) + continue; + + (void)printf("At position %d:\n", i); + (void)printf(" expected: 0x%04X\n", t->wchars[i]); + (void)printf(" got : 0x%04X\n", wbuf[i]); + atf_tc_fail("Test failed"); + } + + ATF_REQUIRE_EQ_MSG((size_t)i, t->length, "Incorrect length: " + "%d (expected: %zd)", i, t->length); + } + + (void)printf("Ok.\n"); +} + +ATF_TC(ctype2_state); +ATF_TC_HEAD(ctype2_state, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks mbrtowc(3) and mbsrtowcs(3) (using state " + "object) with different locales"); +} +ATF_TC_BODY(ctype2_state, tc) +{ + struct test *t; + + for (t = &tests[0]; t->data != NULL; ++t) + h_ctype2(t, true); +} + +ATF_TC(ctype2); +ATF_TC_HEAD(ctype2, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks mbrtowc(3) and mbsrtowcs(3) (using internal " + "state) with different locales"); +} +ATF_TC_BODY(ctype2, tc) +{ + struct test *t; + + for (t = &tests[0]; t->data != NULL; ++t) + h_ctype2(t, false); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, ctype2_state); + ATF_TP_ADD_TC(tp, ctype2); + + return atf_no_error(); +} Index: src/tests/lib/libc/locale/t_mbtowc.c diff -u /dev/null src/tests/lib/libc/locale/t_mbtowc.c:1.1 --- /dev/null Sat Apr 9 17:45:25 2011 +++ src/tests/lib/libc/locale/t_mbtowc.c Sat Apr 9 17:45:25 2011 @@ -0,0 +1,143 @@ +/* $NetBSD: t_mbtowc.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * 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. + */ + +/*- + * Copyright (c)2007 Citrus Project, + * All rights reserved. + * + * 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 AUTHOR 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 AUTHOR 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) 2011\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_mbtowc.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $"); + +#include <errno.h> +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <vis.h> +#include <wchar.h> + +#include <atf-c.h> + +static void +h_mbtowc(const char *locale, const char *illegal, const char *legal) +{ + char buf[64]; + size_t stateful, ret; + char *str; + + ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); + 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" : ""); + + /* initialize internal state */ + ret = mbtowc(NULL, NULL, 0); + ATF_REQUIRE(stateful ? ret : !ret); + + (void)strvis(buf, illegal, VIS_WHITE | VIS_OCTAL); + (void)printf("Checking illegal sequence: \"%s\"\n", buf); + + ret = mbtowc(NULL, illegal, strlen(illegal)); + (void)printf("mbtowc() returned: %zd\n", ret); + ATF_REQUIRE_EQ(ret, (size_t)-1); + (void)printf("errno: %s\n", strerror(errno)); + ATF_REQUIRE_EQ(errno, EILSEQ); + + /* 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); + } + + /* valid multibyte sequence case */ + (void)strvis(buf, legal, VIS_WHITE | VIS_OCTAL); + (void)printf("Checking legal sequence: \"%s\"\n", buf); + + errno = 0; + ret = mbtowc(NULL, legal, strlen(legal)); + (void)printf("mbtowc() returned: %zd\n", ret); + ATF_REQUIRE(ret != (size_t)-1); + (void)printf("errno: %s\n", strerror(errno)); + ATF_REQUIRE_EQ(errno, 0); + + (void)printf("Ok.\n"); +} + +ATF_TC(mbtowc); +ATF_TC_HEAD(mbtowc, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks mbtowc(3)"); +} +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"); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, mbtowc); + + return atf_no_error(); +} Index: src/tests/lib/libc/locale/t_wcstod.c diff -u /dev/null src/tests/lib/libc/locale/t_wcstod.c:1.1 --- /dev/null Sat Apr 9 17:45:25 2011 +++ src/tests/lib/libc/locale/t_wcstod.c Sat Apr 9 17:45:25 2011 @@ -0,0 +1,456 @@ +/* $NetBSD: t_wcstod.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * 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. + */ + +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. + * + * 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 AUTHOR 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 AUTHOR 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) 2011\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_wcstod.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $"); + +#include <errno.h> +#include <math.h> +#include <stdlib.h> +#include <string.h> +#include <wchar.h> + +#include <atf-c.h> + +#define ALT_HUGE_VAL -1 +#define ALT_MINUS_HUGE_VAL -2 +#define ALT_NAN -3 + +#if !defined(__vax__) +static struct test { + const wchar_t *wcs; + size_t len; + double val; + int err; +} tests[] = { +{ L"IN", 0, 0, 0 }, +{ L"+IN", 0, 0, 0 }, +{ L"-IN", 0, 0, 0 }, +{ L"INX", 0, 0, 0 }, +{ L"+INX", 0, 0, 0 }, +{ L"-INX", 0, 0, 0 }, +{ L"INF", 3, ALT_HUGE_VAL, 0 }, +{ L"+INF", 4, ALT_HUGE_VAL, 0 }, +{ L"-INF", 4, ALT_MINUS_HUGE_VAL, 0 }, +{ L"INFX", 3, ALT_HUGE_VAL, 0 }, +{ L"+INFX", 4, ALT_HUGE_VAL, 0 }, +{ L"-INFX", 4, ALT_MINUS_HUGE_VAL, 0 }, +{ L" IN", 0, 0, 0 }, +{ L" +IN", 0, 0, 0 }, +{ L" -IN", 0, 0, 0 }, +{ L" INX", 0, 0, 0 }, +{ L" +INX", 0, 0, 0 }, +{ L" -INX", 0, 0, 0 }, +{ L"+ INF", 0, 0, 0 }, +{ L"- INF", 0, 0, 0 }, +{ L" INF", 8, ALT_HUGE_VAL, 0 }, +{ L" +INF", 9, ALT_HUGE_VAL, 0 }, +{ L" -INF", 9, ALT_MINUS_HUGE_VAL, 0 }, +{ L" INFX", 8, ALT_HUGE_VAL, 0 }, +{ L" +INFX", 9, ALT_HUGE_VAL, 0 }, +{ L" -INFX", 9, ALT_MINUS_HUGE_VAL, 0 }, +{ L" INFINIT", 8, ALT_HUGE_VAL, 0 }, +{ L" +INFINIT", 9, ALT_HUGE_VAL, 0 }, +{ L" -INFINIT", 9, ALT_MINUS_HUGE_VAL, 0 }, +{ L" INFINITY", 13, ALT_HUGE_VAL, 0 }, +{ L" +INFINITY", 14, ALT_HUGE_VAL, 0 }, +{ L" -INFINITY", 14, ALT_MINUS_HUGE_VAL, 0 }, +{ L" INFINITYX", 13, ALT_HUGE_VAL, 0 }, +{ L" +INFINITYX", 14, ALT_HUGE_VAL, 0 }, +{ L" -INFINITYX", 14, ALT_MINUS_HUGE_VAL, 0 }, + +/* NAN */ +{ L"NA", 0, 0, 0 }, +{ L"+NA", 0, 0, 0 }, +{ L"-NA", 0, 0, 0 }, +{ L"NAX", 0, 0, 0 }, +{ L"+NAX", 0, 0, 0 }, +{ L"-NAX", 0, 0, 0 }, +{ L"NAN", 3, ALT_NAN, 0 }, +{ L"+NAN", 4, ALT_NAN, 0 }, +{ L"-NAN", 4, ALT_NAN, 0 }, +{ L"NANX", 3, ALT_NAN, 0 }, +{ L"+NANX", 4, ALT_NAN, 0 }, +{ L"-NANX", 4, ALT_NAN, 0 }, +{ L" NA", 0, 0, 0 }, +{ L" +NA", 0, 0, 0 }, +{ L" -NA", 0, 0, 0 }, +{ L" NAX", 0, 0, 0 }, +{ L" +NAX", 0, 0, 0 }, +{ L" -NAX", 0, 0, 0 }, +{ L"+ NAN", 0, 0, 0 }, +{ L"- NAN", 0, 0, 0 }, +{ L" NAN", 8, ALT_NAN, 0 }, +{ L" +NAN", 9, ALT_NAN, 0 }, +{ L" -NAN", 9, ALT_NAN, 0 }, +{ L" NANX", 8, ALT_NAN, 0 }, +{ L" +NANX", 9, ALT_NAN, 0 }, +{ L" -NANX", 9, ALT_NAN, 0 }, + +{ L"0", 1, 0, 0 }, +{ L"+0", 2, 0, 0 }, +{ L"-0", 2, 0, 0 }, +{ L" 0", 11, 0, 0 }, +{ L" +0", 12, 0, 0 }, +{ L" -0", 12, 0, 0 }, +{ L"+ 0", 0, 0, 0 }, +{ L"- 0", 0, 0, 0 }, + +{ L".", 0, 0, 0 }, +{ L".0", 2, 0, 0 }, +{ L".00", 3, 0, 0 }, +{ L".000", 4, 0, 0 }, + +{ L"0.", 2, 0, 0 }, +{ L"+0.", 3, 0, 0 }, +{ L"-0.", 3, 0, 0 }, +{ L" 0.", 12, 0, 0 }, +{ L" +0.", 13, 0, 0 }, +{ L" -0.", 13, 0, 0 }, + +{ L"0.0", 3, 0, 0 }, +{ L"+0.0", 4, 0, 0 }, +{ L"-0.0", 4, 0, 0 }, +{ L" 0.0", 13, 0, 0 }, +{ L" +0.0", 14, 0, 0 }, +{ L" -0.0", 14, 0, 0 }, + +{ L"000", 3, 0, 0 }, +{ L"+000", 4, 0, 0 }, +{ L"-000", 4, 0, 0 }, +{ L" 000", 13, 0, 0 }, +{ L" +000", 14, 0, 0 }, +{ L" -000", 14, 0, 0 }, + +{ L"000.", 4, 0, 0 }, +{ L"+000.", 5, 0, 0 }, +{ L"-000.", 5, 0, 0 }, +{ L" 000.", 14, 0, 0 }, +{ L" +000.", 15, 0, 0 }, +{ L" -000.", 15, 0, 0 }, + +{ L"000.0", 5, 0, 0 }, +{ L"+000.0", 6, 0, 0 }, +{ L"-000.0", 6, 0, 0 }, +{ L" 000.0", 15, 0, 0 }, +{ L" +000.0", 16, 0, 0 }, +{ L" -000.0", 16, 0, 0 }, + + +{ L"0.0.", 3, 0, 0 }, +{ L"+0.0.", 4, 0, 0 }, +{ L"-0.0.", 4, 0, 0 }, +{ L" 0.0.", 13, 0, 0 }, +{ L" +0.0.", 14, 0, 0 }, +{ L" -0.0.", 14, 0, 0 }, + +{ L"0.0.0", 3, 0, 0 }, +{ L"+0.0.0", 4, 0, 0 }, +{ L"-0.0.0", 4, 0, 0 }, +{ L" 0.0.0", 13, 0, 0 }, +{ L" +0.0.0", 14, 0, 0 }, +{ L" -0.0.0", 14, 0, 0 }, + +/* XXX: FIXME */ +#if defined(__linux__) +{ L"0X", 2, 0, 0 }, +{ L"+0X", 3, 0, 0 }, +{ L"-0X", 3, 0, 0 }, +#else +{ L"0X", 1, 0, 0 }, +{ L"+0X", 2, 0, 0 }, +{ L"-0X", 2, 0, 0 }, +#endif + +/* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */ +#if !defined(__SunOS__) +#if defined(__linux__) +{ L"0X.", 3, 0, 0 }, +{ L"+0X.", 4, 0, 0 }, +{ L"-0X.", 4, 0, 0 }, +{ L" 0X.", 13, 0, 0 }, +{ L" +0X.", 14, 0, 0 }, +{ L" -0X.", 14, 0, 0 }, +#else +{ L"0X.", 1, 0, 0 }, +{ L"+0X.", 2, 0, 0 }, +{ L"-0X.", 2, 0, 0 }, +{ L" 0X.", 11, 0, 0 }, +{ L" +0X.", 12, 0, 0 }, +{ L" -0X.", 12, 0, 0 }, +#endif +/* XXX: FIXME */ +#if defined(__NetBSD__) || defined(__linux__) +{ L"0X.0", 4, 0, 0 }, +{ L"+0X.0", 5, 0, 0 }, +{ L"-0X.0", 5, 0, 0 }, +{ L" 0X.0", 14, 0, 0 }, +{ L" +0X.0", 15, 0, 0 }, +{ L" -0X.0", 15, 0, 0 }, + +{ L"0X.0P", 4, 0, 0 }, +{ L"+0X.0P", 5, 0, 0 }, +{ L"-0X.0P", 5, 0, 0 }, +{ L" 0X.0P", 14, 0, 0 }, +{ L" +0X.0P", 15, 0, 0 }, +{ L" -0X.0P", 15, 0, 0 }, +#else +{ L"0X.0", 1, 0, 0 }, +{ L"+0X.0", 2, 0, 0 }, +{ L"-0X.0", 2, 0, 0 }, +{ L" 0X.0", 11, 0, 0 }, +{ L" +0X.0", 12, 0, 0 }, +{ L" -0X.0", 12, 0, 0 }, + +{ L"0X.0P", 1, 0, 0 }, +{ L"+0X.0P", 2, 0, 0 }, +{ L"-0X.0P", 2, 0, 0 }, +{ L" 0X.0P", 11, 0, 0 }, +{ L" +0X.0P", 12, 0, 0 }, +{ L" -0X.0P", 12, 0, 0 }, +#endif + +{ L"0X0", 3, 0, 0 }, +{ L"+0X0", 4, 0, 0 }, +{ L"-0X0", 4, 0, 0 }, +{ L" 0X0", 13, 0, 0 }, +{ L" +0X0", 14, 0, 0 }, +{ L" -0X0", 14, 0, 0 }, + +{ L"00X0.0", 2, 0, 0 }, +{ L"+00X0.0", 3, 0, 0 }, +{ L"-00X0.0", 3, 0, 0 }, +{ L" 00X0.0", 12, 0, 0 }, +{ L" +00X0.0", 13, 0, 0 }, +{ L" -00X0.0", 13, 0, 0 }, + +{ L"0X0P", 3, 0, 0 }, +{ L"+0X0P", 4, 0, 0 }, +{ L"-0X0P", 4, 0, 0 }, +{ L" 0X0P", 13, 0, 0 }, +{ L" +0X0P", 14, 0, 0 }, +{ L" -0X0P", 14, 0, 0 }, + +{ L"0X0.", 4, 0, 0 }, +{ L"+0X0.", 5, 0, 0 }, +{ L"-0X0.", 5, 0, 0 }, +{ L" 0X0.", 14, 0, 0 }, +{ L" +0X0.", 15, 0, 0 }, +{ L" -0X0.", 15, 0, 0 }, + +{ L"0X0.0", 5, 0, 0 }, +{ L"+0X0.0", 6, 0, 0 }, +{ L"-0X0.0", 6, 0, 0 }, +{ L" 0X0.0", 15, 0, 0 }, +{ L" +0X0.0", 16, 0, 0 }, +{ L" -0X0.0", 16, 0, 0 }, + +{ L"0X0.P", 4, 0, 0 }, +{ L"+0X0.P", 5, 0, 0 }, +{ L"-0X0.P", 5, 0, 0 }, +{ L" 0X0.P", 14, 0, 0 }, +{ L" +0X0.P", 15, 0, 0 }, +{ L" -0X0.P", 15, 0, 0 }, + +{ L"0X0.P", 4, 0, 0 }, +{ L"+0X0.P", 5, 0, 0 }, +{ L"-0X0.P", 5, 0, 0 }, +{ L" 0X0.P", 14, 0, 0 }, +{ L" +0X0.P", 15, 0, 0 }, +{ L" -0X0.P", 15, 0, 0 }, + +#endif +{ L"0.12345678", 10, 0.12345678, 0 }, +{ L"+0.12345678", 11, +0.12345678, 0 }, +{ L"-0.12345678", 11, -0.12345678, 0 }, +{ L" 0.12345678", 15, 0.12345678, 0 }, +{ L" +0.12345678", 16, +0.12345678, 0 }, +{ L" -0.12345678", 16, -0.12345678, 0 }, + +{ L"0.12345E67", 10, 0.12345E67, 0 }, +{ L"+0.12345E67", 11, +0.12345E67, 0 }, +{ L"-0.12345E67", 11, -0.12345E67, 0 }, +{ L" 0.12345E67", 15, 0.12345E67, 0 }, +{ L" +0.12345E67", 16, +0.12345E67, 0 }, +{ L" -0.12345E67", 16, -0.12345E67, 0 }, + +{ L"0.12345E+6", 10, 0.12345E+6, 0 }, +{ L"+0.12345E+6", 11, +0.12345E+6, 0 }, +{ L"-0.12345E+6", 11, -0.12345E+6, 0 }, +{ L" 0.12345E+6", 15, 0.12345E+6, 0 }, +{ L" +0.12345E+6", 16, +0.12345E+6, 0 }, +{ L" -0.12345E+6", 16, -0.12345E+6, 0 }, + +{ L"0.98765E-4", 10, 0.98765E-4, 0 }, +{ L"+0.98765E-4", 11, +0.98765E-4, 0 }, +{ L"-0.98765E-4", 11, -0.98765E-4, 0 }, +{ L" 0.98765E-4", 15, 0.98765E-4, 0 }, +{ L" +0.98765E-4", 16, +0.98765E-4, 0 }, +{ L" -0.98765E-4", 16, -0.98765E-4, 0 }, + +{ L"12345678E9", 10, 12345678E9, 0 }, +{ L"+12345678E9", 11, +12345678E9, 0 }, +{ L"-12345678E9", 11, -12345678E9, 0 }, +{ L" 12345678E9", 15, 12345678E9, 0 }, +{ L" +12345678E9", 16, +12345678E9, 0 }, +{ L" -12345678E9", 16, -12345678E9, 0 }, + +/* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */ +#if !defined(__SunOS__) +{ L"0x1P+2", 6, 4, 0 }, +{ L"+0x1P+2", 7, +4, 0 }, +{ L"-0x1P+2", 7, -4, 0 }, +{ L" 0x1P+2", 11, 4, 0 }, +{ L" +0x1P+2", 12, +4, 0 }, +{ L" -0x1P+2", 12, -4, 0 }, + +{ L"0x1.0P+2", 8, 4, 0 }, +{ L"+0x1.0P+2", 9, +4, 0 }, +{ L"-0x1.0P+2", 9, -4, 0 }, +{ L" 0x1.0P+2", 13, 4, 0 }, +{ L" +0x1.0P+2", 14, +4, 0 }, +{ L" -0x1.0P+2", 14, -4, 0 }, + +{ L"0x1P-2", 6, 0.25, 0 }, +{ L"+0x1P-2", 7, +0.25, 0 }, +{ L"-0x1P-2", 7, -0.25, 0 }, +{ L" 0x1P-2", 11, 0.25, 0 }, +{ L" +0x1P-2", 12, +0.25, 0 }, +{ L" -0x1P-2", 12, -0.25, 0 }, + +{ L"0x1.0P-2", 8, 0.25, 0 }, +{ L"+0x1.0P-2", 9, +0.25, 0 }, +{ L"-0x1.0P-2", 9, -0.25, 0 }, +{ L" 0x1.0P-2", 13, 0.25, 0 }, +{ L" +0x1.0P-2", 14, +0.25, 0 }, +{ L" -0x1.0P-2", 14, -0.25, 0 }, +#endif + +{ NULL, 0, 0, 0 } +}; +#endif /* !defined(__vax__) */ + +ATF_TC(wcstod); +ATF_TC_HEAD(wcstod, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks wcstod(3)"); +} +ATF_TC_BODY(wcstod, tc) +{ +#if defined(__vax__) +#else + struct test *t; +#endif + +#if !defined(__vax__) + for (t = &tests[0]; t->wcs != NULL; ++t) { + double d; + size_t n; + wchar_t *tail; + char *buf; + + /* we do not supported %ls nor %S yet. */ + n = wcstombs(NULL, t->wcs, 0); + ATF_REQUIRE((buf = (void *)malloc(n + 1)) != NULL); + (void)wcstombs(buf, t->wcs, n + 1); + (void)printf("Checking wcstod(\"%s\", &tail):\n", buf); + free(buf); + + errno = 0; + d = wcstod(t->wcs, &tail); + (void)printf("[errno]\n"); + (void)printf(" got : %s\n", strerror(errno)); + (void)printf(" expected: %s\n", strerror(t->err)); + ATF_REQUIRE_EQ(errno, t->err); + + n = (size_t)(tail - t->wcs); + (void)printf("[endptr - nptr]\n"); + (void)printf(" got : %zd\n", n); + (void)printf(" expected: %zd\n", t->len); + ATF_REQUIRE_EQ(n, t->len); + + (void)printf("[result]\n"); + (void)printf(" real: %F\n", d); + if (t->val == ALT_HUGE_VAL) { + (void)printf(" expected: %F\n", HUGE_VAL); + ATF_REQUIRE(isinf(d)); + ATF_REQUIRE_EQ(d, HUGE_VAL); + } else if (t->val == ALT_MINUS_HUGE_VAL) { + (void)printf(" expected: %F\n", -HUGE_VAL); + ATF_REQUIRE(isinf(d)); + ATF_REQUIRE_EQ(d, -HUGE_VAL); + } else if (t->val == ALT_NAN) { + (void)printf(" expected: %F\n", NAN); + ATF_REQUIRE(isnan(d)); + } else { + (void)printf(" expected: %F\n", t->val); + ATF_REQUIRE_EQ(d, t->val); + } + + (void)printf("\n"); + } +#else /* !defined(__vax__) */ + atf_tc_skip("Test is unavailable on vax."); +#endif /* !defined(__vax__) */ +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, wcstod); + + return atf_no_error(); +} Index: src/tests/lib/libc/locale/t_wctomb.c diff -u /dev/null src/tests/lib/libc/locale/t_wctomb.c:1.1 --- /dev/null Sat Apr 9 17:45:25 2011 +++ src/tests/lib/libc/locale/t_wctomb.c Sat Apr 9 17:45:25 2011 @@ -0,0 +1,204 @@ +/* $NetBSD: t_wctomb.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * 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. + */ + +/*- + * Copyright (c)2004 Citrus Project, + * All rights reserved. + * + * 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 AUTHOR 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 AUTHOR 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) 2011\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_wctomb.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $"); + +#include <stdio.h> +#include <stdlib.h> +#include <locale.h> +#include <vis.h> +#include <wchar.h> +#include <string.h> + +#include <atf-c.h> + +#define TC_WCTOMB 0 +#define TC_WCRTOMB 1 +#define TC_WCRTOMB_ST 2 + +static struct test { + const char *locale; + const char *data; + size_t wclen; + size_t mblen[16]; +} tests[] = { +{ + "ja_JP.ISO2022-JP", + "\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 */ + 3 + 3 + 3, + { 3+2, 2, 2, 3+1, 1, 1, 3+1, 1, 1, 3+1 } +}, { + "C", + "ABC", + 3, + { 1, 1, 1, 1 } +}, { NULL, NULL, 0, { } } +}; + +static void +h_wctomb(const struct test *t, char tc) +{ + wchar_t wcs[16 + 2]; + char buf[128]; + char cs[MB_CUR_MAX]; + const char *pcs; + char *str; + mbstate_t st; + mbstate_t *stp = NULL; + size_t sz, ret, i; + + ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); + ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL); + + (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); + ATF_REQUIRE_EQ_MSG(sz, t->wclen, "mbsrtowcs() returned: " + "%d, expected: %d", sz, t->wclen); + ATF_REQUIRE_EQ(wcs[t->wclen], 0); + + for (i = 0; i < t->wclen + 1; i++) { + if (tc == TC_WCTOMB) + ret = wctomb(cs, wcs[i]); + else + ret = wcrtomb(cs, wcs[i], stp); + + if (ret == t->mblen[i]) + continue; + + (void)printf("At position %zd:\n", i); + (void)printf(" expected: %zd\n", t->mblen[i]); + (void)printf(" got : %zd\n", ret); + atf_tc_fail("Test failed"); + /* NOTREACHED */ + } + + (void)printf("Ok.\n"); +} + +ATF_TC(wctomb); +ATF_TC_HEAD(wctomb, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks wctomb(3)"); +} +ATF_TC_BODY(wctomb, tc) +{ + struct test *t; + + (void)printf("Checking wctomb()\n"); + + for (t = &tests[0]; t->data != NULL; ++t) + h_wctomb(t, TC_WCTOMB); +} + +ATF_TC(wcrtomb_state); +ATF_TC_HEAD(wcrtomb_state, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks wcrtomb(3) (using state object)"); +} +ATF_TC_BODY(wcrtomb_state, tc) +{ + struct test *t; + + (void)printf("Checking wcrtomb() (with state object)\n"); + + for (t = &tests[0]; t->data != NULL; ++t) + h_wctomb(t, TC_WCRTOMB_ST); +} + +ATF_TC(wcrtomb); +ATF_TC_HEAD(wcrtomb, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks wcrtomb(3) (using internal state)"); +} +ATF_TC_BODY(wcrtomb, tc) +{ + struct test *t; + + (void)printf("Checking wcrtomb() (using internal state)\n"); + + for (t = &tests[0]; t->data != NULL; ++t) + h_wctomb(t, TC_WCRTOMB); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, wctomb); + ATF_TP_ADD_TC(tp, wcrtomb); + ATF_TP_ADD_TC(tp, wcrtomb_state); + + return atf_no_error(); +}