diff options
author | max99x <max99x@gmail.com> | 2011-07-30 16:12:36 +0300 |
---|---|---|
committer | max99x <max99x@gmail.com> | 2011-07-30 16:12:36 +0300 |
commit | ee54249f11b9e4048dfc459bd8e432617c81d4e1 (patch) | |
tree | 31fbaebf1bb090e40c4d7767e76be00f691b4c61 /tests/ctype | |
parent | af695b99f5e5308a27c19b956489a702461683da (diff) |
Fixed ctype.h implementation; added test for it.
Diffstat (limited to 'tests/ctype')
-rw-r--r-- | tests/ctype/output.txt | 233 | ||||
-rw-r--r-- | tests/ctype/src.c | 193 |
2 files changed, 426 insertions, 0 deletions
diff --git a/tests/ctype/output.txt b/tests/ctype/output.txt new file mode 100644 index 00000000..5f98d20d --- /dev/null +++ b/tests/ctype/output.txt @@ -0,0 +1,233 @@ +ab1 +AB1 +cd2 +CD2 + +toascii(-45): 83 +toascii( 10): 10 +toascii('a'): 97 +toascii(183): 55 + +isascii/call(-45): 0 +isascii/call( 10): 1 +isascii/call('a'): 1 +isascii/call('A'): 1 +isascii/call('5'): 1 +isascii/call('.'): 1 +isascii/call(183): 0 + +islower/call(-45): 0 +islower/call( 10): 0 +islower/call('a'): 1 +islower/call('A'): 0 +islower/call('5'): 0 +islower/call('.'): 0 +islower/call(183): 0 + +isupper/call(-45): 0 +isupper/call( 10): 0 +isupper/call('a'): 0 +isupper/call('A'): 1 +isupper/call('5'): 0 +isupper/call('.'): 0 +isupper/call(183): 0 + +isupper/call(-45): 0 +isupper/call( 10): 0 +isupper/call('a'): 0 +isupper/call('A'): 1 +isupper/call('5'): 0 +isupper/call('.'): 0 +isupper/call(183): 0 + +isalpha/call(-45): 0 +isalpha/call( 10): 0 +isalpha/call('a'): 1 +isalpha/call('A'): 1 +isalpha/call('5'): 0 +isalpha/call('.'): 0 +isalpha/call(183): 0 + +isdigit/call(-45): 0 +isdigit/call( 10): 0 +isdigit/call('a'): 0 +isdigit/call('A'): 0 +isdigit/call('5'): 1 +isdigit/call('.'): 0 +isdigit/call(183): 0 + +isxdigit/call(-45): 0 +isxdigit/call( 10): 0 +isxdigit/call('a'): 1 +isxdigit/call('A'): 1 +isxdigit/call('5'): 1 +isxdigit/call('.'): 0 +isxdigit/call(183): 0 + +isalnum/call(-45): 0 +isalnum/call( 10): 0 +isalnum/call('a'): 1 +isalnum/call('A'): 1 +isalnum/call('5'): 1 +isalnum/call('.'): 0 +isalnum/call(183): 0 + +ispunct/call(-45): 0 +ispunct/call( 10): 0 +ispunct/call('a'): 0 +ispunct/call('A'): 0 +ispunct/call('5'): 0 +ispunct/call('.'): 1 +ispunct/call(183): 0 + +isspace/call(-45): 0 +isspace/call( 10): 1 +isspace/call('a'): 0 +isspace/call('A'): 0 +isspace/call('5'): 0 +isspace/call('.'): 0 +isspace/call(183): 0 + +isblank/call(-45): 0 +isblank/call( 10): 0 +isblank/call('a'): 0 +isblank/call('A'): 0 +isblank/call('5'): 0 +isblank/call('.'): 0 +isblank/call(183): 0 + +iscntrl/call(-45): 0 +iscntrl/call( 10): 1 +iscntrl/call('a'): 0 +iscntrl/call('A'): 0 +iscntrl/call('5'): 0 +iscntrl/call('.'): 0 +iscntrl/call(183): 0 + +isprint/call(-45): 0 +isprint/call( 10): 0 +isprint/call('a'): 1 +isprint/call('A'): 1 +isprint/call('5'): 1 +isprint/call('.'): 1 +isprint/call(183): 0 + +isgraph/call(-45): 0 +isgraph/call( 10): 0 +isgraph/call('a'): 1 +isgraph/call('A'): 1 +isgraph/call('5'): 1 +isgraph/call('.'): 1 +isgraph/call(183): 0 + +isascii(-45): 0 +isascii( 10): 1 +isascii('a'): 1 +isascii('A'): 1 +isascii('5'): 1 +isascii('.'): 1 +isascii(183): 0 + +islower(-45): 0 +islower( 10): 0 +islower('a'): 1 +islower('A'): 0 +islower('5'): 0 +islower('.'): 0 +islower(183): 0 + +isupper(-45): 0 +isupper( 10): 0 +isupper('a'): 0 +isupper('A'): 1 +isupper('5'): 0 +isupper('.'): 0 +isupper(183): 0 + +isupper(-45): 0 +isupper( 10): 0 +isupper('a'): 0 +isupper('A'): 1 +isupper('5'): 0 +isupper('.'): 0 +isupper(183): 0 + +isalpha(-45): 0 +isalpha( 10): 0 +isalpha('a'): 1 +isalpha('A'): 1 +isalpha('5'): 0 +isalpha('.'): 0 +isalpha(183): 0 + +isdigit(-45): 0 +isdigit( 10): 0 +isdigit('a'): 0 +isdigit('A'): 0 +isdigit('5'): 1 +isdigit('.'): 0 +isdigit(183): 0 + +isxdigit(-45): 0 +isxdigit( 10): 0 +isxdigit('a'): 1 +isxdigit('A'): 1 +isxdigit('5'): 1 +isxdigit('.'): 0 +isxdigit(183): 0 + +isalnum(-45): 0 +isalnum( 10): 0 +isalnum('a'): 1 +isalnum('A'): 1 +isalnum('5'): 1 +isalnum('.'): 0 +isalnum(183): 0 + +ispunct(-45): 0 +ispunct( 10): 0 +ispunct('a'): 0 +ispunct('A'): 0 +ispunct('5'): 0 +ispunct('.'): 1 +ispunct(183): 0 + +isspace(-45): 0 +isspace( 10): 1 +isspace('a'): 0 +isspace('A'): 0 +isspace('5'): 0 +isspace('.'): 0 +isspace(183): 0 + +isblank(-45): 0 +isblank( 10): 0 +isblank('a'): 0 +isblank('A'): 0 +isblank('5'): 0 +isblank('.'): 0 +isblank(183): 0 + +iscntrl(-45): 0 +iscntrl( 10): 1 +iscntrl('a'): 0 +iscntrl('A'): 0 +iscntrl('5'): 0 +iscntrl('.'): 0 +iscntrl(183): 0 + +isprint(-45): 0 +isprint( 10): 0 +isprint('a'): 1 +isprint('A'): 1 +isprint('5'): 1 +isprint('.'): 1 +isprint(183): 0 + +isgraph(-45): 0 +isgraph( 10): 0 +isgraph('a'): 1 +isgraph('A'): 1 +isgraph('5'): 1 +isgraph('.'): 1 +isgraph(183): 0 diff --git a/tests/ctype/src.c b/tests/ctype/src.c new file mode 100644 index 00000000..c9b66cee --- /dev/null +++ b/tests/ctype/src.c @@ -0,0 +1,193 @@ +#define _BSD_SOURCE +#include <stdio.h> +#include <ctype.h> + +int main() { + printf("%c%c%c\n", tolower('a'), tolower('B'), tolower('1')); + printf("%c%c%c\n", toupper('a'), toupper('B'), toupper('1')); + + const int* tl = *__ctype_tolower_loc(); + printf("%c%c%c\n", (char)tl['c'], (char)tl['D'], (char)tl['2']); + const int* tu = *__ctype_toupper_loc(); + printf("%c%c%c\n", (char)tu['c'], (char)tu['D'], (char)tu['2']); + + printf("\n"); + + printf("toascii(-45): %d\n", toascii(-45)); + printf("toascii( 10): %d\n", toascii(10)); + printf("toascii('a'): %d\n", toascii('a')); + printf("toascii(183): %d\n", toascii(183)); + + // These will be compiled as actual function calls. + int (*funcs[])(int) = { + isascii, + islower, + isupper, + isupper, + isalpha, + isdigit, + isxdigit, + isalnum, + ispunct, + isspace, + isblank, + iscntrl, + isprint, + isgraph + }; + char* funcNames[] = { + "isascii", + "islower", + "isupper", + "isupper", + "isalpha", + "isdigit", + "isxdigit", + "isalnum", + "ispunct", + "isspace", + "isblank", + "iscntrl", + "isprint", + "isgraph" + }; + for (int i = 0; i < sizeof funcs / sizeof funcs[0]; i++) { + printf("\n"); + printf("%s/call(-45): %d\n", funcNames[i], funcs[i](-45) != 0); + printf("%s/call( 10): %d\n", funcNames[i], funcs[i](10) != 0); + printf("%s/call('a'): %d\n", funcNames[i], funcs[i]('a') != 0); + printf("%s/call('A'): %d\n", funcNames[i], funcs[i]('A') != 0); + printf("%s/call('5'): %d\n", funcNames[i], funcs[i]('5') != 0); + printf("%s/call('.'): %d\n", funcNames[i], funcs[i]('.') != 0); + printf("%s/call(183): %d\n", funcNames[i], funcs[i](183) != 0); + } + + // These will be compiled as macros that use __ctype_b_loc. + printf("\n"); + printf("isascii(-45): %d\n", isascii(-45) != 0); + printf("isascii( 10): %d\n", isascii( 10) != 0); + printf("isascii('a'): %d\n", isascii('a') != 0); + printf("isascii('A'): %d\n", isascii('A') != 0); + printf("isascii('5'): %d\n", isascii('5') != 0); + printf("isascii('.'): %d\n", isascii('.') != 0); + printf("isascii(183): %d\n", isascii(183) != 0); + + printf("\n"); + printf("islower(-45): %d\n", islower(-45) != 0); + printf("islower( 10): %d\n", islower( 10) != 0); + printf("islower('a'): %d\n", islower('a') != 0); + printf("islower('A'): %d\n", islower('A') != 0); + printf("islower('5'): %d\n", islower('5') != 0); + printf("islower('.'): %d\n", islower('.') != 0); + printf("islower(183): %d\n", islower(183) != 0); + + printf("\n"); + printf("isupper(-45): %d\n", isupper(-45) != 0); + printf("isupper( 10): %d\n", isupper( 10) != 0); + printf("isupper('a'): %d\n", isupper('a') != 0); + printf("isupper('A'): %d\n", isupper('A') != 0); + printf("isupper('5'): %d\n", isupper('5') != 0); + printf("isupper('.'): %d\n", isupper('.') != 0); + printf("isupper(183): %d\n", isupper(183) != 0); + + printf("\n"); + printf("isupper(-45): %d\n", isupper(-45) != 0); + printf("isupper( 10): %d\n", isupper( 10) != 0); + printf("isupper('a'): %d\n", isupper('a') != 0); + printf("isupper('A'): %d\n", isupper('A') != 0); + printf("isupper('5'): %d\n", isupper('5') != 0); + printf("isupper('.'): %d\n", isupper('.') != 0); + printf("isupper(183): %d\n", isupper(183) != 0); + + printf("\n"); + printf("isalpha(-45): %d\n", isalpha(-45) != 0); + printf("isalpha( 10): %d\n", isalpha( 10) != 0); + printf("isalpha('a'): %d\n", isalpha('a') != 0); + printf("isalpha('A'): %d\n", isalpha('A') != 0); + printf("isalpha('5'): %d\n", isalpha('5') != 0); + printf("isalpha('.'): %d\n", isalpha('.') != 0); + printf("isalpha(183): %d\n", isalpha(183) != 0); + + printf("\n"); + printf("isdigit(-45): %d\n", isdigit(-45) != 0); + printf("isdigit( 10): %d\n", isdigit( 10) != 0); + printf("isdigit('a'): %d\n", isdigit('a') != 0); + printf("isdigit('A'): %d\n", isdigit('A') != 0); + printf("isdigit('5'): %d\n", isdigit('5') != 0); + printf("isdigit('.'): %d\n", isdigit('.') != 0); + printf("isdigit(183): %d\n", isdigit(183) != 0); + + printf("\n"); + printf("isxdigit(-45): %d\n", isxdigit(-45) != 0); + printf("isxdigit( 10): %d\n", isxdigit( 10) != 0); + printf("isxdigit('a'): %d\n", isxdigit('a') != 0); + printf("isxdigit('A'): %d\n", isxdigit('A') != 0); + printf("isxdigit('5'): %d\n", isxdigit('5') != 0); + printf("isxdigit('.'): %d\n", isxdigit('.') != 0); + printf("isxdigit(183): %d\n", isxdigit(183) != 0); + + printf("\n"); + printf("isalnum(-45): %d\n", isalnum(-45) != 0); + printf("isalnum( 10): %d\n", isalnum( 10) != 0); + printf("isalnum('a'): %d\n", isalnum('a') != 0); + printf("isalnum('A'): %d\n", isalnum('A') != 0); + printf("isalnum('5'): %d\n", isalnum('5') != 0); + printf("isalnum('.'): %d\n", isalnum('.') != 0); + printf("isalnum(183): %d\n", isalnum(183) != 0); + + printf("\n"); + printf("ispunct(-45): %d\n", ispunct(-45) != 0); + printf("ispunct( 10): %d\n", ispunct( 10) != 0); + printf("ispunct('a'): %d\n", ispunct('a') != 0); + printf("ispunct('A'): %d\n", ispunct('A') != 0); + printf("ispunct('5'): %d\n", ispunct('5') != 0); + printf("ispunct('.'): %d\n", ispunct('.') != 0); + printf("ispunct(183): %d\n", ispunct(183) != 0); + + printf("\n"); + printf("isspace(-45): %d\n", isspace(-45) != 0); + printf("isspace( 10): %d\n", isspace( 10) != 0); + printf("isspace('a'): %d\n", isspace('a') != 0); + printf("isspace('A'): %d\n", isspace('A') != 0); + printf("isspace('5'): %d\n", isspace('5') != 0); + printf("isspace('.'): %d\n", isspace('.') != 0); + printf("isspace(183): %d\n", isspace(183) != 0); + + printf("\n"); + printf("isblank(-45): %d\n", isblank(-45) != 0); + printf("isblank( 10): %d\n", isblank( 10) != 0); + printf("isblank('a'): %d\n", isblank('a') != 0); + printf("isblank('A'): %d\n", isblank('A') != 0); + printf("isblank('5'): %d\n", isblank('5') != 0); + printf("isblank('.'): %d\n", isblank('.') != 0); + printf("isblank(183): %d\n", isblank(183) != 0); + + printf("\n"); + printf("iscntrl(-45): %d\n", iscntrl(-45) != 0); + printf("iscntrl( 10): %d\n", iscntrl( 10) != 0); + printf("iscntrl('a'): %d\n", iscntrl('a') != 0); + printf("iscntrl('A'): %d\n", iscntrl('A') != 0); + printf("iscntrl('5'): %d\n", iscntrl('5') != 0); + printf("iscntrl('.'): %d\n", iscntrl('.') != 0); + printf("iscntrl(183): %d\n", iscntrl(183) != 0); + + printf("\n"); + printf("isprint(-45): %d\n", isprint(-45) != 0); + printf("isprint( 10): %d\n", isprint( 10) != 0); + printf("isprint('a'): %d\n", isprint('a') != 0); + printf("isprint('A'): %d\n", isprint('A') != 0); + printf("isprint('5'): %d\n", isprint('5') != 0); + printf("isprint('.'): %d\n", isprint('.') != 0); + printf("isprint(183): %d\n", isprint(183) != 0); + + printf("\n"); + printf("isgraph(-45): %d\n", isgraph(-45) != 0); + printf("isgraph( 10): %d\n", isgraph( 10) != 0); + printf("isgraph('a'): %d\n", isgraph('a') != 0); + printf("isgraph('A'): %d\n", isgraph('A') != 0); + printf("isgraph('5'): %d\n", isgraph('5') != 0); + printf("isgraph('.'): %d\n", isgraph('.') != 0); + printf("isgraph(183): %d\n", isgraph(183) != 0); + + return 0; +} |