Back to index

glibc  2.9
test_wcfuncs.c
Go to the documentation of this file.
00001 /* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <wctype.h>
00022 
00023 int
00024 main (int argc, char *argv[])
00025 {
00026   int result = 0;
00027   wint_t ch;
00028 
00029 
00030   for (ch = 0; ch < 128; ++ch)
00031     {
00032       if (iswlower (ch))
00033        {
00034          /* Get corresponding upper case character.  */
00035          wint_t up = towupper (ch);
00036          /* This should have no effect.  */
00037          wint_t low  = towlower (ch);
00038 
00039          if ((ch != low) || (up == ch) || (up == low))
00040            {
00041              printf ("iswlower/towupper/towlower for character \\%x failed\n", ch);
00042              result++;
00043            }
00044        }
00045       if (iswupper (ch))
00046        {
00047          /* Get corresponding lower case character.  */
00048          wint_t low = towlower (ch);
00049          /* This should have no effect.  */
00050          wint_t up  = towupper (ch);
00051 
00052          if ((ch != up) || (low == ch) || (up == low))
00053            {
00054              printf ("iswupper/towlower/towupper for character \\%x failed\n", ch);
00055              result++;
00056            }
00057        }
00058     }
00059 
00060   /* Finally some specific tests.  */
00061   ch = L'A';
00062   if (!iswupper (ch) || iswlower (ch))
00063     {
00064       printf ("!iswupper/iswlower (L'A') failed\n");
00065       result++;
00066 
00067     }
00068   ch = L'a';
00069   if (iswupper (ch) || !iswlower (ch))
00070     {
00071       printf ("iswupper/!iswlower (L'a') failed\n");
00072       result++;
00073     }
00074   if (towlower (L'A') != L'a')
00075     {
00076       printf ("towlower(L'A') failed\n");
00077       result++;
00078     }
00079   if (towupper (L'a') != L'A')
00080     {
00081       printf ("towupper(L'a') failed\n");
00082       result++;
00083     }
00084 
00085   if (result == 0)
00086     puts ("All test successful!");
00087   return result != 0;
00088 }