LCOV - code coverage report
Current view: top level - lib/gltests - test-c-ctype.c (source / functions) Hit Total Coverage
Test: GNU Libidn Lines: 101 101 100.0 %
Date: 2016-07-20 19:34:35 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Test of character handling in C locale.
       2             :    Copyright (C) 2005, 2007-2016 Free Software Foundation, Inc.
       3             : 
       4             :    This program is free software: you can redistribute it and/or modify
       5             :    it under the terms of the GNU General Public License as published by
       6             :    the Free Software Foundation; either version 3 of the License, or
       7             :    (at your option) any later version.
       8             : 
       9             :    This program is distributed in the hope that it will be useful,
      10             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :    GNU General Public License for more details.
      13             : 
      14             :    You should have received a copy of the GNU General Public License
      15             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
      16             : 
      17             : /* Written by Bruno Haible <bruno@clisp.org>, 2005.  */
      18             : 
      19             : #include <config.h>
      20             : 
      21             : #include "c-ctype.h"
      22             : 
      23             : #include <ctype.h>
      24             : #include <limits.h>
      25             : #include <locale.h>
      26             : 
      27             : #include "macros.h"
      28             : 
      29             : static void
      30           1 : test_agree_with_C_locale (void)
      31             : {
      32             :   int c;
      33             : 
      34         257 :   for (c = 0; c <= UCHAR_MAX; c++)
      35             :     {
      36         256 :       ASSERT (c_isascii (c) == (isascii (c) != 0));
      37         256 :       if (c_isascii (c))
      38             :         {
      39         128 :           ASSERT (c_isalnum (c) == (isalnum (c) != 0));
      40         128 :           ASSERT (c_isalpha (c) == (isalpha (c) != 0));
      41         128 :           ASSERT (c_isblank (c) == (isblank (c) != 0));
      42         128 :           ASSERT (c_iscntrl (c) == (iscntrl (c) != 0));
      43         128 :           ASSERT (c_isdigit (c) == (isdigit (c) != 0));
      44         128 :           ASSERT (c_islower (c) == (islower (c) != 0));
      45         128 :           ASSERT (c_isgraph (c) == (isgraph (c) != 0));
      46         128 :           ASSERT (c_isprint (c) == (isprint (c) != 0));
      47         128 :           ASSERT (c_ispunct (c) == (ispunct (c) != 0));
      48         128 :           ASSERT (c_isspace (c) == (isspace (c) != 0));
      49         128 :           ASSERT (c_isupper (c) == (isupper (c) != 0));
      50         128 :           ASSERT (c_isxdigit (c) == (isxdigit (c) != 0));
      51         128 :           ASSERT (c_tolower (c) == tolower (c));
      52         128 :           ASSERT (c_toupper (c) == toupper (c));
      53             :         }
      54             :     }
      55           1 : }
      56             : 
      57             : static void
      58           3 : test_all (void)
      59             : {
      60             :   int c;
      61           3 :   int n_isascii = 0;
      62             : 
      63        1155 :   for (c = CHAR_MIN; c <= UCHAR_MAX; c++)
      64             :     {
      65        1152 :       if (! (0 <= c && c <= CHAR_MAX))
      66             :         {
      67         768 :           ASSERT (! c_isascii (c));
      68         768 :           ASSERT (! c_isalnum (c));
      69         768 :           ASSERT (! c_isalpha (c));
      70         768 :           ASSERT (! c_isblank (c));
      71         768 :           ASSERT (! c_iscntrl (c));
      72         768 :           ASSERT (! c_isdigit (c));
      73         768 :           ASSERT (! c_islower (c));
      74         768 :           ASSERT (! c_isgraph (c));
      75         768 :           ASSERT (! c_isprint (c));
      76         768 :           ASSERT (! c_ispunct (c));
      77         768 :           ASSERT (! c_isspace (c));
      78         768 :           ASSERT (! c_isupper (c));
      79         768 :           ASSERT (! c_isxdigit (c));
      80         768 :           ASSERT (c_tolower (c) == c);
      81         768 :           ASSERT (c_toupper (c) == c);
      82             :         }
      83             : 
      84        1152 :       n_isascii += c_isascii (c);
      85             : 
      86             : #ifdef C_CTYPE_ASCII
      87        1152 :       ASSERT (c_isascii (c) == (0 <= c && c <= 0x7f));
      88             : #endif
      89             : 
      90        1152 :       ASSERT (c_isascii (c) == (c_isprint (c) || c_iscntrl (c)));
      91             : 
      92        1152 :       ASSERT (c_isalnum (c) == (c_isalpha (c) || c_isdigit (c)));
      93             : 
      94        1152 :       ASSERT (c_isalpha (c) == (c_islower (c) || c_isupper (c)));
      95             : 
      96        1152 :       switch (c)
      97             :         {
      98             :         case '\t': case ' ':
      99           6 :           ASSERT (c_isblank (c) == 1);
     100           6 :           break;
     101             :         default:
     102        1146 :           ASSERT (c_isblank (c) == 0);
     103        1146 :           break;
     104             :         }
     105             : 
     106             : #ifdef C_CTYPE_ASCII
     107        1152 :       ASSERT (c_iscntrl (c) == ((c >= 0 && c < 0x20) || c == 0x7f));
     108             : #endif
     109             : 
     110        1152 :       switch (c)
     111             :         {
     112             :         case '\a': case '\b': case '\f': case '\n':
     113             :         case '\r': case '\t': case '\v':
     114          21 :           ASSERT (c_iscntrl (c));
     115          21 :           break;
     116             :         }
     117             : 
     118        1152 :       ASSERT (! (c_iscntrl (c) && c_isprint (c)));
     119             : 
     120        1152 :       switch (c)
     121             :         {
     122             :         case '0': case '1': case '2': case '3': case '4': case '5':
     123             :         case '6': case '7': case '8': case '9':
     124          30 :           ASSERT (c_isdigit (c) == 1);
     125          30 :           break;
     126             :         default:
     127        1122 :           ASSERT (c_isdigit (c) == 0);
     128        1122 :           break;
     129             :         }
     130             : 
     131        1152 :       switch (c)
     132             :         {
     133             :         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
     134             :         case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
     135             :         case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
     136             :         case 's': case 't': case 'u': case 'v': case 'w': case 'x':
     137             :         case 'y': case 'z':
     138          78 :           ASSERT (c_islower (c) == 1);
     139          78 :           ASSERT (c_toupper (c) == c - 'a' + 'A');
     140          78 :           break;
     141             :         default:
     142        1074 :           ASSERT (c_islower (c) == 0);
     143        1074 :           ASSERT (c_toupper (c) == c);
     144        1074 :           break;
     145             :         }
     146             : 
     147             : #ifdef C_CTYPE_ASCII
     148        1152 :       ASSERT (c_isgraph (c) == ((c >= 0x20 && c < 0x7f) && c != ' '));
     149             : 
     150        1152 :       ASSERT (c_isprint (c) == (c >= 0x20 && c < 0x7f));
     151             : #endif
     152             : 
     153        1152 :       ASSERT (c_isgraph (c) == (c_isalnum (c) || c_ispunct (c)));
     154             : 
     155        1152 :       ASSERT (c_isprint (c) == (c_isgraph (c) || c == ' '));
     156             : 
     157        1152 :       switch (c)
     158             :         {
     159             :         case '!': case '"': case '#': case '$': case '%': case '&': case '\'':
     160             :         case '(': case ')': case '*': case '+': case ',': case '-': case '.':
     161             :         case '/': case ':': case ';': case '<': case '=': case '>': case '?':
     162             :         case '@': case '[': case'\\': case ']': case '^': case '_': case '`':
     163             :         case '{': case '|': case '}': case '~':
     164          96 :           ASSERT (c_ispunct (c) == 1);
     165          96 :           break;
     166             :         default:
     167        1056 :           ASSERT (c_ispunct (c) == 0);
     168        1056 :           break;
     169             :         }
     170             : 
     171        1152 :       switch (c)
     172             :         {
     173             :         case ' ': case '\t': case '\n': case '\v': case '\f': case '\r':
     174          18 :           ASSERT (c_isspace (c) == 1);
     175          18 :           break;
     176             :         default:
     177        1134 :           ASSERT (c_isspace (c) == 0);
     178        1134 :           break;
     179             :         }
     180             : 
     181        1152 :       switch (c)
     182             :         {
     183             :         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
     184             :         case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
     185             :         case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
     186             :         case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
     187             :         case 'Y': case 'Z':
     188          78 :           ASSERT (c_isupper (c) == 1);
     189          78 :           ASSERT (c_tolower (c) == c - 'A' + 'a');
     190          78 :           break;
     191             :         default:
     192        1074 :           ASSERT (c_isupper (c) == 0);
     193        1074 :           ASSERT (c_tolower (c) == c);
     194        1074 :           break;
     195             :         }
     196             : 
     197        1152 :       switch (c)
     198             :         {
     199             :         case '0': case '1': case '2': case '3': case '4': case '5':
     200             :         case '6': case '7': case '8': case '9':
     201             :         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
     202             :         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
     203          66 :           ASSERT (c_isxdigit (c) == 1);
     204          66 :           break;
     205             :         default:
     206        1086 :           ASSERT (c_isxdigit (c) == 0);
     207        1086 :           break;
     208             :         }
     209             :     }
     210             : 
     211           3 :   ASSERT (n_isascii == 128);
     212           3 : }
     213             : 
     214             : int
     215           1 : main ()
     216             : {
     217           1 :   test_agree_with_C_locale ();
     218             : 
     219           1 :   test_all ();
     220             : 
     221           1 :   setlocale (LC_ALL, "de_DE");
     222           1 :   test_all ();
     223             : 
     224           1 :   setlocale (LC_ALL, "ja_JP.EUC-JP");
     225           1 :   test_all ();
     226             : 
     227           1 :   return 0;
     228             : }

Generated by: LCOV version 1.11