diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2005-08-11 21:57:03 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2005-08-11 21:57:03 +0000 |
commit | 064f9d86cfb3e0e50019a31591eb140678997655 (patch) | |
tree | c8c4596622a62bf862a5b4f9d25f45c02a924232 /regress/lib/libc/locale | |
parent | 18d89504abf92ee7d9e282170ccaaa372d8240db (diff) |
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 'regress/lib/libc/locale')
-rw-r--r-- | regress/lib/libc/locale/Makefile | 7 | ||||
-rw-r--r-- | regress/lib/libc/locale/check_isw/Makefile | 9 | ||||
-rw-r--r-- | regress/lib/libc/locale/check_isw/check_isw.c | 147 |
3 files changed, 163 insertions, 0 deletions
diff --git a/regress/lib/libc/locale/Makefile b/regress/lib/libc/locale/Makefile new file mode 100644 index 00000000000..c182172ba2f --- /dev/null +++ b/regress/lib/libc/locale/Makefile @@ -0,0 +1,7 @@ +# $OpenBSD: Makefile,v 1.1 2005/08/11 21:57:02 espie Exp $ + +SUBDIR+= check_isw + +install: + +.include <bsd.subdir.mk> diff --git a/regress/lib/libc/locale/check_isw/Makefile b/regress/lib/libc/locale/check_isw/Makefile new file mode 100644 index 00000000000..0885968fd1a --- /dev/null +++ b/regress/lib/libc/locale/check_isw/Makefile @@ -0,0 +1,9 @@ +# $OpenBSD: Makefile,v 1.1 2005/08/11 21:57:02 espie Exp $ + +NOMAN= +PROG=check_isw + +run-regress-check_isw: ${PROG} + ./${PROG} >/dev/null + +.include <bsd.regress.mk> diff --git a/regress/lib/libc/locale/check_isw/check_isw.c b/regress/lib/libc/locale/check_isw/check_isw.c new file mode 100644 index 00000000000..9386267f611 --- /dev/null +++ b/regress/lib/libc/locale/check_isw/check_isw.c @@ -0,0 +1,147 @@ +/* $OpenBSD: check_isw.c,v 1.1 2005/08/11 21:57:02 espie Exp $ */ +/* + * Copyright (c) 2005 Marc Espie <espie@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* This checks consistency of the isw* functions with the default <ctype> + * functions. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <wchar.h> +#include <wctype.h> + +int bad = 0; + +void +check_bool(int v1, int v2, char msg) +{ + if (!v1 != !v2) { + printf("%c", msg); + bad++; + } +} + +void +check_value(int v1, int v2, char msg) +{ + if (v1 != v2) { + printf("%c", msg); + bad++; + } +} + +void +test1() +{ + int i; + + for (i = 0; i < 256; i++) { + printf(" %02x: ", i); + check_bool(isalnum(i), iswalnum(i), '1'); + check_bool(isalpha(i), iswalpha(i), '2'); + check_bool(isblank(i), iswblank(i), '3'); + check_bool(iscntrl(i), iswcntrl(i), '4'); + check_bool(isdigit(i), iswdigit(i), '5'); + check_bool(isgraph(i), iswgraph(i), '6'); + check_bool(islower(i), iswlower(i), '6'); + check_bool(isprint(i), iswprint(i), '7'); + check_bool(ispunct(i), iswpunct(i), '8'); + check_bool(isspace(i), iswspace(i), '9'); + check_bool(isupper(i), iswupper(i), 'a'); + check_bool(isxdigit(i), iswxdigit(i), 'b'); + check_value(tolower(i), towlower(i), 'c'); + check_value(toupper(i), towupper(i), 'd'); + if (i % 8 == 7) + printf("\n"); + } + printf("%\n"); +} + +void +test2() +{ + unsigned char *s; + unsigned char *buf; + int i, j; + size_t n; + wchar_t c, d; + mbstate_t state; + + s = malloc(256); + if (!s) { + bad++; + return; + } + buf = malloc(MB_CUR_MAX); + if (!buf) { + bad++; + free(s); + return; + } + for (i = 0; i < 256; i++) + s[i] = i+1; + + j = 0; + mbrtowc(NULL, NULL, 1, &state); + printf(" %02x: ", 0); + + while ((n = mbrtowc(&c, s+j, 256-j, &state)) == 1) { + printf(" %02x: ", s[j]); + check_bool(isalnum(s[j]), iswalnum(c), '1'); + check_bool(isalpha(s[j]), iswalpha(c), '2'); + check_bool(isblank(s[j]), iswblank(c), '3'); + check_bool(iscntrl(s[j]), iswcntrl(c), '4'); + check_bool(isdigit(s[j]), iswdigit(c), '5'); + check_bool(isgraph(s[j]), iswgraph(c), '6'); + check_bool(islower(s[j]), iswlower(c), '6'); + check_bool(isprint(s[j]), iswprint(c), '7'); + check_bool(ispunct(s[j]), iswpunct(c), '8'); + check_bool(isspace(s[j]), iswspace(c), '9'); + check_bool(isupper(s[j]), iswupper(c), 'a'); + check_bool(isxdigit(s[j]), iswxdigit(c), 'b'); + d = towlower(c); + if (wctomb(buf, d) == 1) { + check_value(tolower(s[j]), buf[0], 'c'); + } else { + bad++; + } + d = towupper(c); + if (wctomb(buf, d) == 1) { + check_value(toupper(s[j]), buf[0], 'c'); + } else { + bad++; + } + if (s[j] % 8 == 7) + printf("\n"); + j++; + } + if (n != 0 || j != 255) { + bad++; + } + free(s); + free(buf); +} + + +int +main() +{ + test1(); + test2(); + return bad !=0; +} |