Back to index

glibc  2.9
tst-trans.c
Go to the documentation of this file.
00001 /* Test program for user-defined character maps.
00002    Copyright (C) 1999, 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <locale.h>
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <wchar.h>
00026 #include <wctype.h>
00027 
00028 int
00029 main (void)
00030 {
00031   char buf[30];
00032   wchar_t wbuf[30];
00033   wctrans_t t;
00034   wint_t wch;
00035   int errors = 0;
00036   int len;
00037 
00038   setlocale (LC_ALL, "");
00039 
00040   t = wctrans ("test");
00041   if (t == (wctrans_t) 0)
00042     {
00043       puts ("locale data files probably not loaded");
00044       exit (1);
00045     }
00046 
00047   wch = towctrans (L'A', t);
00048   printf ("towctrans (L'A', t) = %c\n", wch);
00049   if (wch != L'B')
00050     errors = 1;
00051 
00052   wch = towctrans (L'B', t);
00053   printf ("towctrans (L'B', t) = %c\n", wch);
00054   if (wch != L'C')
00055     errors = 1;
00056 
00057   /* Test the output digit handling.  */
00058   swprintf (wbuf, sizeof (wbuf) / sizeof (wbuf[0]), L"%Id", 0x499602D2);
00059   errors |= wcscmp (wbuf, L"bcdefghija") != 0;
00060   len = wcslen (wbuf);
00061   errors |= len != 10;
00062   printf ("len = %d, wbuf = L\"%ls\"\n", len, wbuf);
00063 
00064   snprintf (buf, sizeof buf, "%Id", 0x499602D2);
00065   errors |= strcmp (buf, "bcdefghija") != 0;
00066   len = strlen (buf);
00067   errors |= len != 10;
00068   printf ("len = %d, buf = \"%s\"\n", len, buf);
00069 
00070   return errors;
00071 }