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 <limits.h> 38106727Stjr#include <locale.h> 39105980Stjr#include <stdio.h> 40105980Stjr#include <stdlib.h> 41250989Sed#include <string.h> 42105980Stjr#include <wchar.h> 43105980Stjr 44290532Sngie#include <atf-c.h> 45290532Sngie 46290532SngieATF_TC_WITHOUT_HEAD(btowc_test); 47290532SngieATF_TC_BODY(btowc_test, tc) 48105980Stjr{ 49105980Stjr int i; 50105980Stjr 51290532Sngie /* C/POSIX locale. */ 52290532Sngie ATF_REQUIRE(btowc(EOF) == WEOF); 53290532Sngie ATF_REQUIRE(wctob(WEOF) == EOF); 54105980Stjr for (i = 0; i < UCHAR_MAX; i++) 55290532Sngie ATF_REQUIRE(btowc(i) == (wchar_t)i && i == (int)wctob(i)); 56105980Stjr 57290532Sngie /* Japanese (EUC) locale. */ 58290532Sngie ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0); 59290532Sngie ATF_REQUIRE(MB_CUR_MAX > 1); 60290532Sngie ATF_REQUIRE(btowc('A') == L'A' && wctob(L'A') == 'A'); 61290532Sngie ATF_REQUIRE(btowc(0xa3) == WEOF && wctob(0xa3c1) == EOF); 62106727Stjr 63290532Sngie} 64106727Stjr 65290532SngieATF_TP_ADD_TCS(tp) 66290532Sngie{ 67105980Stjr 68290532Sngie ATF_TP_ADD_TC(tp, btowc_test); 69290532Sngie 70290532Sngie return (atf_no_error()); 71105980Stjr} 72