1115894Stjr/*- 2115894Stjr * Copyright (c) 2003 Tim J. Robbins 3115894Stjr * All rights reserved. 4115894Stjr * 5115894Stjr * Redistribution and use in source and binary forms, with or without 6115894Stjr * modification, are permitted provided that the following conditions 7115894Stjr * are met: 8115894Stjr * 1. Redistributions of source code must retain the above copyright 9115894Stjr * notice, this list of conditions and the following disclaimer. 10115894Stjr * 2. Redistributions in binary form must reproduce the above copyright 11115894Stjr * notice, this list of conditions and the following disclaimer in the 12115894Stjr * documentation and/or other materials provided with the distribution. 13115894Stjr * 14115894Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15115894Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16115894Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17115894Stjr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18115894Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19115894Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20115894Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21115894Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22115894Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23115894Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24115894Stjr * SUCH DAMAGE. 25115894Stjr */ 26115894Stjr 27115894Stjr/* 28115894Stjr * Test program for wctype() and iswctype() as specified by 29115894Stjr * IEEE Std. 1003.1-2001 and ISO/IEC 9899:1999. 30115894Stjr * 31115894Stjr * The functions are tested in the "C" and "ja_JP.eucJP" locales. 32115894Stjr */ 33115894Stjr 34115894Stjr#include <sys/cdefs.h> 35115894Stjr__FBSDID("$FreeBSD: releng/10.3/lib/libc/tests/locale/iswctype_test.c 291178 2015-11-23 08:31:41Z ngie $"); 36115894Stjr 37291178Sngie#include <sys/param.h> 38291178Sngie#include <errno.h> 39115894Stjr#include <locale.h> 40115894Stjr#include <stdio.h> 41250989Sed#include <string.h> 42115894Stjr#include <wchar.h> 43115894Stjr#include <wctype.h> 44115894Stjr 45290532Sngie#include <atf-c.h> 46290532Sngie 47291178Sngiestatic void 48291178Sngierequire_lc_ctype(const char *locale_name) 49115894Stjr{ 50291178Sngie char *lc_ctype_set; 51115894Stjr 52291178Sngie lc_ctype_set = setlocale(LC_CTYPE, locale_name); 53291178Sngie if (lc_ctype_set == NULL) 54291178Sngie atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d", 55291178Sngie locale_name, errno); 56291178Sngie 57291178Sngie ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0); 58291178Sngie} 59291178Sngie 60291178Sngiestatic wctype_t t; 61291178Sngiestatic int i, j; 62291178Sngiestatic struct { 63291178Sngie const char *name; 64291178Sngie int (*func)(wint_t); 65291178Sngie} cls[] = { 66291178Sngie { "alnum", iswalnum }, 67291178Sngie { "alpha", iswalpha }, 68291178Sngie { "blank", iswblank }, 69291178Sngie { "cntrl", iswcntrl }, 70291178Sngie { "digit", iswdigit }, 71291178Sngie { "graph", iswgraph }, 72291178Sngie { "lower", iswlower }, 73291178Sngie { "print", iswprint }, 74291178Sngie { "punct", iswpunct }, 75291178Sngie { "space", iswspace }, 76291178Sngie { "upper", iswupper }, 77291178Sngie { "xdigit", iswxdigit } 78291178Sngie}; 79291178Sngie 80291178SngieATF_TC_WITHOUT_HEAD(iswctype_c_locale_test); 81291178SngieATF_TC_BODY(iswctype_c_locale_test, tc) 82291178Sngie{ 83291178Sngie 84291178Sngie require_lc_ctype("C"); 85291178Sngie for (i = 0; i < nitems(cls); i++) { 86115894Stjr t = wctype(cls[i].name); 87290532Sngie ATF_REQUIRE(t != 0); 88115894Stjr for (j = 0; j < 256; j++) 89290532Sngie ATF_REQUIRE(cls[i].func(j) == iswctype(j, t)); 90115894Stjr } 91115894Stjr t = wctype("elephant"); 92290532Sngie ATF_REQUIRE(t == 0); 93115894Stjr for (i = 0; i < 256; i++) 94290532Sngie ATF_REQUIRE(iswctype(i, t) == 0); 95291178Sngie} 96115894Stjr 97291178SngieATF_TC_WITHOUT_HEAD(iswctype_euc_jp_test); 98291178SngieATF_TC_BODY(iswctype_euc_jp_test, tc) 99291178Sngie{ 100291178Sngie 101291178Sngie require_lc_ctype("ja_JP.eucJP"); 102291178Sngie 103291178Sngie for (i = 0; i < nitems(cls); i++) { 104115894Stjr t = wctype(cls[i].name); 105290532Sngie ATF_REQUIRE(t != 0); 106115894Stjr for (j = 0; j < 65536; j++) 107290532Sngie ATF_REQUIRE(cls[i].func(j) == iswctype(j, t)); 108115894Stjr } 109115894Stjr t = wctype("elephant"); 110290532Sngie ATF_REQUIRE(t == 0); 111115894Stjr for (i = 0; i < 65536; i++) 112290532Sngie ATF_REQUIRE(iswctype(i, t) == 0); 113290532Sngie} 114115894Stjr 115290532SngieATF_TP_ADD_TCS(tp) 116290532Sngie{ 117115894Stjr 118291178Sngie ATF_TP_ADD_TC(tp, iswctype_c_locale_test); 119291178Sngie ATF_TP_ADD_TC(tp, iswctype_euc_jp_test); 120290532Sngie 121290532Sngie return (atf_no_error()); 122115894Stjr} 123