15 wchar_t wc
, map
[257], wtmp
[257];
16 char s
[MB_LEN_MAX
*256];
21 setlocale(LC_CTYPE
, "C");
23 if (MB_CUR_MAX
!= 1) t_error("MB_CUR_MAX = %d, expected 1\n", (int)MB_CUR_MAX
);
25 for (i
=0; i
<256; i
++) {
27 if (mbrtowc(&wc
, &(char){i
}, 1, &st
) != !!i
)
28 t_error("mbrtowc failed to convert byte %.2x to wchar_t\n", i
);
29 if ((map
[i
]=btowc(i
)) == WEOF
) {
30 t_error("btowc failed to convert byte %.2x to wchar_t\n", i
);
35 t_error("bytes %.2x and %.2x map to same wchar_t %.4x\n", j
, i
, (unsigned)map
[i
]);
39 for (i
=0; i
<256; i
++) {
40 if (map
[i
]==WEOF
) continue;
41 if (wctob(map
[i
]) != i
)
42 t_error("wctob failed to convert wchar_t %.4x back to byte %.2x\n", (unsigned)map
[i
], i
);
45 /* covering whole 32-bit range would be too slow... maybe add random high tests? */
46 for (i
=0; i
<0x110000; i
++) {
47 if (wcschr(map
+1, i
)) continue;
48 if ((c
=wctob(i
)) != WEOF
&& ni_errors
++ < 50)
49 t_error("wctob accepted non-image wchar_t %.4x as byte %.2x\n", i
, c
);
51 if (wcrtomb(s
, i
, &st
) != -1 && ni_errors
++ < 50)
52 t_error("wcrtomb accepted non-image wchar_t %.4x\n", i
);
55 t_error("additional %d non-image errors (not printed)\n", ni_errors
);
59 if ((rv
=wcsrtombs(s
, &(const wchar_t *){map
+1}, sizeof s
, &st
)) != 255)
60 t_error("wcsrtombs returned %zd, expected 255\n", rv
);
61 if ((rv
=mbsrtowcs(wtmp
, &(const char *){s
}, 256, &st
)) != 255)
62 t_error("mbsrtowcs returned %zd, expected 255\n", rv
);
63 if (memcmp(map
+1, wtmp
, 256*sizeof(*map
)))
64 t_error("wcsrtombs/mbsrtowcs round trip failed\n");
66 for (i
=128; i
<256; i
++) {
67 if (iswalnum(map
[i
])) t_error("iswalnum returned true for %.4x (%.2x)\n", map
[i
], i
);
68 if (iswalpha(map
[i
])) t_error("iswalpha returned true for %.4x (%.2x)\n", map
[i
], i
);
69 if (iswblank(map
[i
])) t_error("iswblank returned true for %.4x (%.2x)\n", map
[i
], i
);
70 if (iswcntrl(map
[i
])) t_error("iswcntrl returned true for %.4x (%.2x)\n", map
[i
], i
);
71 if (iswdigit(map
[i
])) t_error("iswdigit returned true for %.4x (%.2x)\n", map
[i
], i
);
72 if (iswgraph(map
[i
])) t_error("iswgraph returned true for %.4x (%.2x)\n", map
[i
], i
);
73 if (iswlower(map
[i
])) t_error("iswlower returned true for %.4x (%.2x)\n", map
[i
], i
);
74 if (iswprint(map
[i
])) t_error("iswprint returned true for %.4x (%.2x)\n", map
[i
], i
);
75 if (iswpunct(map
[i
])) t_error("iswpunct returned true for %.4x (%.2x)\n", map
[i
], i
);
76 if (iswspace(map
[i
])) t_error("iswspace returned true for %.4x (%.2x)\n", map
[i
], i
);
77 if (iswupper(map
[i
])) t_error("iswupper returned true for %.4x (%.2x)\n", map
[i
], i
);
78 if (iswxdigit(map
[i
])) t_error("iswxdigit returned true for %.4x (%.2x)\n", map
[i
], i
);