xref: /netbsd-src/tests/lib/libc/locale/t_wcsrtombs.c (revision 92bbbea0b3057a315d0df9b5a539a14d4c7d97ff)
1*92bbbea0Schristos /*	$NetBSD: t_wcsrtombs.c,v 1.1 2019/07/28 13:46:45 christos Exp $	*/
2*92bbbea0Schristos 
3*92bbbea0Schristos /*-
4*92bbbea0Schristos  * Copyright (c) 2019 The NetBSD Foundation, Inc.
5*92bbbea0Schristos  * All rights reserved.
6*92bbbea0Schristos  *
7*92bbbea0Schristos  * Redistribution and use in source and binary forms, with or without
8*92bbbea0Schristos  * modification, are permitted provided that the following conditions
9*92bbbea0Schristos  * are met:
10*92bbbea0Schristos  * 1. Redistributions of source code must retain the above copyright
11*92bbbea0Schristos  *    notice, this list of conditions and the following disclaimer.
12*92bbbea0Schristos  * 2. Redistributions in binary form must reproduce the above copyright
13*92bbbea0Schristos  *    notice, this list of conditions and the following disclaimer in the
14*92bbbea0Schristos  *    documentation and/or other materials provided with the distribution.
15*92bbbea0Schristos  *
16*92bbbea0Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17*92bbbea0Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18*92bbbea0Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19*92bbbea0Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20*92bbbea0Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*92bbbea0Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*92bbbea0Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*92bbbea0Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*92bbbea0Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*92bbbea0Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*92bbbea0Schristos  * POSSIBILITY OF SUCH DAMAGE.
27*92bbbea0Schristos  */
28*92bbbea0Schristos 
29*92bbbea0Schristos #include <sys/cdefs.h>
30*92bbbea0Schristos __RCSID("$NetBSD: t_wcsrtombs.c,v 1.1 2019/07/28 13:46:45 christos Exp $");
31*92bbbea0Schristos 
32*92bbbea0Schristos #include <atf-c.h>
33*92bbbea0Schristos #include <wchar.h>
34*92bbbea0Schristos #include <errno.h>
35*92bbbea0Schristos #include <string.h>
36*92bbbea0Schristos 
37*92bbbea0Schristos ATF_TC(wcsrtombs_advance);
ATF_TC_HEAD(wcsrtombs_advance,tc)38*92bbbea0Schristos ATF_TC_HEAD(wcsrtombs_advance, tc)
39*92bbbea0Schristos {
40*92bbbea0Schristos 	atf_tc_set_md_var(tc, "descr", "Test wcsrtombs(3) advances "
41*92bbbea0Schristos 	    "the source pointer to the first illegal byte");
42*92bbbea0Schristos }
43*92bbbea0Schristos 
ATF_TC_BODY(wcsrtombs_advance,tc)44*92bbbea0Schristos ATF_TC_BODY(wcsrtombs_advance, tc)
45*92bbbea0Schristos {
46*92bbbea0Schristos 	wchar_t label[] = L"L" L"\u0403" L"bel";
47*92bbbea0Schristos 	const wchar_t *wp = label;
48*92bbbea0Schristos 	char lbuf[128];
49*92bbbea0Schristos 	mbstate_t mbstate;
50*92bbbea0Schristos 	size_t n;
51*92bbbea0Schristos 
52*92bbbea0Schristos 	memset(&mbstate, 0, sizeof(mbstate));
53*92bbbea0Schristos 	memset(lbuf, 0, sizeof(lbuf));
54*92bbbea0Schristos 	n = wcsrtombs(lbuf, &wp, sizeof(lbuf), &mbstate);
55*92bbbea0Schristos 
56*92bbbea0Schristos 	ATF_REQUIRE_EQ(n, (size_t)-1);
57*92bbbea0Schristos 	ATF_REQUIRE_EQ(errno, EILSEQ);
58*92bbbea0Schristos 	ATF_REQUIRE_EQ(wp - label, 1);
59*92bbbea0Schristos }
60*92bbbea0Schristos 
ATF_TP_ADD_TCS(tp)61*92bbbea0Schristos ATF_TP_ADD_TCS(tp)
62*92bbbea0Schristos {
63*92bbbea0Schristos 
64*92bbbea0Schristos 	ATF_TP_ADD_TC(tp, wcsrtombs_advance);
65*92bbbea0Schristos 	return atf_no_error();
66*92bbbea0Schristos }
67