summaryrefslogtreecommitdiff
path: root/tests/test-c-ctype.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-c-ctype.c')
-rw-r--r--tests/test-c-ctype.c354
1 files changed, 98 insertions, 256 deletions
diff --git a/tests/test-c-ctype.c b/tests/test-c-ctype.c
index 81fe936e..184cdec6 100644
--- a/tests/test-c-ctype.c
+++ b/tests/test-c-ctype.c
@@ -1,5 +1,5 @@
/* Test of character handling in C locale.
- Copyright (C) 2005, 2007-2015 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2007-2016 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,59 +20,79 @@
#include "c-ctype.h"
+#include <ctype.h>
+#include <limits.h>
#include <locale.h>
#include "macros.h"
static void
-test_all (void)
+test_agree_with_C_locale (void)
{
int c;
- for (c = -0x80; c < 0x100; c++)
+ for (c = 0; c <= UCHAR_MAX; c++)
{
- ASSERT (c_isascii (c) == (c >= 0 && c < 0x80));
-
- switch (c)
+ ASSERT (c_isascii (c) == (isascii (c) != 0));
+ if (c_isascii (c))
{
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
- case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
- case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
- case 'Y': case 'Z':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
- case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
- case 's': case 't': case 'u': case 'v': case 'w': case 'x':
- case 'y': case 'z':
- case '0': case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- ASSERT (c_isalnum (c) == 1);
- break;
- default:
- ASSERT (c_isalnum (c) == 0);
- break;
+ 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));
}
+ }
+}
- switch (c)
+static void
+test_all (void)
+{
+ int c;
+ int n_isascii = 0;
+
+ for (c = CHAR_MIN; c <= UCHAR_MAX; c++)
+ {
+ if (! (0 <= c && c <= CHAR_MAX))
{
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
- case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
- case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
- case 'Y': case 'Z':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
- case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
- case 's': case 't': case 'u': case 'v': case 'w': case 'x':
- case 'y': case 'z':
- ASSERT (c_isalpha (c) == 1);
- break;
- default:
- ASSERT (c_isalpha (c) == 0);
- break;
+ ASSERT (! c_isascii (c));
+ ASSERT (! c_isalnum (c));
+ ASSERT (! c_isalpha (c));
+ ASSERT (! c_isblank (c));
+ ASSERT (! c_iscntrl (c));
+ ASSERT (! c_isdigit (c));
+ ASSERT (! c_islower (c));
+ ASSERT (! c_isgraph (c));
+ ASSERT (! c_isprint (c));
+ ASSERT (! c_ispunct (c));
+ ASSERT (! c_isspace (c));
+ ASSERT (! c_isupper (c));
+ ASSERT (! c_isxdigit (c));
+ ASSERT (c_tolower (c) == c);
+ ASSERT (c_toupper (c) == c);
}
+ n_isascii += c_isascii (c);
+
+#ifdef C_CTYPE_ASCII
+ ASSERT (c_isascii (c) == (0 <= c && c <= 0x7f));
+#endif
+
+ ASSERT (c_isascii (c) == (c_isprint (c) || c_iscntrl (c)));
+
+ ASSERT (c_isalnum (c) == (c_isalpha (c) || c_isdigit (c)));
+
+ ASSERT (c_isalpha (c) == (c_islower (c) || c_isupper (c)));
+
switch (c)
{
case '\t': case ' ':
@@ -83,7 +103,19 @@ test_all (void)
break;
}
+#ifdef C_CTYPE_ASCII
ASSERT (c_iscntrl (c) == ((c >= 0 && c < 0x20) || c == 0x7f));
+#endif
+
+ switch (c)
+ {
+ case '\a': case '\b': case '\f': case '\n':
+ case '\r': case '\t': case '\v':
+ ASSERT (c_iscntrl (c));
+ break;
+ }
+
+ ASSERT (! (c_iscntrl (c) && c_isprint (c)));
switch (c)
{
@@ -104,17 +136,37 @@ test_all (void)
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
ASSERT (c_islower (c) == 1);
+ ASSERT (c_toupper (c) == c - 'a' + 'A');
break;
default:
ASSERT (c_islower (c) == 0);
+ ASSERT (c_toupper (c) == c);
break;
}
+#ifdef C_CTYPE_ASCII
ASSERT (c_isgraph (c) == ((c >= 0x20 && c < 0x7f) && c != ' '));
ASSERT (c_isprint (c) == (c >= 0x20 && c < 0x7f));
+#endif
+
+ ASSERT (c_isgraph (c) == (c_isalnum (c) || c_ispunct (c)));
+
+ ASSERT (c_isprint (c) == (c_isgraph (c) || c == ' '));
- ASSERT (c_ispunct (c) == (c_isgraph (c) && !c_isalnum (c)));
+ switch (c)
+ {
+ case '!': case '"': case '#': case '$': case '%': case '&': case '\'':
+ case '(': case ')': case '*': case '+': case ',': case '-': case '.':
+ case '/': case ':': case ';': case '<': case '=': case '>': case '?':
+ case '@': case '[': case'\\': case ']': case '^': case '_': case '`':
+ case '{': case '|': case '}': case '~':
+ ASSERT (c_ispunct (c) == 1);
+ break;
+ default:
+ ASSERT (c_ispunct (c) == 0);
+ break;
+ }
switch (c)
{
@@ -134,9 +186,11 @@ test_all (void)
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
ASSERT (c_isupper (c) == 1);
+ ASSERT (c_tolower (c) == c - 'A' + 'a');
break;
default:
ASSERT (c_isupper (c) == 0);
+ ASSERT (c_tolower (c) == c);
break;
}
@@ -152,228 +206,16 @@ test_all (void)
ASSERT (c_isxdigit (c) == 0);
break;
}
-
- switch (c)
- {
- case 'A':
- ASSERT (c_tolower (c) == 'a');
- ASSERT (c_toupper (c) == c);
- break;
- case 'B':
- ASSERT (c_tolower (c) == 'b');
- ASSERT (c_toupper (c) == c);
- break;
- case 'C':
- ASSERT (c_tolower (c) == 'c');
- ASSERT (c_toupper (c) == c);
- break;
- case 'D':
- ASSERT (c_tolower (c) == 'd');
- ASSERT (c_toupper (c) == c);
- break;
- case 'E':
- ASSERT (c_tolower (c) == 'e');
- ASSERT (c_toupper (c) == c);
- break;
- case 'F':
- ASSERT (c_tolower (c) == 'f');
- ASSERT (c_toupper (c) == c);
- break;
- case 'G':
- ASSERT (c_tolower (c) == 'g');
- ASSERT (c_toupper (c) == c);
- break;
- case 'H':
- ASSERT (c_tolower (c) == 'h');
- ASSERT (c_toupper (c) == c);
- break;
- case 'I':
- ASSERT (c_tolower (c) == 'i');
- ASSERT (c_toupper (c) == c);
- break;
- case 'J':
- ASSERT (c_tolower (c) == 'j');
- ASSERT (c_toupper (c) == c);
- break;
- case 'K':
- ASSERT (c_tolower (c) == 'k');
- ASSERT (c_toupper (c) == c);
- break;
- case 'L':
- ASSERT (c_tolower (c) == 'l');
- ASSERT (c_toupper (c) == c);
- break;
- case 'M':
- ASSERT (c_tolower (c) == 'm');
- ASSERT (c_toupper (c) == c);
- break;
- case 'N':
- ASSERT (c_tolower (c) == 'n');
- ASSERT (c_toupper (c) == c);
- break;
- case 'O':
- ASSERT (c_tolower (c) == 'o');
- ASSERT (c_toupper (c) == c);
- break;
- case 'P':
- ASSERT (c_tolower (c) == 'p');
- ASSERT (c_toupper (c) == c);
- break;
- case 'Q':
- ASSERT (c_tolower (c) == 'q');
- ASSERT (c_toupper (c) == c);
- break;
- case 'R':
- ASSERT (c_tolower (c) == 'r');
- ASSERT (c_toupper (c) == c);
- break;
- case 'S':
- ASSERT (c_tolower (c) == 's');
- ASSERT (c_toupper (c) == c);
- break;
- case 'T':
- ASSERT (c_tolower (c) == 't');
- ASSERT (c_toupper (c) == c);
- break;
- case 'U':
- ASSERT (c_tolower (c) == 'u');
- ASSERT (c_toupper (c) == c);
- break;
- case 'V':
- ASSERT (c_tolower (c) == 'v');
- ASSERT (c_toupper (c) == c);
- break;
- case 'W':
- ASSERT (c_tolower (c) == 'w');
- ASSERT (c_toupper (c) == c);
- break;
- case 'X':
- ASSERT (c_tolower (c) == 'x');
- ASSERT (c_toupper (c) == c);
- break;
- case 'Y':
- ASSERT (c_tolower (c) == 'y');
- ASSERT (c_toupper (c) == c);
- break;
- case 'Z':
- ASSERT (c_tolower (c) == 'z');
- ASSERT (c_toupper (c) == c);
- break;
- case 'a':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'A');
- break;
- case 'b':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'B');
- break;
- case 'c':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'C');
- break;
- case 'd':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'D');
- break;
- case 'e':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'E');
- break;
- case 'f':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'F');
- break;
- case 'g':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'G');
- break;
- case 'h':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'H');
- break;
- case 'i':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'I');
- break;
- case 'j':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'J');
- break;
- case 'k':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'K');
- break;
- case 'l':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'L');
- break;
- case 'm':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'M');
- break;
- case 'n':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'N');
- break;
- case 'o':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'O');
- break;
- case 'p':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'P');
- break;
- case 'q':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'Q');
- break;
- case 'r':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'R');
- break;
- case 's':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'S');
- break;
- case 't':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'T');
- break;
- case 'u':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'U');
- break;
- case 'v':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'V');
- break;
- case 'w':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'W');
- break;
- case 'x':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'X');
- break;
- case 'y':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'Y');
- break;
- case 'z':
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == 'Z');
- break;
- default:
- ASSERT (c_tolower (c) == c);
- ASSERT (c_toupper (c) == c);
- break;
- }
}
+
+ ASSERT (n_isascii == 128);
}
int
main ()
{
+ test_agree_with_C_locale ();
+
test_all ();
setlocale (LC_ALL, "de_DE");