|
Szabolcs Nagy |
007ed0 |
#include <stdio.h>
|
|
Szabolcs Nagy |
007ed0 |
#include <string.h>
|
|
Szabolcs Nagy |
007ed0 |
#include <wchar.h>
|
|
Szabolcs Nagy |
007ed0 |
#include <wctype.h>
|
|
Szabolcs Nagy |
007ed0 |
#include <stdlib.h>
|
|
Szabolcs Nagy |
007ed0 |
#include <locale.h>
|
|
Szabolcs Nagy |
007ed0 |
#include <langinfo.h>
|
|
Szabolcs Nagy |
007ed0 |
#include <limits.h>
|
|
Szabolcs Nagy |
007ed0 |
#include "test.h"
|
|
Szabolcs Nagy |
007ed0 |
|
|
Szabolcs Nagy |
007ed0 |
int main(void)
|
|
Szabolcs Nagy |
007ed0 |
{
|
|
Szabolcs Nagy |
007ed0 |
int i, j;
|
|
Szabolcs Nagy |
007ed0 |
mbstate_t st, st2;
|
|
Szabolcs Nagy |
007ed0 |
wchar_t wc, map[257], wtmp[257];
|
|
Szabolcs Nagy |
007ed0 |
char s[MB_LEN_MAX*256];
|
|
Szabolcs Nagy |
007ed0 |
size_t rv;
|
|
Szabolcs Nagy |
007ed0 |
int c;
|
|
Szabolcs Nagy |
007ed0 |
int ni_errors=0;
|
|
Szabolcs Nagy |
007ed0 |
|
|
Szabolcs Nagy |
007ed0 |
setlocale(LC_CTYPE, "C");
|
|
Szabolcs Nagy |
007ed0 |
|
|
Szabolcs Nagy |
007ed0 |
if (MB_CUR_MAX != 1) t_error("MB_CUR_MAX = %d, expected 1\n", (int)MB_CUR_MAX);
|
|
Szabolcs Nagy |
007ed0 |
|
|
Szabolcs Nagy |
007ed0 |
for (i=0; i<256; i++) {
|
|
Szabolcs Nagy |
007ed0 |
st = (mbstate_t){0};
|
|
Szabolcs Nagy |
007ed0 |
if (mbrtowc(&wc, &(char){i}, 1, &st) != !!i)
|
|
Szabolcs Nagy |
007ed0 |
t_error("mbrtowc failed to convert byte %.2x to wchar_t\n", i);
|
|
Szabolcs Nagy |
007ed0 |
if ((map[i]=btowc(i)) == WEOF) {
|
|
Szabolcs Nagy |
007ed0 |
t_error("btowc failed to convert byte %.2x to wchar_t\n", i);
|
|
Szabolcs Nagy |
007ed0 |
continue;
|
|
Szabolcs Nagy |
007ed0 |
}
|
|
Szabolcs Nagy |
007ed0 |
for (j=0; j
|
|
Szabolcs Nagy |
007ed0 |
if (map[j]==map[i])
|
|
Szabolcs Nagy |
007ed0 |
t_error("bytes %.2x and %.2x map to same wchar_t %.4x\n", j, i, (unsigned)map[i]);
|
|
Szabolcs Nagy |
007ed0 |
}
|
|
Szabolcs Nagy |
007ed0 |
}
|
|
Szabolcs Nagy |
007ed0 |
|
|
Szabolcs Nagy |
007ed0 |
for (i=0; i<256; i++) {
|
|
Szabolcs Nagy |
007ed0 |
if (map[i]==WEOF) continue;
|
|
Szabolcs Nagy |
007ed0 |
if (wctob(map[i]) != i)
|
|
Szabolcs Nagy |
007ed0 |
t_error("wctob failed to convert wchar_t %.4x back to byte %.2x\n", (unsigned)map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
}
|
|
Szabolcs Nagy |
007ed0 |
|
|
Szabolcs Nagy |
007ed0 |
/* covering whole 32-bit range would be too slow... maybe add random high tests? */
|
|
Szabolcs Nagy |
007ed0 |
for (i=0; i<0x110000; i++) {
|
|
Szabolcs Nagy |
007ed0 |
if (wcschr(map+1, i)) continue;
|
|
Szabolcs Nagy |
007ed0 |
if ((c=wctob(i)) != WEOF && ni_errors++ < 50)
|
|
Szabolcs Nagy |
007ed0 |
t_error("wctob accepted non-image wchar_t %.4x as byte %.2x\n", i, c);
|
|
Szabolcs Nagy |
007ed0 |
st = (mbstate_t){0};
|
|
Szabolcs Nagy |
007ed0 |
if (wcrtomb(s, i, &st) != -1 && ni_errors++ < 50)
|
|
Szabolcs Nagy |
007ed0 |
t_error("wcrtomb accepted non-image wchar_t %.4x\n", i);
|
|
Szabolcs Nagy |
007ed0 |
}
|
|
Szabolcs Nagy |
007ed0 |
if (ni_errors > 50)
|
|
Szabolcs Nagy |
007ed0 |
t_error("additional %d non-image errors (not printed)\n", ni_errors);
|
|
Szabolcs Nagy |
007ed0 |
|
|
Szabolcs Nagy |
007ed0 |
map[256] = 0;
|
|
Szabolcs Nagy |
007ed0 |
st = (mbstate_t){0};
|
|
Szabolcs Nagy |
007ed0 |
if ((rv=wcsrtombs(s, &(const wchar_t *){map+1}, sizeof s, &st)) != 255)
|
|
Szabolcs Nagy |
007ed0 |
t_error("wcsrtombs returned %zd, expected 255\n", rv);
|
|
Szabolcs Nagy |
007ed0 |
if ((rv=mbsrtowcs(wtmp, &(const char *){s}, 256, &st)) != 255)
|
|
Szabolcs Nagy |
007ed0 |
t_error("mbsrtowcs returned %zd, expected 255\n", rv);
|
|
Szabolcs Nagy |
007ed0 |
if (memcmp(map+1, wtmp, 256*sizeof(*map)))
|
|
Szabolcs Nagy |
007ed0 |
t_error("wcsrtombs/mbsrtowcs round trip failed\n");
|
|
Szabolcs Nagy |
007ed0 |
|
|
Szabolcs Nagy |
007ed0 |
for (i=128; i<256; i++) {
|
|
Szabolcs Nagy |
007ed0 |
if (iswalnum(map[i])) t_error("iswalnum returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
if (iswalpha(map[i])) t_error("iswalpha returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
if (iswblank(map[i])) t_error("iswblank returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
if (iswcntrl(map[i])) t_error("iswcntrl returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
if (iswdigit(map[i])) t_error("iswdigit returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
if (iswgraph(map[i])) t_error("iswgraph returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
if (iswlower(map[i])) t_error("iswlower returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
if (iswprint(map[i])) t_error("iswprint returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
if (iswpunct(map[i])) t_error("iswpunct returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
if (iswspace(map[i])) t_error("iswspace returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
if (iswupper(map[i])) t_error("iswupper returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
if (iswxdigit(map[i])) t_error("iswxdigit returned true for %.4x (%.2x)\n", map[i], i);
|
|
Szabolcs Nagy |
007ed0 |
}
|
|
Szabolcs Nagy |
007ed0 |
|
|
Szabolcs Nagy |
007ed0 |
return t_status;
|
|
Szabolcs Nagy |
007ed0 |
}
|