Path: blob/main/lib/libc/tests/locale/towctrans_test.c
39491 views
/*-1* Copyright (c) 2003 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 wctrans() and towctrans() as specified by28* IEEE Std. 1003.1-2001 and ISO/IEC 9899:1999.29*30* The functions are tested in the "C" and "ja_JP.eucJP" locales.31*/3233#include <locale.h>34#include <stdio.h>35#include <string.h>36#include <wchar.h>37#include <wctype.h>3839#include <atf-c.h>4041ATF_TC_WITHOUT_HEAD(towctrans_test);42ATF_TC_BODY(towctrans_test, tc)43{44wctype_t t;45int i, j;46struct {47const char *name;48wint_t (*func)(wint_t);49} tran[] = {50{ "tolower", towlower },51{ "toupper", towupper },52};5354/* C/POSIX locale. */55for (i = 0; i < sizeof(tran) / sizeof(*tran); i++) {56t = wctrans(tran[i].name);57ATF_REQUIRE(t != 0);58for (j = 0; j < 256; j++)59ATF_REQUIRE(tran[i].func(j) == towctrans(j, t));60}61t = wctrans("elephant");62ATF_REQUIRE(t == 0);63for (i = 0; i < 256; i++)64ATF_REQUIRE(towctrans(i, t) == i);6566/* Japanese (EUC) locale. */67ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);68for (i = 0; i < sizeof(tran) / sizeof(*tran); i++) {69t = wctrans(tran[i].name);70ATF_REQUIRE(t != 0);71for (j = 0; j < 65536; j++)72ATF_REQUIRE(tran[i].func(j) == towctrans(j, t));73}74t = wctrans("elephant");75ATF_REQUIRE(t == 0);76for (i = 0; i < 65536; i++)77ATF_REQUIRE(towctrans(i, t) == i);78}7980ATF_TP_ADD_TCS(tp)81{8283ATF_TP_ADD_TC(tp, towctrans_test);8485return (atf_no_error());86}878889