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