|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
MBSTOWCS: size_t mbstowcs (wchar_t *ws, char *s, size_t n)
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define TST_FUNCTION mbstowcs
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include "tsp_common.c"
|
|
Packit |
6c4009 |
#include "dat_mbstowcs.c"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
tst_mbstowcs (FILE * fp, int debug_flg)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
TST_DECL_VARS (size_t);
|
|
Packit |
6c4009 |
char w_flg, s_flg;
|
|
Packit |
6c4009 |
const char *s;
|
|
Packit |
6c4009 |
size_t n;
|
|
Packit |
6c4009 |
wchar_t ws[WCSSIZE], *ws_ex, *wp;
|
|
Packit |
6c4009 |
int err, i;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
TST_DO_TEST (mbstowcs)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
TST_HEAD_LOCALE (mbstowcs, S_MBSTOWCS);
|
|
Packit |
6c4009 |
TST_DO_REC (mbstowcs)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (mbstowcs (NULL, "", 0) != 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
err_count++;
|
|
Packit |
6c4009 |
Result (C_FAILURE, S_MBSTOWCS, CASE_3,
|
|
Packit |
6c4009 |
"Initialization failed - skipping this test case.");
|
|
Packit |
6c4009 |
continue;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
TST_DO_SEQ (MBSTOWCS_SEQNUM)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
TST_GET_ERRET_SEQ (mbstowcs);
|
|
Packit |
6c4009 |
w_flg = TST_INPUT_SEQ (mbstowcs).w_flg;
|
|
Packit |
6c4009 |
s_flg = TST_INPUT_SEQ (mbstowcs).s_flg;
|
|
Packit |
6c4009 |
n = TST_INPUT_SEQ (mbstowcs).n;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (s_flg == 0)
|
|
Packit |
6c4009 |
s = NULL;
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
s = TST_INPUT_SEQ (mbstowcs).s;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
wp = (wchar_t *) ((w_flg == 0) ? NULL : ws);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
TST_CLEAR_ERRNO;
|
|
Packit |
6c4009 |
ret = mbstowcs (wp, s, n);
|
|
Packit |
6c4009 |
TST_SAVE_ERRNO;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (debug_flg)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fprintf (stderr, "mbstowcs: ret = %zd\n", ret);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
TST_IF_RETURN (S_MBSTOWCS)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (s == NULL || wp == NULL || ret == (size_t) - 1)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
continue;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ws_ex = TST_EXPECT_SEQ (mbstowcs).ws;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
for (err = 0, i = 0; i < ret; i++)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (debug_flg)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fprintf (stderr,
|
|
Packit |
6c4009 |
"mbstowcs: ws[%d] => 0x%lx : 0x%lx <= ws_ex[%d]\n",
|
|
Packit |
6c4009 |
i, (unsigned long int) ws[i],
|
|
Packit |
6c4009 |
(unsigned long int) ws_ex[i], i);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (ws[i] != ws_ex[i])
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
err++;
|
|
Packit |
6c4009 |
err_count++;
|
|
Packit |
6c4009 |
Result (C_FAILURE, S_MBSTOWCS, CASE_4,
|
|
Packit |
6c4009 |
"the converted wc string has "
|
|
Packit |
6c4009 |
"different value from an expected string");
|
|
Packit |
6c4009 |
break;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (!err)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
Result (C_SUCCESS, S_MBSTOWCS, CASE_4, MS_PASSED);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return err_count;
|
|
Packit |
6c4009 |
}
|