1#include "cache.h"
2
3
4static int test_isdigit(int c)
5{
6 return isdigit(c);
7}
8
9static int test_isspace(int c)
10{
11 return isspace(c);
12}
13
14static int test_isalpha(int c)
15{
16 return isalpha(c);
17}
18
19static int test_isalnum(int c)
20{
21 return isalnum(c);
22}
23
24static int test_is_glob_special(int c)
25{
26 return is_glob_special(c);
27}
28
29#define DIGIT "0123456789"
30#define LOWER "abcdefghijklmnopqrstuvwxyz"
31#define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
32
33static const struct ctype_class {
34 const char *name;
35 int (*test_fn)(int);
36 const char *members;
37} classes[] = {
38 { "isdigit", test_isdigit, DIGIT },
39 { "isspace", test_isspace, " \n\r\t" },
40 { "isalpha", test_isalpha, LOWER UPPER },
41 { "isalnum", test_isalnum, LOWER UPPER DIGIT },
42 { "is_glob_special", test_is_glob_special, "*?[\\" },
43 { NULL }
44};
45
46static int test_class(const struct ctype_class *test)
47{
48 int i, rc = 0;
49
50 for (i = 0; i < 256; i++) {
51 int expected = i ? !!strchr(test->members, i) : 0;
52 int actual = test->test_fn(i);
53
54 if (actual != expected) {
55 rc = 1;
56 printf("%s classifies char %d (0x%02x) wrongly\n",
57 test->name, i, i);
58 }
59 }
60 return rc;
61}
62
63int main(int argc, char **argv)
64{
65 const struct ctype_class *test;
66 int rc = 0;
67
68 for (test = classes; test->name; test++)
69 rc |= test_class(test);
70
71 return rc;
72}