test-towctrans.c revision 115894
1193323Sed/*- 2193323Sed * Copyright (c) 2003 Tim J. Robbins 3193323Sed * All rights reserved. 4193323Sed * 5193323Sed * Redistribution and use in source and binary forms, with or without 6193323Sed * modification, are permitted provided that the following conditions 7193323Sed * are met: 8193323Sed * 1. Redistributions of source code must retain the above copyright 9193323Sed * notice, this list of conditions and the following disclaimer. 10193323Sed * 2. Redistributions in binary form must reproduce the above copyright 11193323Sed * notice, this list of conditions and the following disclaimer in the 12193323Sed * documentation and/or other materials provided with the distribution. 13193323Sed * 14193323Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15193323Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16193323Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17193323Sed * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18224145Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19218893Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20218893Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21193323Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22193323Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23193323Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24193323Sed * SUCH DAMAGE. 25193323Sed */ 26193323Sed 27249423Sdim/* 28218893Sdim * Test program for wctrans() and towctrans() as specified by 29218893Sdim * IEEE Std. 1003.1-2001 and ISO/IEC 9899:1999. 30218893Sdim * 31218893Sdim * The functions are tested in the "C" and "ja_JP.eucJP" locales. 32234353Sdim */ 33263508Sdim 34263508Sdim#include <sys/cdefs.h> 35263508Sdim__FBSDID("$FreeBSD: head/tools/regression/lib/libc/locale/test-towctrans.c 115894 2003-06-06 09:42:21Z tjr $"); 36263508Sdim 37251662Sdim#include <assert.h> 38218893Sdim#include <locale.h> 39218893Sdim#include <stdio.h> 40218893Sdim#include <wchar.h> 41218893Sdim#include <wctype.h> 42218893Sdim 43223017Sdimint 44249423Sdimmain(int argc, char *argv[]) 45249423Sdim{ 46249423Sdim wctype_t t; 47251662Sdim int i, j; 48218893Sdim struct { 49218893Sdim const char *name; 50218893Sdim wint_t (*func)(wint_t); 51218893Sdim } tran[] = { 52218893Sdim { "tolower", towlower }, 53218893Sdim { "toupper", towupper }, 54218893Sdim }; 55218893Sdim 56218893Sdim /* 57218893Sdim * C/POSIX locale. 58218893Sdim */ 59218893Sdim for (i = 0; i < sizeof(tran) / sizeof(*tran); i++) { 60218893Sdim t = wctrans(tran[i].name); 61218893Sdim assert(t != 0); 62218893Sdim for (j = 0; j < 256; j++) 63249423Sdim assert(tran[i].func(j) == towctrans(j, t)); 64198090Srdivacky } 65218893Sdim t = wctype("elephant"); 66218893Sdim assert(t == 0); 67249423Sdim for (i = 0; i < 256; i++) 68218893Sdim assert(towctrans(i, t) == i); 69218893Sdim 70218893Sdim /* 71218893Sdim * Japanese (EUC) locale. 72249423Sdim */ 73239462Sdim assert(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0); 74239462Sdim for (i = 0; i < sizeof(tran) / sizeof(*tran); i++) { 75249423Sdim t = wctrans(tran[i].name); 76239462Sdim assert(t != 0); 77263508Sdim for (j = 0; j < 65536; j++) 78263508Sdim assert(tran[i].func(j) == towctrans(j, t)); 79263508Sdim } 80239462Sdim t = wctype("elephant"); 81263508Sdim assert(t == 0); 82263508Sdim for (i = 0; i < 65536; i++) 83249423Sdim assert(towctrans(i, t) == i); 84249423Sdim 85249423Sdim printf("PASS towctrans()\n"); 86263508Sdim printf("PASS wctrans()\n"); 87263508Sdim 88263508Sdim return (0); 89263508Sdim} 90263508Sdim