Author: ngie
Date: Mon Nov 23 08:31:41 2015
New Revision: 291178
URL: https://svnweb.freebsd.org/changeset/base/291178

Log:
  MFC r290532,r290561,r290843,r290844,r290845:
  
  r290532:
  
  Integrate tools/regression/lib/libc/locale into the FreeBSD test suite
  as lib/libc/tests/locale
  
  Sponsored by: EMC / Isilon Storage Division
  
  r290561:
  
  Delete leftover printfs from when these were TAP tests
  
  Sponsored by: EMC / Isilon Storage Division
  
  r290843:
  
  Polish up the tests a bit more after projects/collation was merged to head
  
  Provide more meaningful diagnostic messages if LC_CTYPE can't be set properly
  instead of segfaulting, because setlocale returns NULL and strcmp(NULL, b) 
will
  always segfault
  
  Split up the testcases so one failing (in this case en_US.ISO8859-15) won't
  cause the rest of the testcases to be skipped
  
  Remove some unused variables
  
  Sponsored by: EMC / Isilon Storage Division
  
  r290844:
  
  Polish up iswctype_test
  
  - Split up the testcases into C locale and ja_JP.eucJP testcases.
  - Avoid a segfault in the event that setlocale fails, similar to r290843
  - Replace `sizeof(x) / sizeof(*x)` pattern with `nitems(x)`
  
  Sponsored by: EMC / Isilon Storage Division
  
  r290845:
  
  Remove unused variables; sort by alignment where needed
  
  Sponsored by: EMC / Isilon Storage Division

Added:
  stable/10/lib/libc/tests/locale/btowc_test.c
     - copied unchanged from r290532, head/lib/libc/tests/locale/btowc_test.c
  stable/10/lib/libc/tests/locale/c16rtomb_test.c
     - copied, changed from r290532, head/lib/libc/tests/locale/c16rtomb_test.c
  stable/10/lib/libc/tests/locale/iswctype_test.c
     - copied, changed from r290532, head/lib/libc/tests/locale/iswctype_test.c
  stable/10/lib/libc/tests/locale/mblen_test.c
     - copied, changed from r290532, head/lib/libc/tests/locale/mblen_test.c
  stable/10/lib/libc/tests/locale/mbrlen_test.c
     - copied, changed from r290532, head/lib/libc/tests/locale/mbrlen_test.c
  stable/10/lib/libc/tests/locale/mbrtoc16_test.c
     - copied, changed from r290532, head/lib/libc/tests/locale/mbrtoc16_test.c
  stable/10/lib/libc/tests/locale/mbrtowc_test.c
     - copied, changed from r290532, head/lib/libc/tests/locale/mbrtowc_test.c
  stable/10/lib/libc/tests/locale/mbsnrtowcs_test.c
     - copied unchanged from r290532, 
head/lib/libc/tests/locale/mbsnrtowcs_test.c
  stable/10/lib/libc/tests/locale/mbsrtowcs_test.c
     - copied, changed from r290532, head/lib/libc/tests/locale/mbsrtowcs_test.c
  stable/10/lib/libc/tests/locale/mbstowcs_test.c
     - copied unchanged from r290532, head/lib/libc/tests/locale/mbstowcs_test.c
  stable/10/lib/libc/tests/locale/mbtowc_test.c
     - copied, changed from r290532, head/lib/libc/tests/locale/mbtowc_test.c
  stable/10/lib/libc/tests/locale/towctrans_test.c
     - copied unchanged from r290532, 
head/lib/libc/tests/locale/towctrans_test.c
  stable/10/lib/libc/tests/locale/wcrtomb_test.c
     - copied unchanged from r290532, head/lib/libc/tests/locale/wcrtomb_test.c
  stable/10/lib/libc/tests/locale/wcsnrtombs_test.c
     - copied unchanged from r290532, 
head/lib/libc/tests/locale/wcsnrtombs_test.c
  stable/10/lib/libc/tests/locale/wcsrtombs_test.c
     - copied unchanged from r290532, 
head/lib/libc/tests/locale/wcsrtombs_test.c
  stable/10/lib/libc/tests/locale/wcstombs_test.c
     - copied unchanged from r290532, head/lib/libc/tests/locale/wcstombs_test.c
  stable/10/lib/libc/tests/locale/wctomb_test.c
     - copied unchanged from r290532, head/lib/libc/tests/locale/wctomb_test.c
Deleted:
  stable/10/tools/regression/lib/libc/locale/
Modified:
  stable/10/lib/libc/tests/locale/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/tests/locale/Makefile
==============================================================================
--- stable/10/lib/libc/tests/locale/Makefile    Mon Nov 23 08:26:26 2015        
(r291177)
+++ stable/10/lib/libc/tests/locale/Makefile    Mon Nov 23 08:31:41 2015        
(r291178)
@@ -4,6 +4,24 @@
 
 TESTSDIR=      ${TESTSBASE}/lib/libc/locale
 
+ATF_TESTS_C+=          btowc_test
+ATF_TESTS_C+=          c16rtomb_test
+ATF_TESTS_C+=          iswctype_test
+ATF_TESTS_C+=          mblen_test
+ATF_TESTS_C+=          mbrlen_test
+ATF_TESTS_C+=          mbrtoc16_test
+ATF_TESTS_C+=          mbrtowc_2_test
+ATF_TESTS_C+=          mbsnrtowcs_2_test
+ATF_TESTS_C+=          mbsrtowcs_test
+ATF_TESTS_C+=          mbstowcs_2_test
+ATF_TESTS_C+=          mbtowc_2_test
+ATF_TESTS_C+=          towctrans_test
+ATF_TESTS_C+=          wcrtomb_test
+ATF_TESTS_C+=          wcsnrtombs_test
+ATF_TESTS_C+=          wcsrtombs_test
+ATF_TESTS_C+=          wcstombs_test
+ATF_TESTS_C+=          wctomb_2_test
+
 NETBSD_ATF_TESTS_C=    io_test
 NETBSD_ATF_TESTS_C+=   mbrtowc_test
 NETBSD_ATF_TESTS_C+=   mbstowcs_test
@@ -15,7 +33,13 @@ NETBSD_ATF_TESTS_C+= wcsspn_test
 NETBSD_ATF_TESTS_C+=   wcstod_test
 NETBSD_ATF_TESTS_C+=   wctomb_test
 
-CFLAGS.t_wctomb.c+= -Wno-stack-protector
+SRCS.mbrtowc_2_test=   mbrtowc_test.c
+SRCS.mbsnrtowcs_2_test=        mbsnrtowcs_test.c
+SRCS.mbstowcs_2_test=  mbstowcs_test.c
+SRCS.mbtowc_2_test=    mbtowc_test.c
+SRCS.wctomb_2_test=    wctomb_test.c
+
+CFLAGS.t_wctomb.c+=    -Wno-stack-protector
 
 .include "../Makefile.netbsd-tests"
 

Copied: stable/10/lib/libc/tests/locale/btowc_test.c (from r290532, 
head/lib/libc/tests/locale/btowc_test.c)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/lib/libc/tests/locale/btowc_test.c        Mon Nov 23 08:31:41 
2015        (r291178, copy of r290532, head/lib/libc/tests/locale/btowc_test.c)
@@ -0,0 +1,71 @@
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * 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.
+ */
+
+/*
+ * Test program for btowc() and wctob() as specified by IEEE Std. 1003.1-2001
+ * and ISO/IEC 9899:1999.
+ *
+ * The function is tested in the "C" and "ja_JP.eucJP" locales.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(btowc_test);
+ATF_TC_BODY(btowc_test, tc)
+{
+       int i;
+
+       /* C/POSIX locale. */
+       ATF_REQUIRE(btowc(EOF) == WEOF);
+       ATF_REQUIRE(wctob(WEOF) == EOF);
+       for (i = 0; i < UCHAR_MAX; i++)
+               ATF_REQUIRE(btowc(i) == (wchar_t)i && i == (int)wctob(i));
+
+       /* Japanese (EUC) locale. */
+       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") 
== 0);
+       ATF_REQUIRE(MB_CUR_MAX > 1);
+       ATF_REQUIRE(btowc('A') == L'A' && wctob(L'A') == 'A');
+       ATF_REQUIRE(btowc(0xa3) == WEOF && wctob(0xa3c1) == EOF);
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, btowc_test);
+
+       return (atf_no_error());
+}

Copied and modified: stable/10/lib/libc/tests/locale/c16rtomb_test.c (from 
r290532, head/lib/libc/tests/locale/c16rtomb_test.c)
==============================================================================
--- head/lib/libc/tests/locale/c16rtomb_test.c  Sun Nov  8 02:06:17 2015        
(r290532, copy source)
+++ stable/10/lib/libc/tests/locale/c16rtomb_test.c     Mon Nov 23 08:31:41 
2015        (r291178)
@@ -42,13 +42,27 @@ __FBSDID("$FreeBSD$");
 
 #include <atf-c.h>
 
-ATF_TC_WITHOUT_HEAD(c16rtomb_test);
-ATF_TC_BODY(c16rtomb_test, tc)
+static void
+require_lc_ctype(const char *locale_name)
 {
-       mbstate_t s;
-       char buf[MB_LEN_MAX + 1];
+       char *lc_ctype_set;
 
-       /* C/POSIX locale. */
+       lc_ctype_set = setlocale(LC_CTYPE, locale_name);
+       if (lc_ctype_set == NULL)
+               atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d",
+                   locale_name, errno);
+
+       ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0);
+}
+
+static mbstate_t s;
+static char buf[MB_LEN_MAX + 1];
+
+ATF_TC_WITHOUT_HEAD(c16rtomb_c_locale_test);
+ATF_TC_BODY(c16rtomb_c_locale_test, tc)
+{
+
+       require_lc_ctype("C");
 
        /*
         * If the buffer argument is NULL, c16 is implicitly 0,
@@ -80,11 +94,13 @@ ATF_TC_BODY(c16rtomb_test, tc)
        ATF_REQUIRE(c16rtomb(buf, 0xdca9, &s) == (size_t)-1);
        ATF_REQUIRE(errno == EILSEQ);
        ATF_REQUIRE((unsigned char)buf[0] == 0xcc);
+}
 
-       /* ISO8859-1. */
+ATF_TC_WITHOUT_HEAD(c16rtomb_iso_8859_1_test);
+ATF_TC_BODY(c16rtomb_iso_8859_1_test, tc)
+{
 
-       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-1"),
-           "en_US.ISO8859-1") == 0);
+       require_lc_ctype("en_US.ISO8859-1");
 
        /* Unicode character 'Euro sign'. */
        memset(&s, 0, sizeof(s));
@@ -92,21 +108,26 @@ ATF_TC_BODY(c16rtomb_test, tc)
        ATF_REQUIRE(c16rtomb(buf, 0x20ac, &s) == (size_t)-1);
        ATF_REQUIRE(errno == EILSEQ);
        ATF_REQUIRE((unsigned char)buf[0] == 0xcc);
+}
 
-       /* ISO8859-15. */
+ATF_TC_WITHOUT_HEAD(c16rtomb_iso_8859_15_test);
+ATF_TC_BODY(c16rtomb_iso_8859_15_test, tc)
+{
 
-       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-15"),
-           "en_US.ISO8859-15") == 0);
+       require_lc_ctype("en_US.ISO8859-15");
 
        /* Unicode character 'Euro sign'. */
        memset(&s, 0, sizeof(s));
        memset(buf, 0xcc, sizeof(buf));
        ATF_REQUIRE(c16rtomb(buf, 0x20ac, &s) == 1);
        ATF_REQUIRE((unsigned char)buf[0] == 0xa4 && (unsigned char)buf[1] == 
0xcc);
+}
 
-       /* UTF-8. */
+ATF_TC_WITHOUT_HEAD(c16rtomb_utf_8_test);
+ATF_TC_BODY(c16rtomb_utf_8_test, tc)
+{
 
-       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.UTF-8"), "en_US.UTF-8") 
== 0);
+       require_lc_ctype("en_US.UTF-8");
 
        /* Unicode character 'Pile of poo'. */
        memset(&s, 0, sizeof(s));
@@ -136,7 +157,10 @@ ATF_TC_BODY(c16rtomb_test, tc)
 ATF_TP_ADD_TCS(tp)
 {
 
-       ATF_TP_ADD_TC(tp, c16rtomb_test);
+       ATF_TP_ADD_TC(tp, c16rtomb_c_locale_test);
+       ATF_TP_ADD_TC(tp, c16rtomb_iso_8859_1_test);
+       ATF_TP_ADD_TC(tp, c16rtomb_iso_8859_15_test);
+       ATF_TP_ADD_TC(tp, c16rtomb_utf_8_test);
 
        return (atf_no_error());
 }

Copied and modified: stable/10/lib/libc/tests/locale/iswctype_test.c (from 
r290532, head/lib/libc/tests/locale/iswctype_test.c)
==============================================================================
--- head/lib/libc/tests/locale/iswctype_test.c  Sun Nov  8 02:06:17 2015        
(r290532, copy source)
+++ stable/10/lib/libc/tests/locale/iswctype_test.c     Mon Nov 23 08:31:41 
2015        (r291178)
@@ -34,6 +34,8 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <sys/param.h>
+#include <errno.h>
 #include <locale.h>
 #include <stdio.h>
 #include <string.h>
@@ -42,31 +44,45 @@ __FBSDID("$FreeBSD$");
 
 #include <atf-c.h>
 
-ATF_TC_WITHOUT_HEAD(iswctype_test);
-ATF_TC_BODY(iswctype_test, tc)
+static void
+require_lc_ctype(const char *locale_name)
 {
-       wctype_t t;
-       int i, j;
-       struct {
-               const char *name;
-               int (*func)(wint_t);
-       } cls[] = {
-               { "alnum", iswalnum },
-               { "alpha", iswalpha },
-               { "blank", iswblank },
-               { "cntrl", iswcntrl },
-               { "digit", iswdigit },
-               { "graph", iswgraph },
-               { "lower", iswlower },
-               { "print", iswprint },
-               { "punct", iswpunct },
-               { "space", iswspace },
-               { "upper", iswupper },
-               { "xdigit", iswxdigit }
-       };
+       char *lc_ctype_set;
 
-       /* C/POSIX locale. */
-       for (i = 0; i < sizeof(cls) / sizeof(*cls); i++) {
+       lc_ctype_set = setlocale(LC_CTYPE, locale_name);
+       if (lc_ctype_set == NULL)
+               atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d",
+                   locale_name, errno);
+
+       ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0);
+}
+
+static wctype_t t;
+static int i, j;
+static struct {
+       const char *name;
+       int (*func)(wint_t);
+} cls[] = {
+       { "alnum", iswalnum },
+       { "alpha", iswalpha },
+       { "blank", iswblank },
+       { "cntrl", iswcntrl },
+       { "digit", iswdigit },
+       { "graph", iswgraph },
+       { "lower", iswlower },
+       { "print", iswprint },
+       { "punct", iswpunct },
+       { "space", iswspace },
+       { "upper", iswupper },
+       { "xdigit", iswxdigit }
+};
+
+ATF_TC_WITHOUT_HEAD(iswctype_c_locale_test);
+ATF_TC_BODY(iswctype_c_locale_test, tc)
+{
+
+       require_lc_ctype("C");
+       for (i = 0; i < nitems(cls); i++) {
                t = wctype(cls[i].name);
                ATF_REQUIRE(t != 0);
                for (j = 0; j < 256; j++)
@@ -76,10 +92,15 @@ ATF_TC_BODY(iswctype_test, tc)
        ATF_REQUIRE(t == 0);
        for (i = 0; i < 256; i++)
                ATF_REQUIRE(iswctype(i, t) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(iswctype_euc_jp_test);
+ATF_TC_BODY(iswctype_euc_jp_test, tc)
+{
+
+       require_lc_ctype("ja_JP.eucJP");
 
-       /* Japanese (EUC) locale. */
-       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") 
== 0);
-       for (i = 0; i < sizeof(cls) / sizeof(*cls); i++) {
+       for (i = 0; i < nitems(cls); i++) {
                t = wctype(cls[i].name);
                ATF_REQUIRE(t != 0);
                for (j = 0; j < 65536; j++)
@@ -94,7 +115,8 @@ ATF_TC_BODY(iswctype_test, tc)
 ATF_TP_ADD_TCS(tp)
 {
 
-       ATF_TP_ADD_TC(tp, iswctype_test);
+       ATF_TP_ADD_TC(tp, iswctype_c_locale_test);
+       ATF_TP_ADD_TC(tp, iswctype_euc_jp_test);
 
        return (atf_no_error());
 }

Copied and modified: stable/10/lib/libc/tests/locale/mblen_test.c (from 
r290532, head/lib/libc/tests/locale/mblen_test.c)
==============================================================================
--- head/lib/libc/tests/locale/mblen_test.c     Sun Nov  8 02:06:17 2015        
(r290532, copy source)
+++ stable/10/lib/libc/tests/locale/mblen_test.c        Mon Nov 23 08:31:41 
2015        (r291178)
@@ -46,15 +46,12 @@ __FBSDID("$FreeBSD$");
 ATF_TC_WITHOUT_HEAD(mblen_test);
 ATF_TC_BODY(mblen_test, tc)
 {
-       size_t len;
        char buf[MB_LEN_MAX + 1];
 
        /*
         * C/POSIX locale.
         */
 
-       printf("1..1\n");
-
        ATF_REQUIRE(MB_CUR_MAX == 1);
 
        /* No shift states in C locale. */

Copied and modified: stable/10/lib/libc/tests/locale/mbrlen_test.c (from 
r290532, head/lib/libc/tests/locale/mbrlen_test.c)
==============================================================================
--- head/lib/libc/tests/locale/mbrlen_test.c    Sun Nov  8 02:06:17 2015        
(r290532, copy source)
+++ stable/10/lib/libc/tests/locale/mbrlen_test.c       Mon Nov 23 08:31:41 
2015        (r291178)
@@ -49,7 +49,6 @@ ATF_TC_WITHOUT_HEAD(mbrlen_test);
 ATF_TC_BODY(mbrlen_test, tc)
 {
        mbstate_t s;
-       size_t len;
        char buf[MB_LEN_MAX + 1];
 
        /* C/POSIX locale. */

Copied and modified: stable/10/lib/libc/tests/locale/mbrtoc16_test.c (from 
r290532, head/lib/libc/tests/locale/mbrtoc16_test.c)
==============================================================================
--- head/lib/libc/tests/locale/mbrtoc16_test.c  Sun Nov  8 02:06:17 2015        
(r290532, copy source)
+++ stable/10/lib/libc/tests/locale/mbrtoc16_test.c     Mon Nov 23 08:31:41 
2015        (r291178)
@@ -42,18 +42,27 @@ __FBSDID("$FreeBSD$");
 
 #include <atf-c.h>
 
-ATF_TC_WITHOUT_HEAD(mbrtoc16_test);
-ATF_TC_BODY(mbrtoc16_test, tc)
+static void
+require_lc_ctype(const char *locale_name)
 {
-       mbstate_t s;
-       size_t len;
-       char16_t c16;
-
-       /*
-        * C/POSIX locale.
-        */
+       char *lc_ctype_set;
 
-       printf("1..1\n");
+       lc_ctype_set = setlocale(LC_CTYPE, locale_name);
+       if (lc_ctype_set == NULL)
+               atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d",
+                   locale_name, errno);
+
+       ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0);
+}
+
+static mbstate_t s;
+static char16_t c16;
+
+ATF_TC_WITHOUT_HEAD(mbrtoc16_c_locale_test);
+ATF_TC_BODY(mbrtoc16_c_locale_test, tc)
+{
+
+       require_lc_ctype("C");
 
        /* Null wide character, internal state. */
        ATF_REQUIRE(mbrtoc16(&c16, "", 1, NULL) == 0);
@@ -93,35 +102,37 @@ ATF_TC_BODY(mbrtoc16_test, tc)
        ATF_REQUIRE(mbrtoc16(&c16, "C", 1, &s) == 1);
        ATF_REQUIRE(c16 == L'C');
 
-       /*
-        * ISO-8859-1.
-        */
+}
 
-       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-1"),
-           "en_US.ISO8859-1") == 0);
+ATF_TC_WITHOUT_HEAD(mbrtoc16_iso_8859_1_test);
+ATF_TC_BODY(mbrtoc16_iso_8859_1_test, tc)
+{
+
+       require_lc_ctype("en_US.ISO8859-1");
 
        /* Currency sign. */
        memset(&s, 0, sizeof(s));
        ATF_REQUIRE(mbrtoc16(&c16, "\xa4", 1, &s) == 1);
        ATF_REQUIRE(c16 == 0xa4);
+}
 
-       /*
-        * ISO-8859-15.
-        */
+ATF_TC_WITHOUT_HEAD(mbrtoc16_iso_8859_15_test);
+ATF_TC_BODY(mbrtoc16_iso_8859_15_test, tc)
+{
 
-       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-15"),
-           "en_US.ISO8859-15") == 0);
+       require_lc_ctype("en_US.ISO8859-15");
 
        /* Euro sign. */
        memset(&s, 0, sizeof(s));
        ATF_REQUIRE(mbrtoc16(&c16, "\xa4", 1, &s) == 1);
        ATF_REQUIRE(c16 == 0x20ac);
+}
 
-       /*
-        * UTF-8.
-        */
+ATF_TC_WITHOUT_HEAD(mbrtoc16_utf_8_test);
+ATF_TC_BODY(mbrtoc16_utf_8_test, tc)
+{
 
-       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.UTF-8"), "en_US.UTF-8") 
== 0);
+       require_lc_ctype("en_US.UTF-8");
 
        /* Null wide character, internal state. */
        ATF_REQUIRE(mbrtoc16(NULL, 0, 0, NULL) == 0);
@@ -194,7 +205,10 @@ ATF_TC_BODY(mbrtoc16_test, tc)
 ATF_TP_ADD_TCS(tp)
 {
 
-       ATF_TP_ADD_TC(tp, mbrtoc16_test);
+       ATF_TP_ADD_TC(tp, mbrtoc16_c_locale_test);
+       ATF_TP_ADD_TC(tp, mbrtoc16_iso_8859_1_test);
+       ATF_TP_ADD_TC(tp, mbrtoc16_iso_8859_15_test);
+       ATF_TP_ADD_TC(tp, mbrtoc16_utf_8_test);
 
        return (atf_no_error());
 }

Copied and modified: stable/10/lib/libc/tests/locale/mbrtowc_test.c (from 
r290532, head/lib/libc/tests/locale/mbrtowc_test.c)
==============================================================================
--- head/lib/libc/tests/locale/mbrtowc_test.c   Sun Nov  8 02:06:17 2015        
(r290532, copy source)
+++ stable/10/lib/libc/tests/locale/mbrtowc_test.c      Mon Nov 23 08:31:41 
2015        (r291178)
@@ -49,7 +49,6 @@ ATF_TC_WITHOUT_HEAD(mbrtowc_test);
 ATF_TC_BODY(mbrtowc_test, tc)
 {
        mbstate_t s;
-       size_t len;
        wchar_t wc;
        char buf[MB_LEN_MAX + 1];
 
@@ -57,8 +56,6 @@ ATF_TC_BODY(mbrtowc_test, tc)
         * C/POSIX locale.
         */
 
-       printf("1..1\n");
-
        ATF_REQUIRE(MB_CUR_MAX == 1);
 
        /* Null wide character, internal state. */

Copied: stable/10/lib/libc/tests/locale/mbsnrtowcs_test.c (from r290532, 
head/lib/libc/tests/locale/mbsnrtowcs_test.c)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/lib/libc/tests/locale/mbsnrtowcs_test.c   Mon Nov 23 08:31:41 
2015        (r291178, copy of r290532, 
head/lib/libc/tests/locale/mbsnrtowcs_test.c)
@@ -0,0 +1,195 @@
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins
+ * 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.
+ */
+
+/*
+ * Test program for mbsnrtowcs().
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(mbsnrtowcs_test);
+ATF_TC_BODY(mbsnrtowcs_test, tc)
+{
+       char srcbuf[128];
+       wchar_t dstbuf[128];
+       char *src;
+       mbstate_t s;
+
+       /* C/POSIX locale. */
+
+       /* Simple null terminated string. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       src = srcbuf;
+       memset(&s, 0, sizeof(s));
+       ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 6, sizeof(dstbuf) /
+           sizeof(*dstbuf), &s) == 5);
+       ATF_REQUIRE(wcscmp(dstbuf, L"hello") == 0);
+       ATF_REQUIRE(dstbuf[6] == 0xcccc);
+       ATF_REQUIRE(src == NULL);
+
+       /* Simple null terminated string, stopping early. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       src = srcbuf;
+       memset(&s, 0, sizeof(s));
+       ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 4, sizeof(dstbuf) /
+           sizeof(*dstbuf), &s) == 4);
+       ATF_REQUIRE(wmemcmp(dstbuf, L"hell", 4) == 0);
+       ATF_REQUIRE(dstbuf[5] == 0xcccc);
+       ATF_REQUIRE(src == srcbuf + 4);
+
+       /* Not enough space in destination buffer. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       src = srcbuf;
+       memset(&s, 0, sizeof(s));
+       ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 6, 4, &s) == 4);
+       ATF_REQUIRE(wmemcmp(dstbuf, L"hell", 4) == 0);
+       ATF_REQUIRE(dstbuf[5] == 0xcccc);
+       ATF_REQUIRE(src == srcbuf + 4);
+
+       /* Null terminated string, internal dest. buffer */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       src = srcbuf;
+       memset(&s, 0, sizeof(s));
+       ATF_REQUIRE(mbsnrtowcs(NULL, (const char **)&src, 6, 0, &s) == 5);
+
+       /* Null terminated string, internal dest. buffer, stopping early */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       src = srcbuf;
+       memset(&s, 0, sizeof(s));
+       ATF_REQUIRE(mbsnrtowcs(NULL, (const char **)&src, 4, 0, &s) == 4);
+
+       /* Null terminated string, internal state. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       src = srcbuf;
+       ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 6, sizeof(dstbuf) /
+           sizeof(*dstbuf), NULL) == 5);
+       ATF_REQUIRE(wcscmp(dstbuf, L"hello") == 0);
+       ATF_REQUIRE(dstbuf[6] == 0xcccc);
+       ATF_REQUIRE(src == NULL);
+
+       /* Null terminated string, internal state, internal dest. buffer. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       src = srcbuf;
+       ATF_REQUIRE(mbsnrtowcs(NULL, (const char **)&src, 6, 0, NULL) == 5);
+
+       /* Empty source buffer. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       srcbuf[0] = '\0';
+       src = srcbuf;
+       memset(&s, 0, sizeof(s));
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 1, 1, &s) == 0);
+       ATF_REQUIRE(dstbuf[0] == 0);
+       ATF_REQUIRE(dstbuf[1] == 0xcccc);
+       ATF_REQUIRE(src == NULL);
+
+       /* Zero length destination buffer. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       src = srcbuf;
+       memset(&s, 0, sizeof(s));
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 1, 0, &s) == 0);
+       ATF_REQUIRE(dstbuf[0] == 0xcccc);
+       ATF_REQUIRE(src == srcbuf);
+
+       /* Zero length source buffer. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       src = srcbuf;
+       memset(&s, 0, sizeof(s));
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 0, 1, &s) == 0);
+       ATF_REQUIRE(dstbuf[0] == 0xcccc);
+       ATF_REQUIRE(src == srcbuf);
+
+       /*
+        * Japanese (EUC) locale.
+        */
+
+       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") 
== 0);
+       ATF_REQUIRE(MB_CUR_MAX > 1);
+
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "\xA3\xC1 B \xA3\xC3");
+       src = srcbuf;
+       memset(&s, 0, sizeof(s));
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 8, sizeof(dstbuf) /
+           sizeof(*dstbuf), &s) == 5);
+       ATF_REQUIRE(dstbuf[0] == 0xA3C1 && dstbuf[1] == 0x20 && dstbuf[2] == 
0x42 &&
+           dstbuf[3] == 0x20 && dstbuf[4] == 0xA3C3 && dstbuf[5] == 0);
+       ATF_REQUIRE(src == NULL);
+
+       /* Partial character. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "\xA3\xC1 B \xA3\xC3");
+       src = srcbuf;
+       memset(&s, 0, sizeof(s));
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 6, sizeof(dstbuf) /
+           sizeof(*dstbuf), &s) == 4);
+       ATF_REQUIRE(src == srcbuf + 6);
+       ATF_REQUIRE(!mbsinit(&s));
+       ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 1, sizeof(dstbuf) /
+           sizeof(*dstbuf), &s) == 1);
+       ATF_REQUIRE(src == srcbuf + 7);
+       ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 1, sizeof(dstbuf) /
+           sizeof(*dstbuf), &s) == 0);
+       ATF_REQUIRE(src == NULL);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, mbsnrtowcs_test);
+
+       return (atf_no_error());
+}

Copied and modified: stable/10/lib/libc/tests/locale/mbsrtowcs_test.c (from 
r290532, head/lib/libc/tests/locale/mbsrtowcs_test.c)
==============================================================================
--- head/lib/libc/tests/locale/mbsrtowcs_test.c Sun Nov  8 02:06:17 2015        
(r290532, copy source)
+++ stable/10/lib/libc/tests/locale/mbsrtowcs_test.c    Mon Nov 23 08:31:41 
2015        (r291178)
@@ -57,8 +57,6 @@ ATF_TC_BODY(mbsrtowcs_test, tc)
         * C/POSIX locale.
         */
 
-       printf("1..1\n");
-
        /* Simple null terminated string. */
        memset(srcbuf, 0xcc, sizeof(srcbuf));
        strcpy(srcbuf, "hello");

Copied: stable/10/lib/libc/tests/locale/mbstowcs_test.c (from r290532, 
head/lib/libc/tests/locale/mbstowcs_test.c)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/lib/libc/tests/locale/mbstowcs_test.c     Mon Nov 23 08:31:41 
2015        (r291178, copy of r290532, 
head/lib/libc/tests/locale/mbstowcs_test.c)
@@ -0,0 +1,111 @@
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * 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.
+ */
+
+/*
+ * Test program for mbstowcs(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1999.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(mbstowcs_test);
+ATF_TC_BODY(mbstowcs_test, tc)
+{
+       char srcbuf[128];
+       wchar_t dstbuf[128];
+
+       /* C/POSIX locale. */
+
+       /* Simple null terminated string. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       ATF_REQUIRE(mbstowcs(dstbuf, srcbuf, sizeof(dstbuf) / sizeof(*dstbuf)) 
== 5);
+       ATF_REQUIRE(wcscmp(dstbuf, L"hello") == 0);
+       ATF_REQUIRE(dstbuf[6] == 0xcccc);
+
+       /* Not enough space in destination buffer. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       ATF_REQUIRE(mbstowcs(dstbuf, srcbuf, 4) == 4);
+       ATF_REQUIRE(wmemcmp(dstbuf, L"hell", 4) == 0);
+       ATF_REQUIRE(dstbuf[5] == 0xcccc);
+
+       /* Null terminated string, internal dest. buffer (XSI extension) */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       ATF_REQUIRE(mbstowcs(NULL, srcbuf, 0) == 5);
+
+       /* Empty source buffer. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       srcbuf[0] = '\0';
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       ATF_REQUIRE(mbstowcs(dstbuf, srcbuf, 1) == 0);
+       ATF_REQUIRE(dstbuf[0] == 0);
+       ATF_REQUIRE(dstbuf[1] == 0xcccc);
+
+       /* Zero length destination buffer. */
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "hello");
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       ATF_REQUIRE(mbstowcs(dstbuf, srcbuf, 0) == 0);
+       ATF_REQUIRE(dstbuf[0] == 0xcccc);
+
+       /* Japanese (EUC) locale. */
+
+       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") 
== 0);
+       ATF_REQUIRE(MB_CUR_MAX > 1);
+
+       memset(srcbuf, 0xcc, sizeof(srcbuf));
+       strcpy(srcbuf, "\xA3\xC1 B \xA3\xC3");
+       wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+       ATF_REQUIRE(mbstowcs(dstbuf, srcbuf, sizeof(dstbuf) / sizeof(*dstbuf)) 
== 5);
+       ATF_REQUIRE(dstbuf[0] == 0xA3C1 && dstbuf[1] == 0x20 && dstbuf[2] == 
0x42 &&
+           dstbuf[3] == 0x20 && dstbuf[4] == 0xA3C3 && dstbuf[5] == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, mbstowcs_test);
+
+       return (atf_no_error());
+}

Copied and modified: stable/10/lib/libc/tests/locale/mbtowc_test.c (from 
r290532, head/lib/libc/tests/locale/mbtowc_test.c)
==============================================================================
--- head/lib/libc/tests/locale/mbtowc_test.c    Sun Nov  8 02:06:17 2015        
(r290532, copy source)
+++ stable/10/lib/libc/tests/locale/mbtowc_test.c       Mon Nov 23 08:31:41 
2015        (r291178)
@@ -46,9 +46,8 @@ __FBSDID("$FreeBSD$");
 ATF_TC_WITHOUT_HEAD(mbtowc_test);
 ATF_TC_BODY(mbtowc_test, tc)
 {
-       size_t len;
-       wchar_t wc;
        char buf[MB_LEN_MAX + 1];
+       wchar_t wc;
 
        /* C/POSIX locale. */
 

Copied: stable/10/lib/libc/tests/locale/towctrans_test.c (from r290532, 
head/lib/libc/tests/locale/towctrans_test.c)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/lib/libc/tests/locale/towctrans_test.c    Mon Nov 23 08:31:41 
2015        (r291178, copy of r290532, 
head/lib/libc/tests/locale/towctrans_test.c)
@@ -0,0 +1,90 @@
+/*-
+ * Copyright (c) 2003 Tim J. Robbins
+ * 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.
+ */
+
+/*
+ * Test program for wctrans() and towctrans() as specified by
+ * IEEE Std. 1003.1-2001 and ISO/IEC 9899:1999.
+ *
+ * The functions are tested in the "C" and "ja_JP.eucJP" locales.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(towctrans_test);
+ATF_TC_BODY(towctrans_test, tc)
+{
+       wctype_t t;
+       int i, j;
+       struct {
+               const char *name;
+               wint_t (*func)(wint_t);
+       } tran[] = {
+               { "tolower", towlower },
+               { "toupper", towupper },
+       };
+
+       /* C/POSIX locale. */
+       for (i = 0; i < sizeof(tran) / sizeof(*tran); i++) {
+               t = wctrans(tran[i].name);
+               ATF_REQUIRE(t != 0);
+               for (j = 0; j < 256; j++)
+                       ATF_REQUIRE(tran[i].func(j) == towctrans(j, t));
+       }
+       t = wctrans("elephant");
+       ATF_REQUIRE(t == 0);
+       for (i = 0; i < 256; i++)
+               ATF_REQUIRE(towctrans(i, t) == i);
+
+       /* Japanese (EUC) locale. */
+       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") 
== 0);
+       for (i = 0; i < sizeof(tran) / sizeof(*tran); i++) {
+               t = wctrans(tran[i].name);
+               ATF_REQUIRE(t != 0);
+               for (j = 0; j < 65536; j++)
+                       ATF_REQUIRE(tran[i].func(j) == towctrans(j, t));
+       }
+       t = wctrans("elephant");
+       ATF_REQUIRE(t == 0);
+       for (i = 0; i < 65536; i++)
+               ATF_REQUIRE(towctrans(i, t) == i);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, towctrans_test);
+
+       return (atf_no_error());
+}

Copied: stable/10/lib/libc/tests/locale/wcrtomb_test.c (from r290532, 
head/lib/libc/tests/locale/wcrtomb_test.c)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/lib/libc/tests/locale/wcrtomb_test.c      Mon Nov 23 08:31:41 
2015        (r291178, copy of r290532, 
head/lib/libc/tests/locale/wcrtomb_test.c)
@@ -0,0 +1,135 @@
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * 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.
+ */
+
+/*
+ * Test program for wcrtomb(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1999.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(wcrtomb_test);
+ATF_TC_BODY(wcrtomb_test, tc)
+{
+       mbstate_t s;
+       size_t len;
+       char buf[MB_LEN_MAX + 1];
+
+       /* C/POSIX locale. */
+
+       ATF_REQUIRE(MB_CUR_MAX == 1);
+
+       /*
+        * If the buffer argument is NULL, wc is implicitly L'\0',
+        * wcrtomb() resets its internal state.
+        */
+       ATF_REQUIRE(wcrtomb(NULL, L'\0', NULL) == 1);
+       ATF_REQUIRE(wcrtomb(NULL, UCHAR_MAX + 1, NULL) == 1);
+
+       /* Null wide character. */
+       memset(&s, 0, sizeof(s));
+       memset(buf, 0xcc, sizeof(buf));
+       len = wcrtomb(buf, L'\0', &s);
+       ATF_REQUIRE(len == 1);
+       ATF_REQUIRE((unsigned char)buf[0] == 0 && (unsigned char)buf[1] == 
0xcc);
+
+       /* Latin letter A, internal state. */
+       ATF_REQUIRE(wcrtomb(NULL, L'\0', NULL) == 1);
+       ATF_REQUIRE(wcrtomb(NULL, L'A', NULL) == 1);
+
+       /* Latin letter A. */
+       memset(&s, 0, sizeof(s));
+       memset(buf, 0xcc, sizeof(buf));
+       len = wcrtomb(buf, L'A', &s);
+       ATF_REQUIRE(len == 1);
+       ATF_REQUIRE((unsigned char)buf[0] == 'A' && (unsigned char)buf[1] == 
0xcc);
+
+       /* Invalid code. */
+       ATF_REQUIRE(wcrtomb(buf, UCHAR_MAX + 1, NULL) == (size_t)-1);
+       ATF_REQUIRE(errno == EILSEQ);
+
+       /*
+        * Japanese (EUC) locale.
+        */
+
+       ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") 
== 0);
+       ATF_REQUIRE(MB_CUR_MAX == 3);
+
+       /*
+        * If the buffer argument is NULL, wc is implicitly L'\0',

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to