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/11.0/lib/libc/tests/locale/iswctype_test.c 290844 2015-11-15 04:50:08Z ngie $"); 36115894Stjr 37290844Sngie#include <sys/param.h> 38290844Sngie#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 47290844Sngiestatic void 48290844Sngierequire_lc_ctype(const char *locale_name) 49115894Stjr{ 50290844Sngie char *lc_ctype_set; 51115894Stjr 52290844Sngie lc_ctype_set = setlocale(LC_CTYPE, locale_name); 53290844Sngie if (lc_ctype_set == NULL) 54290844Sngie atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d", 55290844Sngie locale_name, errno); 56290844Sngie 57290844Sngie ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0); 58290844Sngie} 59290844Sngie 60290844Sngiestatic wctype_t t; 61290844Sngiestatic int i, j; 62290844Sngiestatic struct { 63290844Sngie const char *name; 64290844Sngie int (*func)(wint_t); 65290844Sngie} cls[] = { 66290844Sngie { "alnum", iswalnum }, 67290844Sngie { "alpha", iswalpha }, 68290844Sngie { "blank", iswblank }, 69290844Sngie { "cntrl", iswcntrl }, 70290844Sngie { "digit", iswdigit }, 71290844Sngie { "graph", iswgraph }, 72290844Sngie { "lower", iswlower }, 73290844Sngie { "print", iswprint }, 74290844Sngie { "punct", iswpunct }, 75290844Sngie { "space", iswspace }, 76290844Sngie { "upper", iswupper }, 77290844Sngie { "xdigit", iswxdigit } 78290844Sngie}; 79290844Sngie 80290844SngieATF_TC_WITHOUT_HEAD(iswctype_c_locale_test); 81290844SngieATF_TC_BODY(iswctype_c_locale_test, tc) 82290844Sngie{ 83290844Sngie 84290844Sngie require_lc_ctype("C"); 85290844Sngie 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); 95290844Sngie} 96115894Stjr 97290844SngieATF_TC_WITHOUT_HEAD(iswctype_euc_jp_test); 98290844SngieATF_TC_BODY(iswctype_euc_jp_test, tc) 99290844Sngie{ 100290844Sngie 101290844Sngie require_lc_ctype("ja_JP.eucJP"); 102290844Sngie 103290844Sngie 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 118290844Sngie ATF_TP_ADD_TC(tp, iswctype_c_locale_test); 119290844Sngie ATF_TP_ADD_TC(tp, iswctype_euc_jp_test); 120290532Sngie 121290532Sngie return (atf_no_error()); 122115894Stjr} 123