1 /* $NetBSD: t_mbsnrtowcs.c,v 1.1 2013/05/28 16:57:56 joerg Exp $ */
4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Joerg Sonnenberger.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: t_mbsnrtowcs.c,v 1.1 2013/05/28 16:57:56 joerg Exp $");
40 static const struct test
{
44 const wchar_t output1
[64];
46 const wchar_t output2
[64];
49 { "C", "ABCD0123", 4, { 0x41, 0x42, 0x43, 0x44 }, 4,
50 { 0x30, 0x31, 0x32, 0x33, 0x0 }, 5 },
51 { "en_US.UTF-8", "ABCD0123", 4, { 0x41, 0x42, 0x43, 0x44 }, 4,
52 { 0x30, 0x31, 0x32, 0x33, 0x0 }, 5 },
53 { "en_US.UTF-8", "ABC\303\2440123", 4, { 0x41, 0x42, 0x43, }, 3,
54 { 0xe4, 0x30, 0x31, 0x32, 0x33, 0x0 }, 6 },
58 ATF_TC_HEAD(mbsnrtowcs
, tc
)
60 atf_tc_set_md_var(tc
, "descr",
61 "Checks mbsnrtowc(3) with different locales");
63 ATF_TC_BODY(mbsnrtowcs
, tc
)
72 for (i
= 0; i
< __arraycount(tests
); ++i
) {
74 ATF_REQUIRE_STREQ(setlocale(LC_ALL
, "C"), "C");
75 ATF_REQUIRE(setlocale(LC_CTYPE
, t
->locale
) != NULL
);
76 memset(&state
, 0, sizeof(state
));
78 len
= mbsnrtowcs(buf
, &src
, t
->limit
,
79 __arraycount(buf
), &state
);
80 ATF_REQUIRE_EQ(src
, t
->data
+ t
->limit
);
81 ATF_REQUIRE_EQ(len
, t
->output1_len
);
82 ATF_REQUIRE(wmemcmp(t
->output1
, buf
, len
) == 0);
83 len
= mbsnrtowcs(buf
, &src
, strlen(src
) + 1,
84 __arraycount(buf
), &state
);
85 ATF_REQUIRE_EQ(len
, strlen(t
->data
) - t
->limit
);
86 ATF_REQUIRE(wmemcmp(t
->output2
, buf
, len
+ 1) == 0);
87 ATF_REQUIRE_EQ(src
, NULL
);
94 ATF_TP_ADD_TC(tp
, mbsnrtowcs
);
96 return atf_no_error();