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.2/tools/regression/lib/libc/locale/test-iswctype.c 250989 2013-05-25 18:04:24Z ed $");
36115894Stjr
37115894Stjr#include <assert.h>
38115894Stjr#include <locale.h>
39115894Stjr#include <stdio.h>
40250989Sed#include <string.h>
41115894Stjr#include <wchar.h>
42115894Stjr#include <wctype.h>
43115894Stjr
44115894Stjrint
45115894Stjrmain(int argc, char *argv[])
46115894Stjr{
47115894Stjr	wctype_t t;
48115894Stjr	int i, j;
49115894Stjr	struct {
50115894Stjr		const char *name;
51115894Stjr		int (*func)(wint_t);
52115894Stjr	} cls[] = {
53115894Stjr		{ "alnum", iswalnum },
54115894Stjr		{ "alpha", iswalpha },
55115894Stjr		{ "blank", iswblank },
56115894Stjr		{ "cntrl", iswcntrl },
57115894Stjr		{ "digit", iswdigit },
58115894Stjr		{ "graph", iswgraph },
59115894Stjr		{ "lower", iswlower },
60115894Stjr		{ "print", iswprint },
61115894Stjr		{ "punct", iswpunct },
62115894Stjr		{ "space", iswspace },
63115894Stjr		{ "upper", iswupper },
64115894Stjr		{ "xdigit", iswxdigit }
65115894Stjr	};
66115894Stjr
67137587Snik	printf("1..2\n");
68137587Snik
69115894Stjr	/*
70115894Stjr	 * C/POSIX locale.
71115894Stjr	 */
72115894Stjr	for (i = 0; i < sizeof(cls) / sizeof(*cls); i++) {
73115894Stjr		t = wctype(cls[i].name);
74115894Stjr		assert(t != 0);
75115894Stjr		for (j = 0; j < 256; j++)
76115894Stjr			assert(cls[i].func(j) == iswctype(j, t));
77115894Stjr	}
78115894Stjr	t = wctype("elephant");
79115894Stjr	assert(t == 0);
80115894Stjr	for (i = 0; i < 256; i++)
81115894Stjr		assert(iswctype(i, t) == 0);
82115894Stjr
83115894Stjr	/*
84115894Stjr	 * Japanese (EUC) locale.
85115894Stjr	 */
86115894Stjr	assert(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
87115894Stjr	for (i = 0; i < sizeof(cls) / sizeof(*cls); i++) {
88115894Stjr		t = wctype(cls[i].name);
89115894Stjr		assert(t != 0);
90115894Stjr		for (j = 0; j < 65536; j++)
91115894Stjr			assert(cls[i].func(j) == iswctype(j, t));
92115894Stjr	}
93115894Stjr	t = wctype("elephant");
94115894Stjr	assert(t == 0);
95115894Stjr	for (i = 0; i < 65536; i++)
96115894Stjr		assert(iswctype(i, t) == 0);
97115894Stjr
98137587Snik	printf("ok 1 - iswctype()\n");
99137587Snik	printf("ok 2 - wctype()\n");
100115894Stjr
101115894Stjr	return (0);
102115894Stjr}
103