1*5fb02e28Smgorny /* $NetBSD: t_catalog.c,v 1.1 2020/03/08 22:08:46 mgorny Exp $ */
2*5fb02e28Smgorny
3*5fb02e28Smgorny /*-
4*5fb02e28Smgorny * Copyright (c) 2020 The NetBSD Foundation, Inc.
5*5fb02e28Smgorny * All rights reserved.
6*5fb02e28Smgorny *
7*5fb02e28Smgorny * Redistribution and use in source and binary forms, with or without
8*5fb02e28Smgorny * modification, are permitted provided that the following conditions
9*5fb02e28Smgorny * are met:
10*5fb02e28Smgorny * 1. Redistributions of source code must retain the above copyright
11*5fb02e28Smgorny * notice, this list of conditions and the following disclaimer.
12*5fb02e28Smgorny * 2. Redistributions in binary form must reproduce the above copyright
13*5fb02e28Smgorny * notice, this list of conditions and the following disclaimer in the
14*5fb02e28Smgorny * documentation and/or other materials provided with the distribution.
15*5fb02e28Smgorny *
16*5fb02e28Smgorny * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17*5fb02e28Smgorny * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18*5fb02e28Smgorny * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19*5fb02e28Smgorny * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20*5fb02e28Smgorny * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*5fb02e28Smgorny * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*5fb02e28Smgorny * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*5fb02e28Smgorny * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*5fb02e28Smgorny * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*5fb02e28Smgorny * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*5fb02e28Smgorny * POSSIBILITY OF SUCH DAMAGE.
27*5fb02e28Smgorny */
28*5fb02e28Smgorny #include <sys/cdefs.h>
29*5fb02e28Smgorny __RCSID("$NetBSD: t_catalog.c,v 1.1 2020/03/08 22:08:46 mgorny Exp $");
30*5fb02e28Smgorny
31*5fb02e28Smgorny #include <atf-c.h>
32*5fb02e28Smgorny #include <errno.h>
33*5fb02e28Smgorny #include <stdio.h> /* Needed for sys_nerr on FreeBSD */
34*5fb02e28Smgorny #include <limits.h>
35*5fb02e28Smgorny #include <locale.h>
36*5fb02e28Smgorny #include <nl_types.h>
37*5fb02e28Smgorny #include <signal.h>
38*5fb02e28Smgorny #include <string.h>
39*5fb02e28Smgorny
40*5fb02e28Smgorny ATF_TC(catalog_errno);
ATF_TC_HEAD(catalog_errno,tc)41*5fb02e28Smgorny ATF_TC_HEAD(catalog_errno, tc)
42*5fb02e28Smgorny {
43*5fb02e28Smgorny atf_tc_set_md_var(tc, "descr", "Test whether C catalog covers all "
44*5fb02e28Smgorny "errno values");
45*5fb02e28Smgorny }
46*5fb02e28Smgorny
ATF_TC_BODY(catalog_errno,tc)47*5fb02e28Smgorny ATF_TC_BODY(catalog_errno, tc)
48*5fb02e28Smgorny {
49*5fb02e28Smgorny int i;
50*5fb02e28Smgorny nl_catd catd = catopen("libc", NL_CAT_LOCALE);
51*5fb02e28Smgorny ATF_REQUIRE(catd);
52*5fb02e28Smgorny
53*5fb02e28Smgorny for (i = 1; i < sys_nerr; i++) {
54*5fb02e28Smgorny const char *strerr = sys_errlist[i];
55*5fb02e28Smgorny const char *caterr = catgets(catd, 1, i, "");
56*5fb02e28Smgorny ATF_CHECK_MSG(!strcmp(strerr, caterr),
57*5fb02e28Smgorny "Catalog message mismatch for errno=%d (sys_errlist: '%s', "
58*5fb02e28Smgorny "catalog: '%s')\n", i, strerr, caterr);
59*5fb02e28Smgorny }
60*5fb02e28Smgorny
61*5fb02e28Smgorny catclose(catd);
62*5fb02e28Smgorny }
63*5fb02e28Smgorny
64*5fb02e28Smgorny ATF_TC(catalog_signal);
ATF_TC_HEAD(catalog_signal,tc)65*5fb02e28Smgorny ATF_TC_HEAD(catalog_signal, tc)
66*5fb02e28Smgorny {
67*5fb02e28Smgorny atf_tc_set_md_var(tc, "descr", "Test whether C catalog covers all "
68*5fb02e28Smgorny "signal values");
69*5fb02e28Smgorny }
70*5fb02e28Smgorny
ATF_TC_BODY(catalog_signal,tc)71*5fb02e28Smgorny ATF_TC_BODY(catalog_signal, tc)
72*5fb02e28Smgorny {
73*5fb02e28Smgorny int i;
74*5fb02e28Smgorny nl_catd catd = catopen("libc", NL_CAT_LOCALE);
75*5fb02e28Smgorny ATF_REQUIRE(catd);
76*5fb02e28Smgorny
77*5fb02e28Smgorny for (i = 1; i < SIGRTMIN-1; i++) {
78*5fb02e28Smgorny const char *strerr = sys_siglist[i];
79*5fb02e28Smgorny const char *caterr = catgets(catd, 2, i, "");
80*5fb02e28Smgorny ATF_CHECK_MSG(!strcmp(strerr, caterr),
81*5fb02e28Smgorny "Catalog message mismatch for signal=%d (sys_siglist: '%s', "
82*5fb02e28Smgorny "catalog: '%s')\n", i, strerr, caterr);
83*5fb02e28Smgorny }
84*5fb02e28Smgorny
85*5fb02e28Smgorny catclose(catd);
86*5fb02e28Smgorny }
87*5fb02e28Smgorny
ATF_TP_ADD_TCS(tp)88*5fb02e28Smgorny ATF_TP_ADD_TCS(tp)
89*5fb02e28Smgorny {
90*5fb02e28Smgorny (void)setlocale(LC_ALL, "C");
91*5fb02e28Smgorny
92*5fb02e28Smgorny ATF_TP_ADD_TC(tp, catalog_errno);
93*5fb02e28Smgorny ATF_TP_ADD_TC(tp, catalog_signal);
94*5fb02e28Smgorny
95*5fb02e28Smgorny return atf_no_error();
96*5fb02e28Smgorny }
97*5fb02e28Smgorny
98