Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src atf-ify the various locale tests



details:   https://anonhg.NetBSD.org/src/rev/035248a52e7f
branches:  trunk
changeset: 763976:035248a52e7f
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat Apr 09 17:45:24 2011 +0000

description:
atf-ify the various locale tests

diffstat:

 distrib/sets/lists/tests/mi      |   15 +-
 etc/mtree/NetBSD.dist.tests      |    4 +-
 tests/lib/libc/Makefile          |    4 +-
 tests/lib/libc/locale/Makefile   |   13 +
 tests/lib/libc/locale/t_ctype1.c |  202 +++++++++++++++++
 tests/lib/libc/locale/t_ctype2.c |  266 ++++++++++++++++++++++
 tests/lib/libc/locale/t_mbtowc.c |  143 ++++++++++++
 tests/lib/libc/locale/t_wcstod.c |  456 +++++++++++++++++++++++++++++++++++++++
 tests/lib/libc/locale/t_wctomb.c |  204 +++++++++++++++++
 9 files changed, 1303 insertions(+), 4 deletions(-)

diffs (truncated from 1386 to 300 lines):

diff -r ccb34f00377e -r 035248a52e7f distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Apr 09 17:25:28 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Apr 09 17:45:24 2011 +0000
@@ -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
diff -r ccb34f00377e -r 035248a52e7f etc/mtree/NetBSD.dist.tests
--- a/etc/mtree/NetBSD.dist.tests       Sat Apr 09 17:25:28 2011 +0000
+++ b/etc/mtree/NetBSD.dist.tests       Sat Apr 09 17:45:24 2011 +0000
@@ -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
diff -r ccb34f00377e -r 035248a52e7f tests/lib/libc/Makefile
--- a/tests/lib/libc/Makefile   Sat Apr 09 17:25:28 2011 +0000
+++ b/tests/lib/libc/Makefile   Sat Apr 09 17:45:24 2011 +0000
@@ -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"
diff -r ccb34f00377e -r 035248a52e7f tests/lib/libc/locale/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/locale/Makefile    Sat Apr 09 17:45:24 2011 +0000
@@ -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>
diff -r ccb34f00377e -r 035248a52e7f tests/lib/libc/locale/t_ctype1.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/locale/t_ctype1.c  Sat Apr 09 17:45:24 2011 +0000
@@ -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();



Home | Main Index | Thread Index | Old Index