11.3Sandvar/* $NetBSD: t_digittoint.c,v 1.3 2022/05/24 20:50:20 andvar Exp $ */ 21.1Sperseant 31.1Sperseant/*- 41.1Sperseant * Copyright (c) 2017 The NetBSD Foundation, Inc. 51.1Sperseant * All rights reserved. 61.1Sperseant * 71.1Sperseant * This code is derived from software contributed to The NetBSD Foundation 81.1Sperseant * by Konrad Schroder 91.1Sperseant * 101.1Sperseant * Redistribution and use in source and binary forms, with or without 111.1Sperseant * modification, are permitted provided that the following conditions 121.1Sperseant * are met: 131.1Sperseant * 1. Redistributions of source code must retain the above copyright 141.1Sperseant * notice, this list of conditions and the following disclaimer. 151.1Sperseant * 2. Redistributions in binary form must reproduce the above copyright 161.1Sperseant * notice, this list of conditions and the following disclaimer in the 171.1Sperseant * documentation and/or other materials provided with the distribution. 181.1Sperseant * 191.1Sperseant * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sperseant * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sperseant * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sperseant * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sperseant * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sperseant * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sperseant * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sperseant * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sperseant * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sperseant * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sperseant * POSSIBILITY OF SUCH DAMAGE. 301.1Sperseant */ 311.1Sperseant 321.1Sperseant#include <sys/cdefs.h> 331.1Sperseant__COPYRIGHT("@(#) Copyright (c) 2017\ 341.1Sperseant The NetBSD Foundation, inc. All rights reserved."); 351.3Sandvar__RCSID("$NetBSD: t_digittoint.c,v 1.3 2022/05/24 20:50:20 andvar Exp $"); 361.1Sperseant 371.1Sperseant#include <locale.h> 381.1Sperseant#include <stdio.h> 391.1Sperseant#include <string.h> 401.1Sperseant#include <vis.h> 411.1Sperseant#include <ctype.h> 421.1Sperseant 431.1Sperseant#include <atf-c.h> 441.1Sperseant 451.2Sperseant/* Use this until we have a better way to tell if it is defined */ 461.2Sperseant#ifdef digittoint 471.2Sperseant# define DIGITTOINT_DEFINED 481.2Sperseant#endif 491.2Sperseant 501.1Sperseantstatic struct test { 511.1Sperseant const char *locale; 521.1Sperseant const char *digits; 531.1Sperseant} tests[] = { 541.1Sperseant { 551.1Sperseant "C", 561.1Sperseant "0123456789AbcDeF", 571.1Sperseant }, { 581.1Sperseant "en_US.UTF-8", 591.1Sperseant "0123456789AbcDeF", 601.1Sperseant }, { 611.1Sperseant "ru_RU.KOI-8", 621.1Sperseant "0123456789AbcDeF", 631.1Sperseant }, { 641.1Sperseant NULL, 651.1Sperseant NULL, 661.1Sperseant } 671.1Sperseant}; 681.1Sperseant 691.2Sperseant#ifdef DIGITTOINT_DEFINED 701.1Sperseantstatic void 711.1Sperseanth_digittoint(const struct test *t) 721.1Sperseant{ 731.1Sperseant int i; 741.1Sperseant 751.1Sperseant ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); 761.1Sperseant printf("Trying locale %s...\n", t->locale); 771.1Sperseant ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL); 781.1Sperseant 791.1Sperseant for (i = 0; i < 16; i++) { 801.1Sperseant printf(" char %2.2x in position %d\n", t->digits[i], i); 811.1Sperseant ATF_REQUIRE_EQ(digittoint(t->digits[i]), i); 821.1Sperseant } 831.1Sperseant} 841.2Sperseant#endif /* DIGITTOINT_DEFINED */ 851.1Sperseant 861.1SperseantATF_TC(digittoint); 871.1Sperseant 881.1SperseantATF_TC_HEAD(digittoint, tc) 891.1Sperseant{ 901.1Sperseant atf_tc_set_md_var(tc, "descr", 911.3Sandvar "Checks digittoint under different locales"); 921.1Sperseant} 931.1Sperseant 941.1SperseantATF_TC_BODY(digittoint, tc) 951.1Sperseant{ 961.1Sperseant struct test *t; 971.1Sperseant 981.2Sperseant#ifdef DIGITTOINT_DEFINED 991.1Sperseant for (t = &tests[0]; t->locale != NULL; ++t) 1001.1Sperseant h_digittoint(t); 1011.2Sperseant#else /* ! DIGITTOINT_DEFINED */ 1021.2Sperseant atf_tc_skip("digittoint(3) not present to test"); 1031.2Sperseant#endif /* DIGITTOINT_DEFINED */ 1041.1Sperseant} 1051.1Sperseant 1061.1SperseantATF_TP_ADD_TCS(tp) 1071.1Sperseant{ 1081.1Sperseant 1091.1Sperseant ATF_TP_ADD_TC(tp, digittoint); 1101.1Sperseant 1111.1Sperseant return atf_no_error(); 1121.1Sperseant} 113