1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
/*
MBTOWC: int mbtowc (wchar_t *wc, char *s, size_t n)
*/
#define TST_FUNCTION mbtowc
#include "tsp_common.c"
#include "dat_mbtowc.c"
int
tst_mbtowc (FILE * fp, int debug_flg)
{
TST_DECL_VARS (int);
char w_flg, s_flg;
const char *s_in;
size_t n;
wchar_t wc, wc_ex, *wp;
TST_DO_TEST (mbtowc)
{
TST_HEAD_LOCALE (mbtowc, S_MBTOWC);
TST_DO_REC (mbtowc)
{
if (mbstowcs (NULL, "", 0) != 0)
{
err_count++;
Result (C_FAILURE, S_MBSTOWCS, CASE_3,
"Initialization failed - skipping this test case.");
continue;
}
TST_DO_SEQ (MBTOWC_SEQNUM)
{
TST_GET_ERRET_SEQ (mbtowc);
w_flg = TST_INPUT_SEQ (mbtowc).w_flg;
s_flg = TST_INPUT_SEQ (mbtowc).s_flg;
n = TST_INPUT_SEQ (mbtowc).n;
if (n == USE_MBCURMAX)
{
n = MB_CUR_MAX;
}
if (s_flg == 0)
s_in = NULL;
else
s_in = TST_INPUT_SEQ (mbtowc).s;
wp = (wchar_t *) ((w_flg == 0) ? NULL : &wc);
/* XXX Clear the internal state. We should probably have
a flag for this. */
mbtowc (NULL, NULL, 0);
TST_CLEAR_ERRNO;
ret = mbtowc (wp, s_in, n);
TST_SAVE_ERRNO;
if (debug_flg)
{
fprintf (stdout, "mbtowc() [ %s : %d ] ret = %d\n", locale,
rec + 1, ret);
fprintf (stdout, " errno = %d\n",
errno_save);
}
TST_IF_RETURN (S_MBTOWC)
{
if (s_in == NULL)
{ /* state dependency */
if (ret_exp == +1)
{ /* state-dependent */
if (ret != 0)
{
/* Non-zero: state-dependent encoding. */
Result (C_SUCCESS, S_MBTOWC, CASE_3, MS_PASSED);
}
else
{
err_count++;
Result (C_FAILURE, S_MBTOWC, CASE_3,
"should be state-dependent encoding, "
"but a return value shows it is "
"state-independent");
}
}
if (ret_exp == 0)
{ /* state-independent */
if (ret == 0)
{
/* Non-zero: state-dependent encoding. */
Result (C_SUCCESS, S_MBTOWC, CASE_3, MS_PASSED);
}
else
{
err_count++;
Result (C_FAILURE, S_MBTOWC, CASE_3,
"should be state-independent encoding, "
"but a return value shows it is "
"state-dependent");
}
}
}
}
if ((wp == NULL || s_in == NULL || s_in[0] == 0) || ret <= 0)
{
continue;
}
wc_ex = TST_EXPECT_SEQ (mbtowc).wc;
if (wc_ex == wc)
{
Result (C_SUCCESS, S_MBTOWC, CASE_4, MS_PASSED);
}
else
{
err_count++;
Result (C_FAILURE, S_MBTOWC, CASE_4,
"converted wc is different from an expected wc");
}
}
}
}
return err_count;
}
|