Back to index

glibc  2.9
test6.c
Go to the documentation of this file.
00001 /* Test program for character classes and mappings.
00002    Copyright (C) 1999 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
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 <ctype.h>
00022 #include <locale.h>
00023 #include <wchar.h>
00024 
00025 
00026 int
00027 main (void)
00028 {
00029   const char lower[] = "abcdefghijklmnopqrstuvwxyz";
00030   const char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
00031 #define LEN (sizeof (upper) - 1)
00032   const wchar_t wlower[] = L"abcdefghijklmnopqrstuvwxyz";
00033   const wchar_t wupper[] = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
00034   int i;
00035   int result = 0;
00036 
00037   setlocale (LC_ALL, "test6");
00038 
00039   for (i = 0; i < LEN; ++i)
00040     {
00041       /* Test basic table handling (basic == not more than 256 characters).
00042         The charmaps swaps the normal lower-upper case meaning of the
00043         ASCII characters used in the source code while the Unicode mapping
00044         in the repertoire map has the normal correspondants.  This test
00045         shows the independence of the tables for `char' and `wchar_t'
00046         characters.  */
00047 
00048       if (islower (lower[i]))
00049        {
00050          printf ("islower ('%c') false\n", lower[i]);
00051          result = 1;
00052        }
00053       if (! isupper (lower[i]))
00054        {
00055          printf ("isupper ('%c') false\n", lower[i]);
00056          result = 1;
00057        }
00058 
00059       if (! islower (upper[i]))
00060        {
00061          printf ("islower ('%c') false\n", upper[i]);
00062          result = 1;
00063        }
00064       if (isupper (upper[i]))
00065        {
00066          printf ("isupper ('%c') false\n", upper[i]);
00067          result = 1;
00068        }
00069 
00070       if (toupper (lower[i]) != lower[i])
00071        {
00072          printf ("toupper ('%c') false\n", lower[i]);
00073          result = 1;
00074        }
00075       if (tolower (lower[i]) != upper[i])
00076        {
00077          printf ("tolower ('%c') false\n", lower[i]);
00078          result = 1;
00079        }
00080 
00081       if (tolower (upper[i]) != upper[i])
00082        {
00083          printf ("tolower ('%c') false\n", upper[i]);
00084          result = 1;
00085        }
00086       if (toupper (upper[i]) != lower[i])
00087        {
00088          printf ("toupper ('%c') false\n", upper[i]);
00089          result = 1;
00090        }
00091 
00092       if (iswlower (wupper[i]))
00093        {
00094          printf ("iswlower (L'%c') false\n", upper[i]);
00095          result = 1;
00096        }
00097       if (! iswupper (wupper[i]))
00098        {
00099          printf ("iswupper (L'%c') false\n", upper[i]);
00100          result = 1;
00101        }
00102 
00103       if (iswupper (wlower[i]))
00104        {
00105          printf ("iswupper (L'%c') false\n", lower[i]);
00106          result = 1;
00107        }
00108       if (! iswlower (wlower[i]))
00109        {
00110          printf ("iswlower (L'%c') false\n", lower[i]);
00111          result = 1;
00112        }
00113 
00114       if (towupper (wlower[i]) != wupper[i])
00115        {
00116          printf ("towupper ('%c') false\n", lower[i]);
00117          result = 1;
00118        }
00119       if (towlower (wlower[i]) != wlower[i])
00120        {
00121          printf ("towlower ('%c') false\n", lower[i]);
00122          result = 1;
00123        }
00124 
00125       if (towlower (wupper[i]) != wlower[i])
00126        {
00127          printf ("towlower ('%c') false\n", upper[i]);
00128          result = 1;
00129        }
00130       if (towupper (wupper[i]) != wupper[i])
00131        {
00132          printf ("towupper ('%c') false\n", upper[i]);
00133          result = 1;
00134        }
00135     }
00136 
00137   return result;
00138 }