Home | History | Annotate | Line # | Download | only in locale
      1  1.3  riastrad /*	$NetBSD: t_mbrtoc16.c,v 1.3 2024/08/20 17:43:09 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*-
      4  1.1  riastrad  * Copyright (c) 2002 Tim J. Robbins
      5  1.1  riastrad  * All rights reserved.
      6  1.1  riastrad  *
      7  1.1  riastrad  * Copyright (c) 2013 Ed Schouten <ed (at) FreeBSD.org>
      8  1.1  riastrad  * All rights reserved.
      9  1.1  riastrad  *
     10  1.1  riastrad  * Redistribution and use in source and binary forms, with or without
     11  1.1  riastrad  * modification, are permitted provided that the following conditions
     12  1.1  riastrad  * are met:
     13  1.1  riastrad  * 1. Redistributions of source code must retain the above copyright
     14  1.1  riastrad  *    notice, this list of conditions and the following disclaimer.
     15  1.1  riastrad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  riastrad  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  riastrad  *    documentation and/or other materials provided with the distribution.
     18  1.1  riastrad  *
     19  1.1  riastrad  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     20  1.1  riastrad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  1.1  riastrad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  1.1  riastrad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     23  1.1  riastrad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  1.1  riastrad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  1.1  riastrad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.1  riastrad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.1  riastrad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.1  riastrad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.1  riastrad  * SUCH DAMAGE.
     30  1.1  riastrad  */
     31  1.1  riastrad /*
     32  1.1  riastrad  * Test program for mbrtoc16() as specified by ISO/IEC 9899:2011.
     33  1.1  riastrad  */
     34  1.1  riastrad 
     35  1.1  riastrad #include <sys/cdefs.h>
     36  1.3  riastrad __RCSID("$NetBSD: t_mbrtoc16.c,v 1.3 2024/08/20 17:43:09 riastradh Exp $");
     37  1.1  riastrad 
     38  1.1  riastrad #include <errno.h>
     39  1.1  riastrad #include <inttypes.h>
     40  1.1  riastrad #include <limits.h>
     41  1.1  riastrad #include <locale.h>
     42  1.1  riastrad #include <string.h>
     43  1.1  riastrad #include <uchar.h>
     44  1.1  riastrad 
     45  1.1  riastrad #include <atf-c.h>
     46  1.1  riastrad 
     47  1.1  riastrad static void
     48  1.1  riastrad require_lc_ctype(const char *locale_name)
     49  1.1  riastrad {
     50  1.1  riastrad 	char *lc_ctype_set;
     51  1.1  riastrad 
     52  1.1  riastrad 	lc_ctype_set = setlocale(LC_CTYPE, locale_name);
     53  1.1  riastrad 	if (lc_ctype_set == NULL)
     54  1.1  riastrad 		atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d",
     55  1.1  riastrad 		    locale_name, errno);
     56  1.1  riastrad 
     57  1.1  riastrad 	ATF_REQUIRE_EQ_MSG(strcmp(lc_ctype_set, locale_name), 0,
     58  1.1  riastrad 	    "lc_ctype_set=%s locale_name=%s", lc_ctype_set, locale_name);
     59  1.1  riastrad }
     60  1.1  riastrad 
     61  1.1  riastrad static mbstate_t s;
     62  1.1  riastrad static char16_t c16;
     63  1.1  riastrad 
     64  1.1  riastrad ATF_TC_WITHOUT_HEAD(mbrtoc16_c_locale_test);
     65  1.1  riastrad ATF_TC_BODY(mbrtoc16_c_locale_test, tc)
     66  1.1  riastrad {
     67  1.1  riastrad 	size_t n;
     68  1.1  riastrad 
     69  1.1  riastrad 	require_lc_ctype("C");
     70  1.1  riastrad 
     71  1.1  riastrad 	/* Null wide character, internal state. */
     72  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 1, NULL)), 0, "n=%zu", n);
     73  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%"PRIx16, (uint16_t)c16);
     74  1.1  riastrad 
     75  1.1  riastrad 	/* Null wide character. */
     76  1.1  riastrad 	memset(&s, 0, sizeof(s));
     77  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 1, &s)), 0, "n=%zu", n);
     78  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%"PRIx16, (uint16_t)c16);
     79  1.1  riastrad 
     80  1.1  riastrad 	/* Latin letter A, internal state. */
     81  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(NULL, 0, 0, NULL)), 0, "n=%zu", n);
     82  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "A", 1, NULL)), 1, "n=%zu", n);
     83  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, L'A', "c16=U+%"PRIx16" L'A'=U+%"PRIx16,
     84  1.1  riastrad 	    (uint16_t)c16, (uint16_t)L'A');
     85  1.1  riastrad 
     86  1.1  riastrad 	/* Latin letter A. */
     87  1.1  riastrad 	memset(&s, 0, sizeof(s));
     88  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "A", 1, &s)), 1, "n=%zu", n);
     89  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, L'A', "c16=U+%"PRIx16" L'A'=U+%"PRIx16,
     90  1.1  riastrad 	    (uint16_t)c16, (uint16_t)L'A');
     91  1.1  riastrad 
     92  1.1  riastrad 	/* Incomplete character sequence. */
     93  1.1  riastrad 	c16 = L'z';
     94  1.1  riastrad 	memset(&s, 0, sizeof(s));
     95  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 0, &s)), (size_t)-2,
     96  1.1  riastrad 	    "n=%zu", n);
     97  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, L'z', "c16=U+%"PRIx16" L'z'=U+%"PRIx16,
     98  1.1  riastrad 	    (uint16_t)c16, (uint16_t)L'z');
     99  1.1  riastrad 
    100  1.1  riastrad 	/* Check that mbrtoc16() doesn't access the buffer when n == 0. */
    101  1.1  riastrad 	c16 = L'z';
    102  1.1  riastrad 	memset(&s, 0, sizeof(s));
    103  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 0, &s)), (size_t)-2,
    104  1.1  riastrad 	    "n=%zu", n);
    105  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, L'z', "c16=U+%"PRIx16" L'z'=U+%"PRIx16,
    106  1.1  riastrad 	    (uint16_t)c16, (uint16_t)L'z');
    107  1.1  riastrad 
    108  1.1  riastrad 	/* Check that mbrtoc16() doesn't read ahead too aggressively. */
    109  1.1  riastrad 	memset(&s, 0, sizeof(s));
    110  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "AB", 2, &s)), 1, "n=%zu", n);
    111  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, L'A', "c16=U+%"PRIx16" L'A'=U+%"PRIx16,
    112  1.1  riastrad 	    (uint16_t)c16, (uint16_t)L'A');
    113  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "C", 1, &s)), 1, "n=%zu", n);
    114  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, L'C', "c16=U+%"PRIx16" L'C'=U+%"PRIx16,
    115  1.1  riastrad 	    (uint16_t)c16, (uint16_t)L'C');
    116  1.2  riastrad }
    117  1.2  riastrad 
    118  1.2  riastrad ATF_TC_WITHOUT_HEAD(mbrtoc16_iso2022jp_locale_test);
    119  1.2  riastrad ATF_TC_BODY(mbrtoc16_iso2022jp_locale_test, tc)
    120  1.2  riastrad {
    121  1.2  riastrad 	size_t n;
    122  1.2  riastrad 
    123  1.2  riastrad 	require_lc_ctype("ja_JP.ISO-2022-JP");
    124  1.2  riastrad 
    125  1.2  riastrad 	/* Null wide character, internal state. */
    126  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 1, NULL)), 0, "n=%zu", n);
    127  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%04"PRIx16, (uint16_t)c16);
    128  1.2  riastrad 
    129  1.2  riastrad 	/* Null wide character. */
    130  1.2  riastrad 	memset(&s, 0, sizeof(s));
    131  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 1, &s)), 0, "n=%zu", n);
    132  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%04"PRIx16, (uint16_t)c16);
    133  1.1  riastrad 
    134  1.2  riastrad 	/* Latin letter A, internal state. */
    135  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(NULL, 0, 0, NULL)), 0, "n=%zu", n);
    136  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "A", 1, NULL)), 1, "n=%zu", n);
    137  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, L'A', "c16=U+%04"PRIx16" L'A'=U+%04"PRIx16,
    138  1.2  riastrad 	    (uint16_t)c16, (uint16_t)L'A');
    139  1.2  riastrad 
    140  1.2  riastrad 	/* Latin letter A. */
    141  1.2  riastrad 	memset(&s, 0, sizeof(s));
    142  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "A", 1, &s)), 1, "n=%zu", n);
    143  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, L'A', "c16=U+%04"PRIx16" L'A'=U+%04"PRIx16,
    144  1.2  riastrad 	    (uint16_t)c16, (uint16_t)L'A');
    145  1.2  riastrad 
    146  1.2  riastrad 	/* Incomplete character sequence. */
    147  1.2  riastrad 	c16 = L'z';
    148  1.2  riastrad 	memset(&s, 0, sizeof(s));
    149  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 0, &s)), (size_t)-2,
    150  1.2  riastrad 	    "n=%zu", n);
    151  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, L'z', "c16=U+%04"PRIx16" L'z'=U+%04"PRIx16,
    152  1.2  riastrad 	    (uint16_t)c16, (uint16_t)L'z');
    153  1.2  riastrad 
    154  1.2  riastrad 	/* Check that mbrtoc16() doesn't access the buffer when n == 0. */
    155  1.2  riastrad 	c16 = L'z';
    156  1.2  riastrad 	memset(&s, 0, sizeof(s));
    157  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 0, &s)), (size_t)-2,
    158  1.2  riastrad 	    "n=%zu", n);
    159  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, L'z', "c16=U+%04"PRIx16" L'z'=U+%04"PRIx16,
    160  1.2  riastrad 	    (uint16_t)c16, (uint16_t)L'z');
    161  1.2  riastrad 
    162  1.2  riastrad 	/* Check that mbrtoc16() doesn't read ahead too aggressively. */
    163  1.2  riastrad 	memset(&s, 0, sizeof(s));
    164  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "AB", 2, &s)), 1, "n=%zu", n);
    165  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, L'A', "c16=U+%04"PRIx16" L'A'=U+%04"PRIx16,
    166  1.2  riastrad 	    (uint16_t)c16, (uint16_t)L'A');
    167  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "C", 1, &s)), 1, "n=%zu", n);
    168  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, L'C', "c16=U+%04"PRIx16" L'C'=U+%04"PRIx16,
    169  1.2  riastrad 	    (uint16_t)c16, (uint16_t)L'C');
    170  1.2  riastrad 
    171  1.2  riastrad 	/* Incomplete character sequence (shift sequence only). */
    172  1.2  riastrad 	memset(&s, 0, sizeof(s));
    173  1.2  riastrad 	c16 = 0;
    174  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\x1b(J", 3, &s)), (size_t)-2,
    175  1.2  riastrad 	    "n=%zu", n);
    176  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%04"PRIx16, (uint16_t)c16);
    177  1.2  riastrad 
    178  1.2  riastrad 	/* Same as above, but complete (U+00A5 YEN SIGN). */
    179  1.2  riastrad 	memset(&s, 0, sizeof(s));
    180  1.2  riastrad 	c16 = 0;
    181  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\x1b(J\x5c", 4, &s)), 4,
    182  1.2  riastrad 	    "n=%zu", n);
    183  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0xa5, "c16=U+%04"PRIx16, (uint16_t)c16);
    184  1.2  riastrad 
    185  1.2  riastrad 	/* Test restarting behaviour. */
    186  1.2  riastrad 	memset(&s, 0, sizeof(s));
    187  1.2  riastrad 	c16 = 0;
    188  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\x1b(", 2, &s)), (size_t)-2,
    189  1.2  riastrad 	    "n=%zu", n);
    190  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%04"PRIx16, (uint16_t)c16);
    191  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "J\x5c", 2, &s)), 2, "n=%zu", n);
    192  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0xa5, "c16=U+%04"PRIx16, (uint16_t)c16);
    193  1.2  riastrad 
    194  1.2  riastrad 	/*
    195  1.2  riastrad 	 * Test shift sequence state in various increments:
    196  1.2  riastrad 	 * 1. U+0042 LATIN CAPITAL LETTER A
    197  1.2  riastrad 	 * 2. (shift ISO/IEC 646:JP) U+00A5 YEN SIGN
    198  1.2  riastrad 	 * 3. U+00A5 YEN SIGN
    199  1.2  riastrad 	 * 4. (shift JIS X 0208) U+30A2 KATAKANA LETTER A
    200  1.2  riastrad 	 * 5. U+30A2 KATAKANA LETTER A
    201  1.2  riastrad 	 * 6. (shift to initial state) U+0000 NUL
    202  1.2  riastrad 	 */
    203  1.2  riastrad 	memset(&s, 0, sizeof(s));
    204  1.2  riastrad 	c16 = 0;
    205  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "A\x1b(J", 4, &s)), 1,
    206  1.2  riastrad 	    "n=%zu", n);
    207  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, L'A', "c16=U+%04"PRIx16, (uint16_t)c16);
    208  1.2  riastrad 	c16 = 0;
    209  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\x1b(J", 3, &s)), (size_t)-2,
    210  1.2  riastrad 	    "n=%zu", n);
    211  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%04"PRIx16, (uint16_t)c16);
    212  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\x5c\x5c", 2, &s)), 1,
    213  1.2  riastrad 	    "n=%zu", n);
    214  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0x00a5, "c16=U+%04"PRIx16, (uint16_t)c16);
    215  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\x5c\x1b$", 3, &s)), 1,
    216  1.2  riastrad 	    "n=%zu", n);
    217  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0x00a5, "c16=U+%04"PRIx16, (uint16_t)c16);
    218  1.2  riastrad 	c16 = 0x1234;
    219  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\x1b", 1, &s)), (size_t)-2,
    220  1.2  riastrad 	    "n=%zu", n);
    221  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0x1234, "c16=U+%04"PRIx16, (uint16_t)c16);
    222  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "$B\x25\x22", 4, &s)), 4,
    223  1.2  riastrad 	    "n=%zu", n);
    224  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0x30a2, "c16=U+%04"PRIx16, (uint16_t)c16);
    225  1.2  riastrad 	c16 = 0;
    226  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\x25", 1, &s)), (size_t)-2,
    227  1.2  riastrad 	    "n=%zu", n);
    228  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%04"PRIx16, (uint16_t)c16);
    229  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\x22\x1b(B\x00", 5, &s)), 1,
    230  1.2  riastrad 	    "n=%zu", n);
    231  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0x30a2, "c16=U+%04"PRIx16, (uint16_t)c16);
    232  1.2  riastrad 	c16 = 0;
    233  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\x1b(", 2, &s)), (size_t)-2,
    234  1.2  riastrad 	    "n=%zu", n);
    235  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%04"PRIx16, (uint16_t)c16);
    236  1.2  riastrad 	c16 = 42;
    237  1.2  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "B\x00", 2, &s)), 0, "n=%zu", n);
    238  1.2  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%04"PRIx16, (uint16_t)c16);
    239  1.1  riastrad }
    240  1.1  riastrad 
    241  1.1  riastrad ATF_TC_WITHOUT_HEAD(mbrtoc16_iso_8859_1_test);
    242  1.1  riastrad ATF_TC_BODY(mbrtoc16_iso_8859_1_test, tc)
    243  1.1  riastrad {
    244  1.1  riastrad 	size_t n;
    245  1.1  riastrad 
    246  1.1  riastrad 	require_lc_ctype("en_US.ISO8859-1");
    247  1.1  riastrad 
    248  1.1  riastrad 	/* Currency sign. */
    249  1.1  riastrad 	memset(&s, 0, sizeof(s));
    250  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\xa4", 1, &s)), 1, "n=%zu", n);
    251  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0xa4, "c16=U+%"PRIx16, (uint16_t)c16);
    252  1.1  riastrad }
    253  1.1  riastrad 
    254  1.1  riastrad ATF_TC_WITHOUT_HEAD(mbrtoc16_iso_8859_15_test);
    255  1.1  riastrad ATF_TC_BODY(mbrtoc16_iso_8859_15_test, tc)
    256  1.1  riastrad {
    257  1.1  riastrad 	size_t n;
    258  1.1  riastrad 
    259  1.1  riastrad 	require_lc_ctype("en_US.ISO8859-15");
    260  1.1  riastrad 
    261  1.1  riastrad 	/* Euro sign. */
    262  1.1  riastrad 	memset(&s, 0, sizeof(s));
    263  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\xa4", 1, &s)), 1, "n=%zu", n);
    264  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0x20ac, "c16=U+%"PRIx16, (uint16_t)c16);
    265  1.1  riastrad }
    266  1.1  riastrad 
    267  1.1  riastrad ATF_TC_WITHOUT_HEAD(mbrtoc16_utf_8_test);
    268  1.1  riastrad ATF_TC_BODY(mbrtoc16_utf_8_test, tc)
    269  1.1  riastrad {
    270  1.1  riastrad 	size_t n;
    271  1.1  riastrad 
    272  1.1  riastrad 	require_lc_ctype("en_US.UTF-8");
    273  1.1  riastrad 
    274  1.1  riastrad 	/* Null wide character, internal state. */
    275  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(NULL, 0, 0, NULL)), 0, "n=%zu", n);
    276  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 1, NULL)), 0, "n=%zu", n);
    277  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%"PRIx16, (uint16_t)c16);
    278  1.1  riastrad 
    279  1.1  riastrad 	/* Null wide character. */
    280  1.1  riastrad 	memset(&s, 0, sizeof(s));
    281  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 1, &s)), 0, "n=%zu", n);
    282  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%"PRIx16, (uint16_t)c16);
    283  1.1  riastrad 
    284  1.1  riastrad 	/* Latin letter A, internal state. */
    285  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(NULL, 0, 0, NULL)), 0, "n=%zu", n);
    286  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "A", 1, NULL)), 1, "n=%zu", n);
    287  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, L'A', "c16=U+%"PRIx16" L'A'=U+%"PRIx16,
    288  1.1  riastrad 	    (uint16_t)c16, (uint16_t)L'A');
    289  1.1  riastrad 
    290  1.1  riastrad 	/* Latin letter A. */
    291  1.1  riastrad 	memset(&s, 0, sizeof(s));
    292  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "A", 1, &s)), 1, "n=%zu", n);
    293  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, L'A', "c16=U+%"PRIx16" L'A'=U+%"PRIx16,
    294  1.1  riastrad 	    (uint16_t)c16, (uint16_t)L'A');
    295  1.1  riastrad 
    296  1.1  riastrad 	/* Incomplete character sequence (zero length). */
    297  1.1  riastrad 	c16 = L'z';
    298  1.1  riastrad 	memset(&s, 0, sizeof(s));
    299  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 0, &s)), (size_t)-2,
    300  1.1  riastrad 	    "n=%zu", n);
    301  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, L'z', "c16=U+%"PRIx16" L'z'=U+%"PRIx16,
    302  1.1  riastrad 	    (uint16_t)c16, (uint16_t)L'z');
    303  1.1  riastrad 
    304  1.1  riastrad 	/* Incomplete character sequence (truncated double-byte). */
    305  1.1  riastrad 	memset(&s, 0, sizeof(s));
    306  1.1  riastrad 	c16 = 0;
    307  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\xc3", 1, &s)), (size_t)-2,
    308  1.1  riastrad 	    "n=%zu", n);
    309  1.1  riastrad 
    310  1.1  riastrad 	/* Same as above, but complete. */
    311  1.1  riastrad 	memset(&s, 0, sizeof(s));
    312  1.1  riastrad 	c16 = 0;
    313  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\xc3\x84", 2, &s)), 2,
    314  1.1  riastrad 	    "n=%zu", n);
    315  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0xc4, "c16=U+%"PRIx16, (uint16_t)c16);
    316  1.1  riastrad 
    317  1.1  riastrad 	/* Test restarting behaviour. */
    318  1.1  riastrad 	memset(&s, 0, sizeof(s));
    319  1.1  riastrad 	c16 = 0;
    320  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\xc3", 1, &s)), (size_t)-2,
    321  1.1  riastrad 	    "n=%zu", n);
    322  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0, "c16=U+%"PRIx16, (uint16_t)c16);
    323  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\xb7", 1, &s)), 1, "n=%zu", n);
    324  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0xf7, "c16=U+%"PRIx16, (uint16_t)c16);
    325  1.1  riastrad 
    326  1.1  riastrad 	/* Surrogate pair. */
    327  1.1  riastrad 	memset(&s, 0, sizeof(s));
    328  1.1  riastrad 	c16 = 0;
    329  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\xf0\x9f\x92\xa9", 4, &s)), 4,
    330  1.1  riastrad 	    "n=%zu", n);
    331  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0xd83d, "c16=U+%"PRIx16, (uint16_t)c16);
    332  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "", 0, &s)), (size_t)-3,
    333  1.1  riastrad 	    "n=%zu", n);
    334  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0xdca9, "c16=U+%"PRIx16, (uint16_t)c16);
    335  1.1  riastrad 
    336  1.1  riastrad 	/* Letter e with acute, precomposed. */
    337  1.1  riastrad 	memset(&s, 0, sizeof(s));
    338  1.1  riastrad 	c16 = 0;
    339  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\xc3\xa9", 2, &s)), 2,
    340  1.1  riastrad 	    "n=%zu", n);
    341  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0xe9, "c16=U+%"PRIx16, (uint16_t)c16);
    342  1.1  riastrad 
    343  1.1  riastrad 	/* Letter e with acute, combined. */
    344  1.1  riastrad 	memset(&s, 0, sizeof(s));
    345  1.1  riastrad 	c16 = 0;
    346  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\x65\xcc\x81", 3, &s)), 1,
    347  1.1  riastrad 	    "n=%zu", n);
    348  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0x65, "c16=U+%"PRIx16, (uint16_t)c16);
    349  1.1  riastrad 	ATF_CHECK_EQ_MSG((n = mbrtoc16(&c16, "\xcc\x81", 2, &s)), 2,
    350  1.1  riastrad 	    "n=%zu", n);
    351  1.1  riastrad 	ATF_CHECK_EQ_MSG(c16, 0x301, "c16=U+%"PRIx16, (uint16_t)c16);
    352  1.1  riastrad }
    353  1.1  riastrad 
    354  1.1  riastrad ATF_TP_ADD_TCS(tp)
    355  1.1  riastrad {
    356  1.1  riastrad 
    357  1.1  riastrad 	ATF_TP_ADD_TC(tp, mbrtoc16_c_locale_test);
    358  1.2  riastrad 	ATF_TP_ADD_TC(tp, mbrtoc16_iso2022jp_locale_test);
    359  1.1  riastrad 	ATF_TP_ADD_TC(tp, mbrtoc16_iso_8859_1_test);
    360  1.1  riastrad 	ATF_TP_ADD_TC(tp, mbrtoc16_iso_8859_15_test);
    361  1.1  riastrad 	ATF_TP_ADD_TC(tp, mbrtoc16_utf_8_test);
    362  1.1  riastrad 
    363  1.1  riastrad 	return (atf_no_error());
    364  1.1  riastrad }
    365