LCOV - code coverage report
Current view: top level - lib/gltests - test-c-ctype.c (source / functions) Hit Total Coverage
Test: GNU Libidn Lines: 215 215 100.0 %
Date: 2015-03-02 11:46:03 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Test of character handling in C locale.
       2             :    Copyright (C) 2005, 2007-2015 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 <locale.h>
      24             : 
      25             : #include "macros.h"
      26             : 
      27             : static void
      28           3 : test_all (void)
      29             : {
      30             :   int c;
      31             : 
      32        1155 :   for (c = -0x80; c < 0x100; c++)
      33             :     {
      34        1152 :       ASSERT (c_isascii (c) == (c >= 0 && c < 0x80));
      35             : 
      36        1152 :       switch (c)
      37             :         {
      38             :         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
      39             :         case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
      40             :         case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
      41             :         case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
      42             :         case 'Y': case 'Z':
      43             :         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
      44             :         case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
      45             :         case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
      46             :         case 's': case 't': case 'u': case 'v': case 'w': case 'x':
      47             :         case 'y': case 'z':
      48             :         case '0': case '1': case '2': case '3': case '4': case '5':
      49             :         case '6': case '7': case '8': case '9':
      50         186 :           ASSERT (c_isalnum (c) == 1);
      51         186 :           break;
      52             :         default:
      53         966 :           ASSERT (c_isalnum (c) == 0);
      54         966 :           break;
      55             :         }
      56             : 
      57        1152 :       switch (c)
      58             :         {
      59             :         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
      60             :         case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
      61             :         case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
      62             :         case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
      63             :         case 'Y': case 'Z':
      64             :         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
      65             :         case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
      66             :         case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
      67             :         case 's': case 't': case 'u': case 'v': case 'w': case 'x':
      68             :         case 'y': case 'z':
      69         156 :           ASSERT (c_isalpha (c) == 1);
      70         156 :           break;
      71             :         default:
      72         996 :           ASSERT (c_isalpha (c) == 0);
      73         996 :           break;
      74             :         }
      75             : 
      76        1152 :       switch (c)
      77             :         {
      78             :         case '\t': case ' ':
      79           6 :           ASSERT (c_isblank (c) == 1);
      80           6 :           break;
      81             :         default:
      82        1146 :           ASSERT (c_isblank (c) == 0);
      83        1146 :           break;
      84             :         }
      85             : 
      86        1152 :       ASSERT (c_iscntrl (c) == ((c >= 0 && c < 0x20) || c == 0x7f));
      87             : 
      88        1152 :       switch (c)
      89             :         {
      90             :         case '0': case '1': case '2': case '3': case '4': case '5':
      91             :         case '6': case '7': case '8': case '9':
      92          30 :           ASSERT (c_isdigit (c) == 1);
      93          30 :           break;
      94             :         default:
      95        1122 :           ASSERT (c_isdigit (c) == 0);
      96        1122 :           break;
      97             :         }
      98             : 
      99        1152 :       switch (c)
     100             :         {
     101             :         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
     102             :         case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
     103             :         case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
     104             :         case 's': case 't': case 'u': case 'v': case 'w': case 'x':
     105             :         case 'y': case 'z':
     106          78 :           ASSERT (c_islower (c) == 1);
     107          78 :           break;
     108             :         default:
     109        1074 :           ASSERT (c_islower (c) == 0);
     110        1074 :           break;
     111             :         }
     112             : 
     113        1152 :       ASSERT (c_isgraph (c) == ((c >= 0x20 && c < 0x7f) && c != ' '));
     114             : 
     115        1152 :       ASSERT (c_isprint (c) == (c >= 0x20 && c < 0x7f));
     116             : 
     117        1152 :       ASSERT (c_ispunct (c) == (c_isgraph (c) && !c_isalnum (c)));
     118             : 
     119        1152 :       switch (c)
     120             :         {
     121             :         case ' ': case '\t': case '\n': case '\v': case '\f': case '\r':
     122          18 :           ASSERT (c_isspace (c) == 1);
     123          18 :           break;
     124             :         default:
     125        1134 :           ASSERT (c_isspace (c) == 0);
     126        1134 :           break;
     127             :         }
     128             : 
     129        1152 :       switch (c)
     130             :         {
     131             :         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
     132             :         case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
     133             :         case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
     134             :         case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
     135             :         case 'Y': case 'Z':
     136          78 :           ASSERT (c_isupper (c) == 1);
     137          78 :           break;
     138             :         default:
     139        1074 :           ASSERT (c_isupper (c) == 0);
     140        1074 :           break;
     141             :         }
     142             : 
     143        1152 :       switch (c)
     144             :         {
     145             :         case '0': case '1': case '2': case '3': case '4': case '5':
     146             :         case '6': case '7': case '8': case '9':
     147             :         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
     148             :         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
     149          66 :           ASSERT (c_isxdigit (c) == 1);
     150          66 :           break;
     151             :         default:
     152        1086 :           ASSERT (c_isxdigit (c) == 0);
     153        1086 :           break;
     154             :         }
     155             : 
     156        1152 :       switch (c)
     157             :         {
     158             :         case 'A':
     159           3 :           ASSERT (c_tolower (c) == 'a');
     160           3 :           ASSERT (c_toupper (c) == c);
     161           3 :           break;
     162             :         case 'B':
     163           3 :           ASSERT (c_tolower (c) == 'b');
     164           3 :           ASSERT (c_toupper (c) == c);
     165           3 :           break;
     166             :         case 'C':
     167           3 :           ASSERT (c_tolower (c) == 'c');
     168           3 :           ASSERT (c_toupper (c) == c);
     169           3 :           break;
     170             :         case 'D':
     171           3 :           ASSERT (c_tolower (c) == 'd');
     172           3 :           ASSERT (c_toupper (c) == c);
     173           3 :           break;
     174             :         case 'E':
     175           3 :           ASSERT (c_tolower (c) == 'e');
     176           3 :           ASSERT (c_toupper (c) == c);
     177           3 :           break;
     178             :         case 'F':
     179           3 :           ASSERT (c_tolower (c) == 'f');
     180           3 :           ASSERT (c_toupper (c) == c);
     181           3 :           break;
     182             :         case 'G':
     183           3 :           ASSERT (c_tolower (c) == 'g');
     184           3 :           ASSERT (c_toupper (c) == c);
     185           3 :           break;
     186             :         case 'H':
     187           3 :           ASSERT (c_tolower (c) == 'h');
     188           3 :           ASSERT (c_toupper (c) == c);
     189           3 :           break;
     190             :         case 'I':
     191           3 :           ASSERT (c_tolower (c) == 'i');
     192           3 :           ASSERT (c_toupper (c) == c);
     193           3 :           break;
     194             :         case 'J':
     195           3 :           ASSERT (c_tolower (c) == 'j');
     196           3 :           ASSERT (c_toupper (c) == c);
     197           3 :           break;
     198             :         case 'K':
     199           3 :           ASSERT (c_tolower (c) == 'k');
     200           3 :           ASSERT (c_toupper (c) == c);
     201           3 :           break;
     202             :         case 'L':
     203           3 :           ASSERT (c_tolower (c) == 'l');
     204           3 :           ASSERT (c_toupper (c) == c);
     205           3 :           break;
     206             :         case 'M':
     207           3 :           ASSERT (c_tolower (c) == 'm');
     208           3 :           ASSERT (c_toupper (c) == c);
     209           3 :           break;
     210             :         case 'N':
     211           3 :           ASSERT (c_tolower (c) == 'n');
     212           3 :           ASSERT (c_toupper (c) == c);
     213           3 :           break;
     214             :         case 'O':
     215           3 :           ASSERT (c_tolower (c) == 'o');
     216           3 :           ASSERT (c_toupper (c) == c);
     217           3 :           break;
     218             :         case 'P':
     219           3 :           ASSERT (c_tolower (c) == 'p');
     220           3 :           ASSERT (c_toupper (c) == c);
     221           3 :           break;
     222             :         case 'Q':
     223           3 :           ASSERT (c_tolower (c) == 'q');
     224           3 :           ASSERT (c_toupper (c) == c);
     225           3 :           break;
     226             :         case 'R':
     227           3 :           ASSERT (c_tolower (c) == 'r');
     228           3 :           ASSERT (c_toupper (c) == c);
     229           3 :           break;
     230             :         case 'S':
     231           3 :           ASSERT (c_tolower (c) == 's');
     232           3 :           ASSERT (c_toupper (c) == c);
     233           3 :           break;
     234             :         case 'T':
     235           3 :           ASSERT (c_tolower (c) == 't');
     236           3 :           ASSERT (c_toupper (c) == c);
     237           3 :           break;
     238             :         case 'U':
     239           3 :           ASSERT (c_tolower (c) == 'u');
     240           3 :           ASSERT (c_toupper (c) == c);
     241           3 :           break;
     242             :         case 'V':
     243           3 :           ASSERT (c_tolower (c) == 'v');
     244           3 :           ASSERT (c_toupper (c) == c);
     245           3 :           break;
     246             :         case 'W':
     247           3 :           ASSERT (c_tolower (c) == 'w');
     248           3 :           ASSERT (c_toupper (c) == c);
     249           3 :           break;
     250             :         case 'X':
     251           3 :           ASSERT (c_tolower (c) == 'x');
     252           3 :           ASSERT (c_toupper (c) == c);
     253           3 :           break;
     254             :         case 'Y':
     255           3 :           ASSERT (c_tolower (c) == 'y');
     256           3 :           ASSERT (c_toupper (c) == c);
     257           3 :           break;
     258             :         case 'Z':
     259           3 :           ASSERT (c_tolower (c) == 'z');
     260           3 :           ASSERT (c_toupper (c) == c);
     261           3 :           break;
     262             :         case 'a':
     263           3 :           ASSERT (c_tolower (c) == c);
     264           3 :           ASSERT (c_toupper (c) == 'A');
     265           3 :           break;
     266             :         case 'b':
     267           3 :           ASSERT (c_tolower (c) == c);
     268           3 :           ASSERT (c_toupper (c) == 'B');
     269           3 :           break;
     270             :         case 'c':
     271           3 :           ASSERT (c_tolower (c) == c);
     272           3 :           ASSERT (c_toupper (c) == 'C');
     273           3 :           break;
     274             :         case 'd':
     275           3 :           ASSERT (c_tolower (c) == c);
     276           3 :           ASSERT (c_toupper (c) == 'D');
     277           3 :           break;
     278             :         case 'e':
     279           3 :           ASSERT (c_tolower (c) == c);
     280           3 :           ASSERT (c_toupper (c) == 'E');
     281           3 :           break;
     282             :         case 'f':
     283           3 :           ASSERT (c_tolower (c) == c);
     284           3 :           ASSERT (c_toupper (c) == 'F');
     285           3 :           break;
     286             :         case 'g':
     287           3 :           ASSERT (c_tolower (c) == c);
     288           3 :           ASSERT (c_toupper (c) == 'G');
     289           3 :           break;
     290             :         case 'h':
     291           3 :           ASSERT (c_tolower (c) == c);
     292           3 :           ASSERT (c_toupper (c) == 'H');
     293           3 :           break;
     294             :         case 'i':
     295           3 :           ASSERT (c_tolower (c) == c);
     296           3 :           ASSERT (c_toupper (c) == 'I');
     297           3 :           break;
     298             :         case 'j':
     299           3 :           ASSERT (c_tolower (c) == c);
     300           3 :           ASSERT (c_toupper (c) == 'J');
     301           3 :           break;
     302             :         case 'k':
     303           3 :           ASSERT (c_tolower (c) == c);
     304           3 :           ASSERT (c_toupper (c) == 'K');
     305           3 :           break;
     306             :         case 'l':
     307           3 :           ASSERT (c_tolower (c) == c);
     308           3 :           ASSERT (c_toupper (c) == 'L');
     309           3 :           break;
     310             :         case 'm':
     311           3 :           ASSERT (c_tolower (c) == c);
     312           3 :           ASSERT (c_toupper (c) == 'M');
     313           3 :           break;
     314             :         case 'n':
     315           3 :           ASSERT (c_tolower (c) == c);
     316           3 :           ASSERT (c_toupper (c) == 'N');
     317           3 :           break;
     318             :         case 'o':
     319           3 :           ASSERT (c_tolower (c) == c);
     320           3 :           ASSERT (c_toupper (c) == 'O');
     321           3 :           break;
     322             :         case 'p':
     323           3 :           ASSERT (c_tolower (c) == c);
     324           3 :           ASSERT (c_toupper (c) == 'P');
     325           3 :           break;
     326             :         case 'q':
     327           3 :           ASSERT (c_tolower (c) == c);
     328           3 :           ASSERT (c_toupper (c) == 'Q');
     329           3 :           break;
     330             :         case 'r':
     331           3 :           ASSERT (c_tolower (c) == c);
     332           3 :           ASSERT (c_toupper (c) == 'R');
     333           3 :           break;
     334             :         case 's':
     335           3 :           ASSERT (c_tolower (c) == c);
     336           3 :           ASSERT (c_toupper (c) == 'S');
     337           3 :           break;
     338             :         case 't':
     339           3 :           ASSERT (c_tolower (c) == c);
     340           3 :           ASSERT (c_toupper (c) == 'T');
     341           3 :           break;
     342             :         case 'u':
     343           3 :           ASSERT (c_tolower (c) == c);
     344           3 :           ASSERT (c_toupper (c) == 'U');
     345           3 :           break;
     346             :         case 'v':
     347           3 :           ASSERT (c_tolower (c) == c);
     348           3 :           ASSERT (c_toupper (c) == 'V');
     349           3 :           break;
     350             :         case 'w':
     351           3 :           ASSERT (c_tolower (c) == c);
     352           3 :           ASSERT (c_toupper (c) == 'W');
     353           3 :           break;
     354             :         case 'x':
     355           3 :           ASSERT (c_tolower (c) == c);
     356           3 :           ASSERT (c_toupper (c) == 'X');
     357           3 :           break;
     358             :         case 'y':
     359           3 :           ASSERT (c_tolower (c) == c);
     360           3 :           ASSERT (c_toupper (c) == 'Y');
     361           3 :           break;
     362             :         case 'z':
     363           3 :           ASSERT (c_tolower (c) == c);
     364           3 :           ASSERT (c_toupper (c) == 'Z');
     365           3 :           break;
     366             :         default:
     367         996 :           ASSERT (c_tolower (c) == c);
     368         996 :           ASSERT (c_toupper (c) == c);
     369         996 :           break;
     370             :         }
     371             :     }
     372           3 : }
     373             : 
     374             : int
     375           1 : main ()
     376             : {
     377           1 :   test_all ();
     378             : 
     379           1 :   setlocale (LC_ALL, "de_DE");
     380           1 :   test_all ();
     381             : 
     382           1 :   setlocale (LC_ALL, "ja_JP.EUC-JP");
     383           1 :   test_all ();
     384             : 
     385           1 :   return 0;
     386             : }

Generated by: LCOV version 1.11