|
Packit Service |
fdd496 |
/* Test of character handling in C locale.
|
|
Packit Service |
fdd496 |
Copyright (C) 2005, 2007-2017 Free Software Foundation, Inc.
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
fdd496 |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
fdd496 |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
fdd496 |
(at your option) any later version.
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
fdd496 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
fdd496 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
fdd496 |
GNU General Public License for more details.
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
fdd496 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
/* Written by Bruno Haible <bruno@clisp.org>, 2005. */
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#include <config.h>
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#include "c-ctype.h"
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#include <ctype.h>
|
|
Packit Service |
fdd496 |
#include <limits.h>
|
|
Packit Service |
fdd496 |
#include <locale.h>
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#include "macros.h"
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
static void
|
|
Packit Service |
fdd496 |
test_agree_with_C_locale (void)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
int c;
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
for (c = 0; c <= UCHAR_MAX; c++)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
ASSERT (c_isascii (c) == (isascii (c) != 0));
|
|
Packit Service |
fdd496 |
if (c_isascii (c))
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
ASSERT (c_isalnum (c) == (isalnum (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_isalpha (c) == (isalpha (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_isblank (c) == (isblank (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_iscntrl (c) == (iscntrl (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_isdigit (c) == (isdigit (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_islower (c) == (islower (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_isgraph (c) == (isgraph (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_isprint (c) == (isprint (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_ispunct (c) == (ispunct (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_isspace (c) == (isspace (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_isupper (c) == (isupper (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_isxdigit (c) == (isxdigit (c) != 0));
|
|
Packit Service |
fdd496 |
ASSERT (c_tolower (c) == tolower (c));
|
|
Packit Service |
fdd496 |
ASSERT (c_toupper (c) == toupper (c));
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
static void
|
|
Packit Service |
fdd496 |
test_all (void)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
int c;
|
|
Packit Service |
fdd496 |
int n_isascii = 0;
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
for (c = CHAR_MIN; c <= UCHAR_MAX; c++)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
if (! (0 <= c && c <= CHAR_MAX))
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
ASSERT (! c_isascii (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_isalnum (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_isalpha (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_isblank (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_iscntrl (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_isdigit (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_islower (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_isgraph (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_isprint (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_ispunct (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_isspace (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_isupper (c));
|
|
Packit Service |
fdd496 |
ASSERT (! c_isxdigit (c));
|
|
Packit Service |
fdd496 |
ASSERT (c_tolower (c) == c);
|
|
Packit Service |
fdd496 |
ASSERT (c_toupper (c) == c);
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
n_isascii += c_isascii (c);
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#ifdef C_CTYPE_ASCII
|
|
Packit Service |
fdd496 |
ASSERT (c_isascii (c) == (0 <= c && c <= 0x7f));
|
|
Packit Service |
fdd496 |
#endif
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
ASSERT (c_isascii (c) == (c_isprint (c) || c_iscntrl (c)));
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
ASSERT (c_isalnum (c) == (c_isalpha (c) || c_isdigit (c)));
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
ASSERT (c_isalpha (c) == (c_islower (c) || c_isupper (c)));
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
switch (c)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
case '\t': case ' ':
|
|
Packit Service |
fdd496 |
ASSERT (c_isblank (c) == 1);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
default:
|
|
Packit Service |
fdd496 |
ASSERT (c_isblank (c) == 0);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#ifdef C_CTYPE_ASCII
|
|
Packit Service |
fdd496 |
ASSERT (c_iscntrl (c) == ((c >= 0 && c < 0x20) || c == 0x7f));
|
|
Packit Service |
fdd496 |
#endif
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
switch (c)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
case '\a': case '\b': case '\f': case '\n':
|
|
Packit Service |
fdd496 |
case '\r': case '\t': case '\v':
|
|
Packit Service |
fdd496 |
ASSERT (c_iscntrl (c));
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
ASSERT (! (c_iscntrl (c) && c_isprint (c)));
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
switch (c)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
case '0': case '1': case '2': case '3': case '4': case '5':
|
|
Packit Service |
fdd496 |
case '6': case '7': case '8': case '9':
|
|
Packit Service |
fdd496 |
ASSERT (c_isdigit (c) == 1);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
default:
|
|
Packit Service |
fdd496 |
ASSERT (c_isdigit (c) == 0);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
switch (c)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
|
Packit Service |
fdd496 |
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
|
|
Packit Service |
fdd496 |
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
|
|
Packit Service |
fdd496 |
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
|
|
Packit Service |
fdd496 |
case 'y': case 'z':
|
|
Packit Service |
fdd496 |
ASSERT (c_islower (c) == 1);
|
|
Packit Service |
fdd496 |
ASSERT (c_toupper (c) == c - 'a' + 'A');
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
default:
|
|
Packit Service |
fdd496 |
ASSERT (c_islower (c) == 0);
|
|
Packit Service |
fdd496 |
ASSERT (c_toupper (c) == c);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
#ifdef C_CTYPE_ASCII
|
|
Packit Service |
fdd496 |
ASSERT (c_isgraph (c) == ((c >= 0x20 && c < 0x7f) && c != ' '));
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
ASSERT (c_isprint (c) == (c >= 0x20 && c < 0x7f));
|
|
Packit Service |
fdd496 |
#endif
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
ASSERT (c_isgraph (c) == (c_isalnum (c) || c_ispunct (c)));
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
ASSERT (c_isprint (c) == (c_isgraph (c) || c == ' '));
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
switch (c)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
case '!': case '"': case '#': case '$': case '%': case '&': case '\'':
|
|
Packit Service |
fdd496 |
case '(': case ')': case '*': case '+': case ',': case '-': case '.':
|
|
Packit Service |
fdd496 |
case '/': case ':': case ';': case '<': case '=': case '>': case '?':
|
|
Packit Service |
fdd496 |
case '@': case '[': case'\\': case ']': case '^': case '_': case '`':
|
|
Packit Service |
fdd496 |
case '{': case '|': case '}': case '~':
|
|
Packit Service |
fdd496 |
ASSERT (c_ispunct (c) == 1);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
default:
|
|
Packit Service |
fdd496 |
ASSERT (c_ispunct (c) == 0);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
switch (c)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
case ' ': case '\t': case '\n': case '\v': case '\f': case '\r':
|
|
Packit Service |
fdd496 |
ASSERT (c_isspace (c) == 1);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
default:
|
|
Packit Service |
fdd496 |
ASSERT (c_isspace (c) == 0);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
switch (c)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
|
Packit Service |
fdd496 |
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
|
|
Packit Service |
fdd496 |
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
|
|
Packit Service |
fdd496 |
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
|
|
Packit Service |
fdd496 |
case 'Y': case 'Z':
|
|
Packit Service |
fdd496 |
ASSERT (c_isupper (c) == 1);
|
|
Packit Service |
fdd496 |
ASSERT (c_tolower (c) == c - 'A' + 'a');
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
default:
|
|
Packit Service |
fdd496 |
ASSERT (c_isupper (c) == 0);
|
|
Packit Service |
fdd496 |
ASSERT (c_tolower (c) == c);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
switch (c)
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
case '0': case '1': case '2': case '3': case '4': case '5':
|
|
Packit Service |
fdd496 |
case '6': case '7': case '8': case '9':
|
|
Packit Service |
fdd496 |
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
|
Packit Service |
fdd496 |
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
|
Packit Service |
fdd496 |
ASSERT (c_isxdigit (c) == 1);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
default:
|
|
Packit Service |
fdd496 |
ASSERT (c_isxdigit (c) == 0);
|
|
Packit Service |
fdd496 |
break;
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
ASSERT (n_isascii == 128);
|
|
Packit Service |
fdd496 |
}
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
int
|
|
Packit Service |
fdd496 |
main ()
|
|
Packit Service |
fdd496 |
{
|
|
Packit Service |
fdd496 |
test_agree_with_C_locale ();
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
test_all ();
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
setlocale (LC_ALL, "de_DE");
|
|
Packit Service |
fdd496 |
test_all ();
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
setlocale (LC_ALL, "ja_JP.EUC-JP");
|
|
Packit Service |
fdd496 |
test_all ();
|
|
Packit Service |
fdd496 |
|
|
Packit Service |
fdd496 |
return 0;
|
|
Packit Service |
fdd496 |
}
|