summaryrefslogtreecommitdiff
path: root/localedata/tst-ctype.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-06-27 03:59:26 +0000
committerUlrich Drepper <drepper@redhat.com>2000-06-27 03:59:26 +0000
commit4edc30e4d70ff4bd49abf8dc5a98502f07ff5991 (patch)
tree8c50e8709e54a5d13e100b34744c085d4e722660 /localedata/tst-ctype.c
parent6ba025af6916737a4b895890caf3ef32b5efbb16 (diff)
Update.
* tst-ctype.c: Read in more tests from stdin. * tst-ctype.sh: Feed extra test data to program via stdin. * tst-ctype-de_DE.in: New file. * locales/i18n (punct): Exclude U00A0. (blank): Include U00A0. * locales/ja_JP: Updates for new format. * Makefile (test-srcs): Add tst-ctype. (distribute): Add tst-ctype.sh. (do-tst-ctype): New target. Run for tests. * tst-ctype.c: New file. * tst-ctype.sh: New file.
Diffstat (limited to 'localedata/tst-ctype.c')
-rw-r--r--localedata/tst-ctype.c172
1 files changed, 151 insertions, 21 deletions
diff --git a/localedata/tst-ctype.c b/localedata/tst-ctype.c
index 9ee678201f..729ff6689a 100644
--- a/localedata/tst-ctype.c
+++ b/localedata/tst-ctype.c
@@ -20,6 +20,7 @@
#include <ctype.h>
#include <locale.h>
#include <stdio.h>
+#include <string.h>
static const char lower[] = "abcdefghijklmnopqrstuvwxyz";
@@ -27,6 +28,29 @@ static const char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const char digits[] = "0123456789";
+static struct classes
+{
+ const char *name;
+ int mask;
+} classes[] =
+{
+#define ENTRY(name) { #name, _IS##name }
+ ENTRY (upper),
+ ENTRY (lower),
+ ENTRY (alpha),
+ ENTRY (digit),
+ ENTRY (xdigit),
+ ENTRY (space),
+ ENTRY (print),
+ ENTRY (graph),
+ ENTRY (blank),
+ ENTRY (cntrl),
+ ENTRY (punct),
+ ENTRY (alnum)
+};
+#define nclasses (sizeof (classes) / sizeof (classes[0]))
+
+
#define FAIL(str, args...) \
{ \
printf (" " str "\n", ##args); \
@@ -40,6 +64,11 @@ main (void)
const char *cp;
const char *cp2;
int errors = 0;
+ char *inpline = NULL;
+ size_t inplinelen = 0;
+ char *resline = NULL;
+ size_t reslinelen = 0;
+ int n;
setlocale (LC_ALL, "");
@@ -48,25 +77,23 @@ main (void)
#if 0
/* Just for debugging. */
- {
- /* Contents of the class array. */
- int n = 0;
-
- printf ("upper = %04x lower = %04x alpha = %04x digit = %04x xdigit = %04x\n"
- "space = %04x print = %04x graph = %04x blank = %04x cntrl = %04x\n"
- "punct = %04x alnum = %04x\n",
- _ISupper, _ISlower, _ISalpha, _ISdigit, _ISxdigit,
- _ISspace, _ISprint, _ISgraph, _ISblank, _IScntrl,
- _ISpunct, _ISalnum);
-
- while (n < 256)
- {
- if (n % 8 == 0)
- printf ("%02x: ", n);
- printf ("%04x%s", __ctype_b[n], (n + 1) % 8 == 0 ? "\n" : " ");
- ++n;
- }
- }
+
+ /* Contents of the class array. */
+ printf ("\
+upper = %04x lower = %04x alpha = %04x digit = %04x xdigit = %04x\n\
+space = %04x print = %04x graph = %04x blank = %04x cntrl = %04x\n\
+punct = %04x alnum = %04x\n",
+ _ISupper, _ISlower, _ISalpha, _ISdigit, _ISxdigit,
+ _ISspace, _ISprint, _ISgraph, _ISblank, _IScntrl,
+ _ISpunct, _ISalnum);
+
+ while (n < 256)
+ {
+ if (n % 8 == 0)
+ printf ("%02x: ", n);
+ printf ("%04x%s", __ctype_b[n], (n + 1) % 8 == 0 ? "\n" : " ");
+ ++n;
+ }
#endif
puts (" Test of ASCII character range\n special NUL byte handling");
@@ -253,10 +280,113 @@ main (void)
FAIL ("toupper ('%c') != '%c'", *cp, *cp);
+ /* Now some locale specific tests. */
+ while (! feof (stdin))
+ {
+ unsigned char *inp;
+ unsigned char *resp;
+
+ if (getline (&inpline, &inplinelen, stdin) <= 0
+ || getline (&resline, &reslinelen, stdin) <= 0)
+ break;
+
+ inp = strchr (inpline, '\n');
+ if (inp != NULL)
+ *inp = '\0';
+ resp = strchr (resline, '\n');
+ if (resp != NULL)
+ *resp = '\0';
+
+ inp = inpline;
+ while (*inp != ' ' && *inp != '\t' && *inp && *inp != '\n'
+ && *inp != '\0')
+ ++inp;
+
+ if (*inp == '\0')
+ {
+ printf ("line \"%s\" is without content\n", inpline);
+ continue;
+ }
+ *inp++ = '\0';
+ while (*inp == ' ' || *inp == '\t')
+ ++inp;
+
+ /* Try all classes. */
+ for (n = 0; n < nclasses; ++n)
+ if (strcmp (inpline, classes[n].name) == 0)
+ break;
+
+ resp = resline;
+ while (*resp == ' ' || *resp == '\t')
+ ++resp;
+
+ if (strlen (inp) != strlen (resp))
+ {
+ printf ("lines \"%.20s\"... and \"%.20s\" have not the same length\n",
+ inp, resp);
+ continue;
+ }
+
+ if (n < nclasses)
+ {
+ if (strspn (resp, "01") != strlen (resp))
+ {
+ printf ("result string \"%s\" malformed\n", resp);
+ continue;
+ }
+
+ printf (" Locale-specific tests for `%s'\n", inpline);
+
+ while (*inp != '\0' && *inp != '\n')
+ {
+ if (((__ctype_b[(unsigned int) *inp] & classes[n].mask) != 0)
+ != (*resp != '0'))
+ {
+ printf (" is%s('%c' = '\\x%02x') %s true\n", inpline,
+ *inp, *inp, *resp == '1' ? "not" : "is");
+ ++errors;
+ }
+ ++inp;
+ ++resp;
+ }
+ }
+ else if (strcmp (inpline, "tolower") == 0)
+ {
+ while (*inp != '\0')
+ {
+ if (tolower (*inp) != *resp)
+ {
+ printf (" tolower('%c' = '\\x%02x') != '%c'\n",
+ *inp, *inp, *resp);
+ ++errors;
+ }
+ ++inp;
+ ++resp;
+ }
+ }
+ else if (strcmp (inpline, "toupper") == 0)
+ {
+ while (*inp != '\0')
+ {
+ if (toupper (*inp) != *resp)
+ {
+ printf (" toupper('%c' = '\\x%02x') != '%c'\n",
+ *inp, *inp, *resp);
+ ++errors;
+ }
+ ++inp;
+ ++resp;
+ }
+ }
+ else
+ printf ("\"%s\": unknown class or map\n", inpline);
+ }
+
+
if (errors != 0)
{
- printf (" %d errors for `%s' locale\n\n\n", errors,
- setlocale (LC_ALL, NULL));
+ printf (" %d error%s for `%s' locale\n\n\n", errors,
+ errors == 1 ? "" : "s", setlocale (LC_ALL, NULL));
return 1;
}