11.1Smgorny/* $NetBSD: t_catalog.c,v 1.1 2020/03/08 22:08:46 mgorny Exp $ */
21.1Smgorny
31.1Smgorny/*-
41.1Smgorny * Copyright (c) 2020 The NetBSD Foundation, Inc.
51.1Smgorny * All rights reserved.
61.1Smgorny *
71.1Smgorny * Redistribution and use in source and binary forms, with or without
81.1Smgorny * modification, are permitted provided that the following conditions
91.1Smgorny * are met:
101.1Smgorny * 1. Redistributions of source code must retain the above copyright
111.1Smgorny *    notice, this list of conditions and the following disclaimer.
121.1Smgorny * 2. Redistributions in binary form must reproduce the above copyright
131.1Smgorny *    notice, this list of conditions and the following disclaimer in the
141.1Smgorny *    documentation and/or other materials provided with the distribution.
151.1Smgorny *
161.1Smgorny * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.1Smgorny * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.1Smgorny * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.1Smgorny * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.1Smgorny * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.1Smgorny * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.1Smgorny * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.1Smgorny * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.1Smgorny * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.1Smgorny * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.1Smgorny * POSSIBILITY OF SUCH DAMAGE.
271.1Smgorny */
281.1Smgorny#include <sys/cdefs.h>
291.1Smgorny__RCSID("$NetBSD: t_catalog.c,v 1.1 2020/03/08 22:08:46 mgorny Exp $");
301.1Smgorny
311.1Smgorny#include <atf-c.h>
321.1Smgorny#include <errno.h>
331.1Smgorny#include <stdio.h>	/* Needed for sys_nerr on FreeBSD */
341.1Smgorny#include <limits.h>
351.1Smgorny#include <locale.h>
361.1Smgorny#include <nl_types.h>
371.1Smgorny#include <signal.h>
381.1Smgorny#include <string.h>
391.1Smgorny
401.1SmgornyATF_TC(catalog_errno);
411.1SmgornyATF_TC_HEAD(catalog_errno, tc)
421.1Smgorny{
431.1Smgorny	atf_tc_set_md_var(tc, "descr", "Test whether C catalog covers all "
441.1Smgorny	    "errno values");
451.1Smgorny}
461.1Smgorny
471.1SmgornyATF_TC_BODY(catalog_errno, tc)
481.1Smgorny{
491.1Smgorny	int i;
501.1Smgorny	nl_catd catd = catopen("libc", NL_CAT_LOCALE);
511.1Smgorny	ATF_REQUIRE(catd);
521.1Smgorny
531.1Smgorny	for (i = 1; i < sys_nerr; i++) {
541.1Smgorny		const char *strerr = sys_errlist[i];
551.1Smgorny		const char *caterr = catgets(catd, 1, i, "");
561.1Smgorny		ATF_CHECK_MSG(!strcmp(strerr, caterr),
571.1Smgorny		    "Catalog message mismatch for errno=%d (sys_errlist: '%s', "
581.1Smgorny		    "catalog: '%s')\n", i, strerr, caterr);
591.1Smgorny	}
601.1Smgorny
611.1Smgorny	catclose(catd);
621.1Smgorny}
631.1Smgorny
641.1SmgornyATF_TC(catalog_signal);
651.1SmgornyATF_TC_HEAD(catalog_signal, tc)
661.1Smgorny{
671.1Smgorny	atf_tc_set_md_var(tc, "descr", "Test whether C catalog covers all "
681.1Smgorny	    "signal values");
691.1Smgorny}
701.1Smgorny
711.1SmgornyATF_TC_BODY(catalog_signal, tc)
721.1Smgorny{
731.1Smgorny	int i;
741.1Smgorny	nl_catd catd = catopen("libc", NL_CAT_LOCALE);
751.1Smgorny	ATF_REQUIRE(catd);
761.1Smgorny
771.1Smgorny	for (i = 1; i < SIGRTMIN-1; i++) {
781.1Smgorny		const char *strerr = sys_siglist[i];
791.1Smgorny		const char *caterr = catgets(catd, 2, i, "");
801.1Smgorny		ATF_CHECK_MSG(!strcmp(strerr, caterr),
811.1Smgorny		    "Catalog message mismatch for signal=%d (sys_siglist: '%s', "
821.1Smgorny		    "catalog: '%s')\n", i, strerr, caterr);
831.1Smgorny	}
841.1Smgorny
851.1Smgorny	catclose(catd);
861.1Smgorny}
871.1Smgorny
881.1SmgornyATF_TP_ADD_TCS(tp)
891.1Smgorny{
901.1Smgorny	(void)setlocale(LC_ALL, "C");
911.1Smgorny
921.1Smgorny	ATF_TP_ADD_TC(tp, catalog_errno);
931.1Smgorny	ATF_TP_ADD_TC(tp, catalog_signal);
941.1Smgorny
951.1Smgorny	return atf_no_error();
961.1Smgorny}
971.1Smgorny
98