Back to index

glibc  2.9
test_wctype.c
Go to the documentation of this file.
00001 /* Copyright (C) 1996, 1997, 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 <ctype.h>
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <wctype.h>
00023 
00024 int
00025 main (int argc, char *argv[])
00026 {
00027   int result = 0;
00028   wctype_t bit_alnum = wctype ("alnum");
00029   wctype_t bit_alpha = wctype ("alpha");
00030   wctype_t bit_cntrl = wctype ("cntrl");
00031   wctype_t bit_digit = wctype ("digit");
00032   wctype_t bit_graph = wctype ("graph");
00033   wctype_t bit_lower = wctype ("lower");
00034   wctype_t bit_print = wctype ("print");
00035   wctype_t bit_punct = wctype ("punct");
00036   wctype_t bit_space = wctype ("space");
00037   wctype_t bit_upper = wctype ("upper");
00038   wctype_t bit_xdigit = wctype ("xdigit");
00039   int ch;
00040 
00041   if (wctype ("does not exist") != 0)
00042     {
00043       puts ("wctype return value != 0 for non existing property");
00044       result = 1;
00045     }
00046 
00047   for (ch = 0; ch < 256; ++ch)
00048     {
00049 #define TEST(test) \
00050       do                                                             \
00051        {                                                             \
00052          if ((is##test (ch) == 0) != (iswctype (ch, bit_##test) == 0))             \
00053            {                                                         \
00054              printf ("`iswctype' class `%s' test "                          \
00055                     "for character \\%o failed\n", #test, ch);       \
00056              result = 1;                                             \
00057            }                                                         \
00058          if ((is##test (ch) == 0) != (isw##test (ch) == 0))                 \
00059            {                                                         \
00060              printf ("`isw%s' test for character \\%o failed\n",            \
00061                     #test, ch);                                      \
00062              result = 1;                                             \
00063            }                                                         \
00064         }                                                            \
00065       while (0)
00066 
00067       TEST (alnum);
00068       TEST (alpha);
00069       TEST (cntrl);
00070       TEST (digit);
00071       TEST (graph);
00072       TEST (lower);
00073       TEST (print);
00074       TEST (punct);
00075       TEST (space);
00076       TEST (upper);
00077       TEST (xdigit);
00078     }
00079 
00080   if (result == 0)
00081     puts ("All test successful!");
00082   return result;
00083 }