diff options
author | espie <> | 2005-08-11 21:57:02 +0000 |
---|---|---|
committer | espie <> | 2005-08-11 21:57:02 +0000 |
commit | 829f2222cd261dcd6fb77cea4c4489e9e744ba6a (patch) | |
tree | 2147a2d8f3ee470a11700e6813a84f2bcaf105f8 /src | |
parent | d7398a270c9cd1b7b4d545ed70ea24384781a86c (diff) | |
download | openbsd-829f2222cd261dcd6fb77cea4c4489e9e744ba6a.tar.gz openbsd-829f2222cd261dcd6fb77cea4c4489e9e744ba6a.tar.bz2 openbsd-829f2222cd261dcd6fb77cea4c4489e9e744ba6a.zip |
regression test to check that isw* functions yield the same result as
is* functions, and that basic mb->wchar conversion yields sensible results.
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libc/Makefile | 5 | ||||
-rw-r--r-- | src/regress/lib/libc/locale/Makefile | 7 | ||||
-rw-r--r-- | src/regress/lib/libc/locale/check_isw/Makefile | 9 | ||||
-rw-r--r-- | src/regress/lib/libc/locale/check_isw/check_isw.c | 147 |
4 files changed, 166 insertions, 2 deletions
diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile index 34d418e428..6a20b61c46 100644 --- a/src/regress/lib/libc/Makefile +++ b/src/regress/lib/libc/Makefile | |||
@@ -1,6 +1,7 @@ | |||
1 | # $OpenBSD: Makefile,v 1.18 2004/10/25 15:10:36 otto Exp $ | 1 | # $OpenBSD: Makefile,v 1.19 2005/08/11 21:57:02 espie Exp $ |
2 | 2 | ||
3 | SUBDIR+= _setjmp alloca atexit db getaddrinfo getopt_long hsearch longjmp malloc | 3 | SUBDIR+= _setjmp alloca atexit db getaddrinfo getopt_long hsearch longjmp \ |
4 | SUBDIR+= locale malloc | ||
4 | SUBDIR+= netdb popen regex setjmp setjmp-signal sigreturn sigsetjmp | 5 | SUBDIR+= netdb popen regex setjmp setjmp-signal sigreturn sigsetjmp |
5 | SUBDIR+= sprintf strerror strtonum time | 6 | SUBDIR+= sprintf strerror strtonum time |
6 | 7 | ||
diff --git a/src/regress/lib/libc/locale/Makefile b/src/regress/lib/libc/locale/Makefile new file mode 100644 index 0000000000..c182172ba2 --- /dev/null +++ b/src/regress/lib/libc/locale/Makefile | |||
@@ -0,0 +1,7 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2005/08/11 21:57:02 espie Exp $ | ||
2 | |||
3 | SUBDIR+= check_isw | ||
4 | |||
5 | install: | ||
6 | |||
7 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/locale/check_isw/Makefile b/src/regress/lib/libc/locale/check_isw/Makefile new file mode 100644 index 0000000000..0885968fd1 --- /dev/null +++ b/src/regress/lib/libc/locale/check_isw/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2005/08/11 21:57:02 espie Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=check_isw | ||
5 | |||
6 | run-regress-check_isw: ${PROG} | ||
7 | ./${PROG} >/dev/null | ||
8 | |||
9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/check_isw/check_isw.c b/src/regress/lib/libc/locale/check_isw/check_isw.c new file mode 100644 index 0000000000..9386267f61 --- /dev/null +++ b/src/regress/lib/libc/locale/check_isw/check_isw.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /* $OpenBSD: check_isw.c,v 1.1 2005/08/11 21:57:02 espie Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2005 Marc Espie <espie@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | /* This checks consistency of the isw* functions with the default <ctype> | ||
19 | * functions. | ||
20 | */ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <ctype.h> | ||
25 | #include <wchar.h> | ||
26 | #include <wctype.h> | ||
27 | |||
28 | int bad = 0; | ||
29 | |||
30 | void | ||
31 | check_bool(int v1, int v2, char msg) | ||
32 | { | ||
33 | if (!v1 != !v2) { | ||
34 | printf("%c", msg); | ||
35 | bad++; | ||
36 | } | ||
37 | } | ||
38 | |||
39 | void | ||
40 | check_value(int v1, int v2, char msg) | ||
41 | { | ||
42 | if (v1 != v2) { | ||
43 | printf("%c", msg); | ||
44 | bad++; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | void | ||
49 | test1() | ||
50 | { | ||
51 | int i; | ||
52 | |||
53 | for (i = 0; i < 256; i++) { | ||
54 | printf(" %02x: ", i); | ||
55 | check_bool(isalnum(i), iswalnum(i), '1'); | ||
56 | check_bool(isalpha(i), iswalpha(i), '2'); | ||
57 | check_bool(isblank(i), iswblank(i), '3'); | ||
58 | check_bool(iscntrl(i), iswcntrl(i), '4'); | ||
59 | check_bool(isdigit(i), iswdigit(i), '5'); | ||
60 | check_bool(isgraph(i), iswgraph(i), '6'); | ||
61 | check_bool(islower(i), iswlower(i), '6'); | ||
62 | check_bool(isprint(i), iswprint(i), '7'); | ||
63 | check_bool(ispunct(i), iswpunct(i), '8'); | ||
64 | check_bool(isspace(i), iswspace(i), '9'); | ||
65 | check_bool(isupper(i), iswupper(i), 'a'); | ||
66 | check_bool(isxdigit(i), iswxdigit(i), 'b'); | ||
67 | check_value(tolower(i), towlower(i), 'c'); | ||
68 | check_value(toupper(i), towupper(i), 'd'); | ||
69 | if (i % 8 == 7) | ||
70 | printf("\n"); | ||
71 | } | ||
72 | printf("%\n"); | ||
73 | } | ||
74 | |||
75 | void | ||
76 | test2() | ||
77 | { | ||
78 | unsigned char *s; | ||
79 | unsigned char *buf; | ||
80 | int i, j; | ||
81 | size_t n; | ||
82 | wchar_t c, d; | ||
83 | mbstate_t state; | ||
84 | |||
85 | s = malloc(256); | ||
86 | if (!s) { | ||
87 | bad++; | ||
88 | return; | ||
89 | } | ||
90 | buf = malloc(MB_CUR_MAX); | ||
91 | if (!buf) { | ||
92 | bad++; | ||
93 | free(s); | ||
94 | return; | ||
95 | } | ||
96 | for (i = 0; i < 256; i++) | ||
97 | s[i] = i+1; | ||
98 | |||
99 | j = 0; | ||
100 | mbrtowc(NULL, NULL, 1, &state); | ||
101 | printf(" %02x: ", 0); | ||
102 | |||
103 | while ((n = mbrtowc(&c, s+j, 256-j, &state)) == 1) { | ||
104 | printf(" %02x: ", s[j]); | ||
105 | check_bool(isalnum(s[j]), iswalnum(c), '1'); | ||
106 | check_bool(isalpha(s[j]), iswalpha(c), '2'); | ||
107 | check_bool(isblank(s[j]), iswblank(c), '3'); | ||
108 | check_bool(iscntrl(s[j]), iswcntrl(c), '4'); | ||
109 | check_bool(isdigit(s[j]), iswdigit(c), '5'); | ||
110 | check_bool(isgraph(s[j]), iswgraph(c), '6'); | ||
111 | check_bool(islower(s[j]), iswlower(c), '6'); | ||
112 | check_bool(isprint(s[j]), iswprint(c), '7'); | ||
113 | check_bool(ispunct(s[j]), iswpunct(c), '8'); | ||
114 | check_bool(isspace(s[j]), iswspace(c), '9'); | ||
115 | check_bool(isupper(s[j]), iswupper(c), 'a'); | ||
116 | check_bool(isxdigit(s[j]), iswxdigit(c), 'b'); | ||
117 | d = towlower(c); | ||
118 | if (wctomb(buf, d) == 1) { | ||
119 | check_value(tolower(s[j]), buf[0], 'c'); | ||
120 | } else { | ||
121 | bad++; | ||
122 | } | ||
123 | d = towupper(c); | ||
124 | if (wctomb(buf, d) == 1) { | ||
125 | check_value(toupper(s[j]), buf[0], 'c'); | ||
126 | } else { | ||
127 | bad++; | ||
128 | } | ||
129 | if (s[j] % 8 == 7) | ||
130 | printf("\n"); | ||
131 | j++; | ||
132 | } | ||
133 | if (n != 0 || j != 255) { | ||
134 | bad++; | ||
135 | } | ||
136 | free(s); | ||
137 | free(buf); | ||
138 | } | ||
139 | |||
140 | |||
141 | int | ||
142 | main() | ||
143 | { | ||
144 | test1(); | ||
145 | test2(); | ||
146 | return bad !=0; | ||
147 | } | ||