Path: blob/main/lib/libc/tests/locale/btowc_test.c
39491 views
/*-1* Copyright (c) 2002 Tim J. Robbins2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526/*27* Test program for btowc() and wctob() as specified by IEEE Std. 1003.1-200128* and ISO/IEC 9899:1999.29*30* The function is tested in the "C" and "ja_JP.eucJP" locales.31*/3233#include <limits.h>34#include <locale.h>35#include <stdio.h>36#include <stdlib.h>37#include <string.h>38#include <wchar.h>3940#include <atf-c.h>4142ATF_TC_WITHOUT_HEAD(btowc_test);43ATF_TC_BODY(btowc_test, tc)44{45int i;4647/* C/POSIX locale. */48ATF_REQUIRE(btowc(EOF) == WEOF);49ATF_REQUIRE(wctob(WEOF) == EOF);50for (i = 0; i < UCHAR_MAX; i++)51ATF_REQUIRE(btowc(i) == (wchar_t)i && i == (int)wctob(i));5253/* Japanese (EUC) locale. */54ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);55ATF_REQUIRE(MB_CUR_MAX > 1);56ATF_REQUIRE(btowc('A') == L'A' && wctob(L'A') == 'A');57ATF_REQUIRE(btowc(0xa3) == WEOF && wctob(0xa3c1) == EOF);5859}6061ATF_TP_ADD_TCS(tp)62{6364ATF_TP_ADD_TC(tp, btowc_test);6566return (atf_no_error());67}686970