]> Savannah Git Hosting - gnulib.git/commitdiff
Test that c_iscntrl agrees with iscntrl, etc.
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 23 Sep 2015 19:26:38 +0000 (12:26 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 23 Sep 2015 19:27:21 +0000 (12:27 -0700)
Suggested by Daniel Richard G. in:
http://lists.gnu.org/archive/html/bug-gnulib/2015-09/msg00034.html
* modules/c-ctype-tests (Depends-on): Add ctype.
* tests/test-c-ctype.c: Include <ctype.h>.
(NCHARS): New constant.
(test_agree_with_C_locale): New function.
(main): Use it.
(test_all): Use named constants.

ChangeLog
modules/c-ctype-tests
tests/test-c-ctype.c

index 493c915f82f5b621ffb49cfd6afb460ad6b69533..7eca2c4bdcd4360c791af98b891d104fb5f75327 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2015-09-23  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Test that c_iscntrl agrees with iscntrl, etc.
+       Suggested by Daniel Richard G. in:
+       http://lists.gnu.org/archive/html/bug-gnulib/2015-09/msg00034.html
+       * modules/c-ctype-tests (Depends-on): Add ctype.
+       * tests/test-c-ctype.c: Include <ctype.h>.
+       (NCHARS): New constant.
+       (test_agree_with_C_locale): New function.
+       (main): Use it.
+       (test_all): Use named constants.
+
        c-ctype: improve c_isascii testing
        * tests/test-c-ctype.c (test_all): Port c_isascii test to EBCDIC.
        Add a test to count the number of ASCII characters.
index 196f529998b5dacc96aacf7ff12870d888eacbd3..cb65ee34acd7f8395ceef1f907e0f4a273cbe1dc 100644 (file)
@@ -3,10 +3,10 @@ tests/test-c-ctype.c
 tests/macros.h
 
 Depends-on:
+ctype
 
 configure.ac:
 
 Makefile.am:
 TESTS += test-c-ctype
 check_PROGRAMS += test-c-ctype
-
index 80eb69de60924e7edc7104eaf4cffbc374f7034a..481cbbb53079e388c2f06a766952d064b142780b 100644 (file)
 
 #include "c-ctype.h"
 
+#include <ctype.h>
 #include <limits.h>
 #include <locale.h>
 
 #include "macros.h"
 
+enum { NCHARS = UCHAR_MAX + 1 };
+
 static char
 to_char (int c)
 {
@@ -33,31 +36,59 @@ to_char (int c)
   return c;
 }
 
+static void
+test_agree_with_C_locale (void)
+{
+  int c;
+
+  for (c = 0; c <= UCHAR_MAX; c++)
+    {
+      ASSERT (c_isascii (c) == (isascii (c) != 0));
+      if (c_isascii (c))
+        {
+          ASSERT (c_isalnum (c) == (isalnum (c) != 0));
+          ASSERT (c_isalpha (c) == (isalpha (c) != 0));
+          ASSERT (c_isblank (c) == (isblank (c) != 0));
+          ASSERT (c_iscntrl (c) == (iscntrl (c) != 0));
+          ASSERT (c_isdigit (c) == (isdigit (c) != 0));
+          ASSERT (c_islower (c) == (islower (c) != 0));
+          ASSERT (c_isgraph (c) == (isgraph (c) != 0));
+          ASSERT (c_isprint (c) == (isprint (c) != 0));
+          ASSERT (c_ispunct (c) == (ispunct (c) != 0));
+          ASSERT (c_isspace (c) == (isspace (c) != 0));
+          ASSERT (c_isupper (c) == (isupper (c) != 0));
+          ASSERT (c_isxdigit (c) == (isxdigit (c) != 0));
+          ASSERT (c_tolower (c) == tolower (c));
+          ASSERT (c_toupper (c) == toupper (c));
+        }
+    }
+}
+
 static void
 test_all (void)
 {
   int c;
   int n_isascii = 0;
 
-  for (c = -0x80; c < 0x100; c++)
+  for (c = SCHAR_MIN; c <= UCHAR_MAX; c++)
     {
       if (c < 0)
         {
-          ASSERT (c_isascii (c) == c_isascii (c + 0x100));
-          ASSERT (c_isalnum (c) == c_isalnum (c + 0x100));
-          ASSERT (c_isalpha (c) == c_isalpha (c + 0x100));
-          ASSERT (c_isblank (c) == c_isblank (c + 0x100));
-          ASSERT (c_iscntrl (c) == c_iscntrl (c + 0x100));
-          ASSERT (c_isdigit (c) == c_isdigit (c + 0x100));
-          ASSERT (c_islower (c) == c_islower (c + 0x100));
-          ASSERT (c_isgraph (c) == c_isgraph (c + 0x100));
-          ASSERT (c_isprint (c) == c_isprint (c + 0x100));
-          ASSERT (c_ispunct (c) == c_ispunct (c + 0x100));
-          ASSERT (c_isspace (c) == c_isspace (c + 0x100));
-          ASSERT (c_isupper (c) == c_isupper (c + 0x100));
-          ASSERT (c_isxdigit (c) == c_isxdigit (c + 0x100));
-          ASSERT (to_char (c_tolower (c)) == to_char (c_tolower (c + 0x100)));
-          ASSERT (to_char (c_toupper (c)) == to_char (c_toupper (c + 0x100)));
+          ASSERT (c_isascii (c) == c_isascii (c + NCHARS));
+          ASSERT (c_isalnum (c) == c_isalnum (c + NCHARS));
+          ASSERT (c_isalpha (c) == c_isalpha (c + NCHARS));
+          ASSERT (c_isblank (c) == c_isblank (c + NCHARS));
+          ASSERT (c_iscntrl (c) == c_iscntrl (c + NCHARS));
+          ASSERT (c_isdigit (c) == c_isdigit (c + NCHARS));
+          ASSERT (c_islower (c) == c_islower (c + NCHARS));
+          ASSERT (c_isgraph (c) == c_isgraph (c + NCHARS));
+          ASSERT (c_isprint (c) == c_isprint (c + NCHARS));
+          ASSERT (c_ispunct (c) == c_ispunct (c + NCHARS));
+          ASSERT (c_isspace (c) == c_isspace (c + NCHARS));
+          ASSERT (c_isupper (c) == c_isupper (c + NCHARS));
+          ASSERT (c_isxdigit (c) == c_isxdigit (c + NCHARS));
+          ASSERT (to_char (c_tolower (c)) == to_char (c_tolower (c + NCHARS)));
+          ASSERT (to_char (c_toupper (c)) == to_char (c_toupper (c + NCHARS)));
         }
 
       if (0 <= c)
@@ -394,6 +425,8 @@ test_all (void)
 int
 main ()
 {
+  test_agree_with_C_locale ();
+
   test_all ();
 
   setlocale (LC_ALL, "de_DE");