diff options
author | Peter Jones <pjones@redhat.com> | 2006-06-29 15:58:41 +0000 |
---|---|---|
committer | Peter Jones <pjones@redhat.com> | 2006-06-29 15:58:41 +0000 |
commit | 097e9e63c1431019b1831db549e7f3686aaf34f4 (patch) | |
tree | 7156813ee826601375c54ccc3e5a0505fcf5fd08 /wlite/test-stdlib.c | |
parent | b7e280956c9fe359efe6cfd6dbeeb658fbe10465 (diff) | |
download | anaconda-097e9e63c1431019b1831db549e7f3686aaf34f4.tar.gz anaconda-097e9e63c1431019b1831db549e7f3686aaf34f4.tar.xz anaconda-097e9e63c1431019b1831db549e7f3686aaf34f4.zip |
- Fix wide character support (#196099, #186701)
Diffstat (limited to 'wlite/test-stdlib.c')
-rw-r--r-- | wlite/test-stdlib.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/wlite/test-stdlib.c b/wlite/test-stdlib.c new file mode 100644 index 000000000..a6de0867d --- /dev/null +++ b/wlite/test-stdlib.c @@ -0,0 +1,47 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "wlite_wchar.h" +#include "wlite_stdlib.h" + +#define test(expr) check((expr),__FILE__,__LINE__,#expr) + +void check(int expr, const char *file, unsigned line, const char *s) { + const char *ok = "PASS (%s:%u) ** %d == %s\n"; + const char *ng = "FAIL (%s:%u) ** %d == %s\n"; + + if (fprintf(stderr, (expr ? ok : ng), file, line, expr, s) < 0) abort(); + if (!expr) exit(EXIT_FAILURE); +} + +int main(int argc, char **argv) { + wchar_t *s, wcs[10]; + char mbs[10]; + + test(1 <= MB_CUR_MAX && MB_CUR_MAX <= MB_LEN_MAX); + + // test(wcstod(L"28G", &s) == 28.0 && s != NULL && *s == L'G'); + + test(wcstol(L"-a0", &s, 11) == -110 && s != NULL && *s == L'\0'); + test(wcstoul(L"54", &s, 4) == 0 && s != NULL && *s == L'5'); + test(wcstoul(L"0xFfg", &s, 16) == 255 && s != NULL && *s == L'g'); + + test(mbstowcs(wcs, "abc", 4) == 3 && wcs[1] == L'b'); + test(wcstombs(mbs, wcs, 10) == 3 && strcmp(mbs, "abc") == 0); + + mblen(NULL, 0); + wctomb(NULL, 0); + + test(mblen("abc", 4) == 1); + test(mbtowc(&wcs[0], "abc", 4) == 1 && wcs[0] == L'a'); + test(wctomb(mbs, wcs[0]) == 1 && mbs[0] == L'a'); + test(mblen("", 1) == 0); + test(mbtowc(&wcs[0], "", 1) == 0 && wcs[0] == 0); + test(wctomb(mbs, wcs[0]) == 1 && mbs[0] == '\0'); + + printf("MB_CUR_MAX = %u\n", MB_CUR_MAX); + puts(mbtowc(NULL, NULL, 0) ? "mbs shift states" : "mbs stateless"); + + return 0; +} |