1*2cbd152aSriastradh /* $NetBSD: t_mbrtoc32.c,v 1.1 2024/08/15 14:16:34 riastradh Exp $ */ 2*2cbd152aSriastradh 3*2cbd152aSriastradh /*- 4*2cbd152aSriastradh * Copyright (c) 2024 The NetBSD Foundation, Inc. 5*2cbd152aSriastradh * All rights reserved. 6*2cbd152aSriastradh * 7*2cbd152aSriastradh * Redistribution and use in source and binary forms, with or without 8*2cbd152aSriastradh * modification, are permitted provided that the following conditions 9*2cbd152aSriastradh * are met: 10*2cbd152aSriastradh * 1. Redistributions of source code must retain the above copyright 11*2cbd152aSriastradh * notice, this list of conditions and the following disclaimer. 12*2cbd152aSriastradh * 2. Redistributions in binary form must reproduce the above copyright 13*2cbd152aSriastradh * notice, this list of conditions and the following disclaimer in the 14*2cbd152aSriastradh * documentation and/or other materials provided with the distribution. 15*2cbd152aSriastradh * 16*2cbd152aSriastradh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17*2cbd152aSriastradh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18*2cbd152aSriastradh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19*2cbd152aSriastradh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20*2cbd152aSriastradh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21*2cbd152aSriastradh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22*2cbd152aSriastradh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23*2cbd152aSriastradh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24*2cbd152aSriastradh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25*2cbd152aSriastradh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26*2cbd152aSriastradh * POSSIBILITY OF SUCH DAMAGE. 27*2cbd152aSriastradh */ 28*2cbd152aSriastradh 29*2cbd152aSriastradh #include <sys/cdefs.h> 30*2cbd152aSriastradh __RCSID("$NetBSD: t_mbrtoc32.c,v 1.1 2024/08/15 14:16:34 riastradh Exp $"); 31*2cbd152aSriastradh 32*2cbd152aSriastradh #include <atf-c.h> 33*2cbd152aSriastradh #include <locale.h> 34*2cbd152aSriastradh #include <uchar.h> 35*2cbd152aSriastradh 36*2cbd152aSriastradh #include "h_macros.h" 37*2cbd152aSriastradh 38*2cbd152aSriastradh ATF_TC(mbrtoc32_null); 39*2cbd152aSriastradh ATF_TC_HEAD(mbrtoc32_null, tc) 40*2cbd152aSriastradh { 41*2cbd152aSriastradh atf_tc_set_md_var(tc, "descr", "Test null string input to mbrtoc32"); 42*2cbd152aSriastradh } 43*2cbd152aSriastradh ATF_TC_BODY(mbrtoc32_null, tc) 44*2cbd152aSriastradh { 45*2cbd152aSriastradh char *locale; 46*2cbd152aSriastradh char32_t c32; 47*2cbd152aSriastradh mbstate_t ps = {0}; 48*2cbd152aSriastradh size_t n; 49*2cbd152aSriastradh 50*2cbd152aSriastradh REQUIRE_LIBC((locale = setlocale(LC_ALL, "C")), NULL); 51*2cbd152aSriastradh ATF_REQUIRE_EQ_MSG(strcmp(locale, "C"), 0, "locale=%s", locale); 52*2cbd152aSriastradh 53*2cbd152aSriastradh ATF_CHECK_EQ_MSG((n = mbrtoc32(&c32, NULL, 0, &ps)), 0, "n=%zu", n); 54*2cbd152aSriastradh } 55*2cbd152aSriastradh 56*2cbd152aSriastradh ATF_TP_ADD_TCS(tp) 57*2cbd152aSriastradh { 58*2cbd152aSriastradh 59*2cbd152aSriastradh ATF_TP_ADD_TC(tp, mbrtoc32_null); 60*2cbd152aSriastradh return atf_no_error(); 61*2cbd152aSriastradh } 62