powerpc: Add the lock elision using HTM
[platform/upstream/glibc.git] / localedata / tst-ctype.c
index 729ff66..62fb11f 100644 (file)
@@ -1,24 +1,24 @@
-/* Copyright (C) 2000 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2015 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@gnu.org>, 2000.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <ctype.h>
 #include <locale.h>
+#include <langinfo.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -26,6 +26,9 @@
 static const char lower[] = "abcdefghijklmnopqrstuvwxyz";
 static const char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 static const char digits[] = "0123456789";
+static const char cntrl[] = "\
+\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\
+\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f ";
 
 
 static struct classes
@@ -58,8 +61,8 @@ static struct classes
   }
 
 
-int
-main (void)
+static int
+do_test (void)
 {
   const char *cp;
   const char *cp2;
@@ -68,13 +71,16 @@ main (void)
   size_t inplinelen = 0;
   char *resline = NULL;
   size_t reslinelen = 0;
-  int n;
+  size_t n;
+  const unsigned short int *__ctype_b;
 
   setlocale (LC_ALL, "");
 
   printf ("Testing the ctype data of the `%s' locale\n",
          setlocale (LC_CTYPE, NULL));
 
+  __ctype_b = ((const unsigned short *) nl_langinfo (_NL_CTYPE_CLASS)) + 128;
+
 #if 0
   /* Just for debugging.  */
 
@@ -115,8 +121,8 @@ punct = %04x  alnum = %04x\n",
     FAIL ("isgraph ('\\0') is true");
   if (isblank ('\0'))
     FAIL ("isblank ('\\0') is true");
-  if (iscntrl ('\0'))
-    FAIL ("iscntrl ('\\0') is true");
+  if (iscntrl ('\0'))
+    FAIL ("iscntrl ('\\0') not true");
   if (ispunct ('\0'))
     FAIL ("ispunct ('\\0') is true");
   if (isalnum ('\0'))
@@ -132,6 +138,9 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (islower (*cp))
       FAIL ("islower ('%c') is true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if (islower (*cp))
+      FAIL ("islower ('\\x%02x') is true", *cp);
 
   puts ("    isupper()");
   for (cp = lower; *cp != '\0'; ++cp)
@@ -143,6 +152,9 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (isupper (*cp))
       FAIL ("isupper ('%c') is true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if (isupper (*cp))
+      FAIL ("isupper ('\\x%02x') is true", *cp);
 
   puts ("    isalpha()");
   for (cp = lower; *cp != '\0'; ++cp)
@@ -154,6 +166,9 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (isalpha (*cp))
       FAIL ("isalpha ('%c') is true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if (isalpha (*cp))
+      FAIL ("isalpha ('\\x%02x') is true", *cp);
 
   puts ("    isdigit()");
   for (cp = lower; *cp != '\0'; ++cp)
@@ -165,6 +180,9 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (! isdigit (*cp))
       FAIL ("isdigit ('%c') not true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if (isdigit (*cp))
+      FAIL ("isdigit ('\\x%02x') is true", *cp);
 
   puts ("    isxdigit()");
   for (cp = lower; *cp != '\0'; ++cp)
@@ -178,6 +196,9 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (! isxdigit (*cp))
       FAIL ("isxdigit ('%c') not true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if (isxdigit (*cp))
+      FAIL ("isxdigit ('\\x%02x') is true", *cp);
 
   puts ("    isspace()");
   for (cp = lower; *cp != '\0'; ++cp)
@@ -189,6 +210,12 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (isspace (*cp))
       FAIL ("isspace ('%c') is true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if ((isspace (*cp) && ((*cp < '\x09' || *cp > '\x0d') && *cp != ' '))
+       || (! isspace (*cp)
+           && ((*cp >= '\x09' && *cp <= '\x0d') || *cp == ' ')))
+      FAIL ("isspace ('\\x%02x') %s true", *cp,
+           (*cp < '\x09' || *cp > '\x0d') ? "is" : "not");
 
   puts ("    isprint()");
   for (cp = lower; *cp != '\0'; ++cp)
@@ -200,6 +227,10 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (! isprint (*cp))
       FAIL ("isprint ('%c') not true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if ((isprint (*cp) && *cp != ' ')
+       || (! isprint (*cp) && *cp == ' '))
+      FAIL ("isprint ('\\x%02x') is true", *cp);
 
   puts ("    isgraph()");
   for (cp = lower; *cp != '\0'; ++cp)
@@ -211,6 +242,9 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (! isgraph (*cp))
       FAIL ("isgraph ('%c') not true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if (isgraph (*cp))
+      FAIL ("isgraph ('\\x%02x') is true", *cp);
 
   puts ("    isblank()");
   for (cp = lower; *cp != '\0'; ++cp)
@@ -222,6 +256,10 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (isblank (*cp))
       FAIL ("isblank ('%c') is true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if ((isblank (*cp) && *cp != '\x09' && *cp != ' ')
+       || (! isblank (*cp) && (*cp == '\x09' || *cp == ' ')))
+      FAIL ("isblank ('\\x%02x') %s true", *cp, *cp != '\x09' ? "is" : "not");
 
   puts ("    iscntrl()");
   for (cp = lower; *cp != '\0'; ++cp)
@@ -233,6 +271,10 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (iscntrl (*cp))
       FAIL ("iscntrl ('%c') is true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if ((iscntrl (*cp) && *cp == ' ')
+       || (! iscntrl (*cp) && *cp != ' '))
+      FAIL ("iscntrl ('\\x%02x') not true", *cp);
 
   puts ("    ispunct()");
   for (cp = lower; *cp != '\0'; ++cp)
@@ -244,6 +286,9 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (ispunct (*cp))
       FAIL ("ispunct ('%c') is true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if (ispunct (*cp))
+      FAIL ("ispunct ('\\x%02x') is true", *cp);
 
   puts ("    isalnum()");
   for (cp = lower; *cp != '\0'; ++cp)
@@ -255,6 +300,9 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (! isalnum (*cp))
       FAIL ("isalnum ('%c') not true", *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if (isalnum (*cp))
+      FAIL ("isalnum ('\\x%02x') is true", *cp);
 
 
   puts ("    tolower()");
@@ -267,6 +315,9 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (tolower (*cp) != *cp)
       FAIL ("tolower ('%c') != '%c'", *cp, *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if (tolower (*cp) != *cp)
+      FAIL ("tolower ('\\x%02x') != '\\x%02x'", *cp, *cp);
 
   puts ("    toupper()");
   for (cp = lower, cp2 = upper; *cp != '\0'; ++cp, ++cp2)
@@ -278,6 +329,9 @@ punct = %04x  alnum = %04x\n",
   for (cp = digits; *cp != '\0'; ++cp)
     if (toupper (*cp) != *cp)
       FAIL ("toupper ('%c') != '%c'", *cp, *cp);
+  for (cp = cntrl; *cp != '\0'; ++cp)
+    if (toupper (*cp) != *cp)
+      FAIL ("toupper ('\\x%02x') != '\\x%02x'", *cp, *cp);
 
 
   /* Now some locale specific tests.  */
@@ -290,14 +344,14 @@ punct = %04x  alnum = %04x\n",
          || getline (&resline, &reslinelen, stdin) <= 0)
        break;
 
-      inp = strchr (inpline, '\n');
+      inp = (unsigned char *) strchr (inpline, '\n');
       if (inp != NULL)
        *inp = '\0';
-      resp = strchr (resline, '\n');
+      resp = (unsigned char *) strchr (resline, '\n');
       if (resp != NULL)
        *resp = '\0';
 
-      inp = inpline;
+      inp = (unsigned char *) inpline;
       while (*inp != ' ' && *inp != '\t' && *inp && *inp != '\n'
             && *inp != '\0')
        ++inp;
@@ -316,11 +370,11 @@ punct = %04x  alnum = %04x\n",
        if (strcmp (inpline, classes[n].name) == 0)
          break;
 
-      resp = resline;
+      resp = (unsigned char *) resline;
       while (*resp == ' ' || *resp == '\t')
        ++resp;
 
-      if (strlen (inp) != strlen (resp))
+      if (strlen ((char *) inp) != strlen ((char *) resp))
        {
          printf ("lines \"%.20s\"... and \"%.20s\" have not the same length\n",
                  inp, resp);
@@ -329,7 +383,7 @@ punct = %04x  alnum = %04x\n",
 
       if (n < nclasses)
        {
-         if (strspn (resp, "01") != strlen (resp))
+         if (strspn ((char *) resp, "01") != strlen ((char *) resp))
            {
              printf ("result string \"%s\" malformed\n", resp);
              continue;
@@ -393,3 +447,6 @@ punct = %04x  alnum = %04x\n",
   printf ("  No errors for `%s' locale\n\n\n", setlocale (LC_ALL, NULL));
   return 0;
 }
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"