1115894Stjr/*- 2115894Stjr * Copyright (c) 2003 Tim J. Robbins 3115894Stjr * All rights reserved. 4115894Stjr * 5115894Stjr * Redistribution and use in source and binary forms, with or without 6115894Stjr * modification, are permitted provided that the following conditions 7115894Stjr * are met: 8115894Stjr * 1. Redistributions of source code must retain the above copyright 9115894Stjr * notice, this list of conditions and the following disclaimer. 10115894Stjr * 2. Redistributions in binary form must reproduce the above copyright 11115894Stjr * notice, this list of conditions and the following disclaimer in the 12115894Stjr * documentation and/or other materials provided with the distribution. 13115894Stjr * 14115894Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15115894Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16115894Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17115894Stjr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18115894Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19115894Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20115894Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21115894Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22115894Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23115894Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24115894Stjr * SUCH DAMAGE. 25115894Stjr */ 26115894Stjr 27115894Stjr/* 28115894Stjr * Test program for wctrans() and towctrans() as specified by 29115894Stjr * IEEE Std. 1003.1-2001 and ISO/IEC 9899:1999. 30115894Stjr * 31115894Stjr * The functions are tested in the "C" and "ja_JP.eucJP" locales. 32115894Stjr */ 33115894Stjr 34115894Stjr#include <sys/cdefs.h> 35115894Stjr__FBSDID("$FreeBSD$"); 36115894Stjr 37115894Stjr#include <assert.h> 38115894Stjr#include <locale.h> 39115894Stjr#include <stdio.h> 40250989Sed#include <string.h> 41115894Stjr#include <wchar.h> 42115894Stjr#include <wctype.h> 43115894Stjr 44115894Stjrint 45115894Stjrmain(int argc, char *argv[]) 46115894Stjr{ 47115894Stjr wctype_t t; 48115894Stjr int i, j; 49115894Stjr struct { 50115894Stjr const char *name; 51115894Stjr wint_t (*func)(wint_t); 52115894Stjr } tran[] = { 53115894Stjr { "tolower", towlower }, 54115894Stjr { "toupper", towupper }, 55115894Stjr }; 56115894Stjr 57137587Snik printf("1..2\n"); 58137587Snik 59115894Stjr /* 60115894Stjr * C/POSIX locale. 61115894Stjr */ 62115894Stjr for (i = 0; i < sizeof(tran) / sizeof(*tran); i++) { 63115894Stjr t = wctrans(tran[i].name); 64115894Stjr assert(t != 0); 65115894Stjr for (j = 0; j < 256; j++) 66115894Stjr assert(tran[i].func(j) == towctrans(j, t)); 67115894Stjr } 68132391Stjr t = wctrans("elephant"); 69115894Stjr assert(t == 0); 70115894Stjr for (i = 0; i < 256; i++) 71115894Stjr assert(towctrans(i, t) == i); 72115894Stjr 73115894Stjr /* 74115894Stjr * Japanese (EUC) locale. 75115894Stjr */ 76115894Stjr assert(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0); 77115894Stjr for (i = 0; i < sizeof(tran) / sizeof(*tran); i++) { 78115894Stjr t = wctrans(tran[i].name); 79115894Stjr assert(t != 0); 80115894Stjr for (j = 0; j < 65536; j++) 81115894Stjr assert(tran[i].func(j) == towctrans(j, t)); 82115894Stjr } 83132391Stjr t = wctrans("elephant"); 84115894Stjr assert(t == 0); 85115894Stjr for (i = 0; i < 65536; i++) 86115894Stjr assert(towctrans(i, t) == i); 87115894Stjr 88137587Snik printf("ok 1 - towctrans()\n"); 89137587Snik printf("ok 2 - wctrans()\n"); 90115894Stjr 91115894Stjr return (0); 92115894Stjr} 93