t_digittoint.c revision 1.1
11.1Sperseant/* $NetBSD: t_digittoint.c,v 1.1 2017/05/30 23:44:02 perseant 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.1Sperseant__RCSID("$NetBSD: t_digittoint.c,v 1.1 2017/05/30 23:44:02 perseant 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.1Sperseantstatic struct test { 461.1Sperseant const char *locale; 471.1Sperseant const char *digits; 481.1Sperseant} tests[] = { 491.1Sperseant { 501.1Sperseant "C", 511.1Sperseant "0123456789AbcDeF", 521.1Sperseant }, { 531.1Sperseant "en_US.UTF-8", 541.1Sperseant "0123456789AbcDeF", 551.1Sperseant }, { 561.1Sperseant "ru_RU.KOI-8", 571.1Sperseant "0123456789AbcDeF", 581.1Sperseant }, { 591.1Sperseant NULL, 601.1Sperseant NULL, 611.1Sperseant } 621.1Sperseant}; 631.1Sperseant 641.1Sperseantstatic void 651.1Sperseanth_digittoint(const struct test *t) 661.1Sperseant{ 671.1Sperseant int i; 681.1Sperseant 691.1Sperseant ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); 701.1Sperseant printf("Trying locale %s...\n", t->locale); 711.1Sperseant ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL); 721.1Sperseant 731.1Sperseant for (i = 0; i < 16; i++) { 741.1Sperseant printf(" char %2.2x in position %d\n", t->digits[i], i); 751.1Sperseant ATF_REQUIRE_EQ(digittoint(t->digits[i]), i); 761.1Sperseant } 771.1Sperseant} 781.1Sperseant 791.1SperseantATF_TC(digittoint); 801.1Sperseant 811.1SperseantATF_TC_HEAD(digittoint, tc) 821.1Sperseant{ 831.1Sperseant atf_tc_set_md_var(tc, "descr", 841.1Sperseant "Checks digittoint under diferent locales"); 851.1Sperseant} 861.1Sperseant 871.1SperseantATF_TC_BODY(digittoint, tc) 881.1Sperseant{ 891.1Sperseant struct test *t; 901.1Sperseant 911.1Sperseant for (t = &tests[0]; t->locale != NULL; ++t) 921.1Sperseant h_digittoint(t); 931.1Sperseant} 941.1Sperseant 951.1SperseantATF_TP_ADD_TCS(tp) 961.1Sperseant{ 971.1Sperseant 981.1Sperseant ATF_TP_ADD_TC(tp, digittoint); 991.1Sperseant 1001.1Sperseant return atf_no_error(); 1011.1Sperseant} 102