|
| 1 | +#include "tests.h" |
| 2 | +#include <wctype.h> |
| 3 | + |
| 4 | +int main(int argc, char **argv) |
| 5 | +{ |
| 6 | + int error = 0, better = 0; |
| 7 | + utf8proc_int32_t c; |
| 8 | + |
| 9 | + (void) argc; /* unused */ |
| 10 | + (void) argv; /* unused */ |
| 11 | + |
| 12 | + /* some simple sanity tests of the character widths */ |
| 13 | + for (c = 0; c <= 0x110000; ++c) { |
| 14 | + utf8proc_int32_t l = utf8proc_tolower(c); |
| 15 | + utf8proc_int32_t u = utf8proc_toupper(c); |
| 16 | + |
| 17 | + check(l == c || utf8proc_codepoint_valid(l), "invalid tolower"); |
| 18 | + check(u == c || utf8proc_codepoint_valid(u), "invalid toupper"); |
| 19 | + |
| 20 | + if (sizeof(wint_t) > 2 || c < (1<<16)) { |
| 21 | + wint_t l0 = towlower(c), u0 = towupper(c); |
| 22 | + |
| 23 | + /* OS unicode tables may be out of date. But if they |
| 24 | + do have a lower/uppercase mapping, hopefully it |
| 25 | + is correct? */ |
| 26 | + if (l0 != c && l0 != l) { |
| 27 | + fprintf(stderr, "MISMATCH %x != towlower(%x) == %x\n", |
| 28 | + l, c, l0); |
| 29 | + ++error; |
| 30 | + } |
| 31 | + else if (l0 != l) { /* often true for out-of-date OS unicode */ |
| 32 | + ++better; |
| 33 | + /* printf("%x != towlower(%x) == %x\n", l, c, l0); */ |
| 34 | + } |
| 35 | + if (u0 != c && u0 != u) { |
| 36 | + fprintf(stderr, "MISMATCH %x != towupper(%x) == %x\n", |
| 37 | + u, c, u0); |
| 38 | + ++error; |
| 39 | + } |
| 40 | + else if (u0 != u) { /* often true for out-of-date OS unicode */ |
| 41 | + ++better; |
| 42 | + /* printf("%x != towupper(%x) == %x\n", u, c, u0); */ |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + check(!error, "utf8proc case conversion FAILED %d tests.", error); |
| 47 | + printf("More up-to-date than OS unicode tables for %d tests.\n", better); |
| 48 | + printf("utf8proc case conversion tests SUCCEEDED.\n"); |
| 49 | + return 0; |
| 50 | +} |
0 commit comments