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