1105980Stjr/*-
2105980Stjr * Copyright (c) 2002 Tim J. Robbins
3105980Stjr * All rights reserved.
4105980Stjr *
5105980Stjr * Redistribution and use in source and binary forms, with or without
6105980Stjr * modification, are permitted provided that the following conditions
7105980Stjr * are met:
8105980Stjr * 1. Redistributions of source code must retain the above copyright
9105980Stjr *    notice, this list of conditions and the following disclaimer.
10105980Stjr * 2. Redistributions in binary form must reproduce the above copyright
11105980Stjr *    notice, this list of conditions and the following disclaimer in the
12105980Stjr *    documentation and/or other materials provided with the distribution.
13105980Stjr *
14105980Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15105980Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16105980Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17105980Stjr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18105980Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19105980Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20105980Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21105980Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22105980Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23105980Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24105980Stjr * SUCH DAMAGE.
25105980Stjr */
26105980Stjr
27105980Stjr/*
28105980Stjr * Test program for btowc() and wctob() as specified by IEEE Std. 1003.1-2001
29106495Stjr * and ISO/IEC 9899:1999.
30105980Stjr *
31106727Stjr * The function is tested in the "C" and "ja_JP.eucJP" locales.
32105980Stjr */
33105980Stjr
34105980Stjr#include <sys/cdefs.h>
35105980Stjr__FBSDID("$FreeBSD$");
36105980Stjr
37105980Stjr#include <assert.h>
38105980Stjr#include <limits.h>
39106727Stjr#include <locale.h>
40105980Stjr#include <stdio.h>
41105980Stjr#include <stdlib.h>
42250989Sed#include <string.h>
43105980Stjr#include <wchar.h>
44105980Stjr
45105980Stjrint
46105980Stjrmain(int argc, char *argv[])
47105980Stjr{
48105980Stjr	int i;
49105980Stjr
50137587Snik	printf("1..2\n");
51137587Snik
52106727Stjr	/*
53106727Stjr	 * C/POSIX locale.
54106727Stjr	 */
55105980Stjr	assert(btowc(EOF) == WEOF);
56105980Stjr	assert(wctob(WEOF) == EOF);
57105980Stjr	for (i = 0; i < UCHAR_MAX; i++)
58105980Stjr		assert(btowc(i) == (wchar_t)i && i == (int)wctob(i));
59105980Stjr
60106727Stjr	/*
61106727Stjr	 * Japanese (EUC) locale.
62106727Stjr	 */
63106727Stjr
64106727Stjr	assert(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
65106727Stjr	assert(MB_CUR_MAX > 1);
66106727Stjr	assert(btowc('A') == L'A' && wctob(L'A') == 'A');
67106727Stjr	assert(btowc(0xa3) == WEOF && wctob(0xa3c1) == EOF);
68106727Stjr
69137587Snik	printf("ok 1 - btowc()\n");
70137587Snik	printf("ok 2 - wctob()\n");
71105980Stjr
72105980Stjr	return (0);
73105980Stjr}
74