2 WCSTOMBS: size_t wcstombs (char *s, const wchar_t *ws, size_t n)
5 #define TST_FUNCTION wcstombs
7 #include "tsp_common.c"
8 #include "dat_wcstombs.c"
13 tst_wcstombs (FILE * fp
, int debug_flg
)
15 TST_DECL_VARS (size_t);
18 char s
[MBSSIZE
], *s_in
;
22 TST_DO_TEST (wcstombs
)
24 TST_HEAD_LOCALE (wcstombs
, S_WCSTOMBS
);
27 TST_GET_ERRET (wcstombs
);
28 memset (s
, MARK_VAL
, MBSSIZE
);
30 s_flg
= TST_INPUT (wcstombs
).s_flg
;
31 s_in
= (s_flg
== 1) ? s
: (char *) NULL
;
32 ws
= TST_INPUT (wcstombs
).ws
;
33 n
= TST_INPUT (wcstombs
).n
;
36 ret
= wcstombs (s_in
, ws
, n
);
41 fprintf (stdout
, "wcstombs: ret = %zu\n", ret
);
44 TST_IF_RETURN (S_WCSTOMBS
)
48 if (s_in
!= NULL
&& ret
!= (size_t) - 1)
50 /* No definition for s, when error occurs. */
51 s_ex
= TST_EXPECT (wcstombs
).s
;
53 for (err
= 0, i
= 0; i
<= ret
&& i
< MBSSIZE
; i
++)
58 " : s[%d] = 0x%hx <-> 0x%hx = s_ex[%d]\n", i
,
62 if (i
== ret
&& ret
== n
) /* no null termination */
66 Result (C_SUCCESS
, S_WCSTOMBS
, CASE_4
, MS_PASSED
);
71 Result (C_FAILURE
, S_WCSTOMBS
, CASE_4
,
72 "should not be null terminated "
73 "(it may be a null char), but it is");
79 if (i
== ret
&& ret
< n
) /* null termination */
83 Result (C_SUCCESS
, S_WCSTOMBS
, CASE_5
, MS_PASSED
);
88 Result (C_FAILURE
, S_WCSTOMBS
, CASE_5
,
89 "should be null terminated, but it is not");
99 Result (C_FAILURE
, S_WCSTOMBS
, CASE_6
,
100 "converted string is different from an "
108 Result (C_SUCCESS
, S_WCSTOMBS
, CASE_6
, MS_PASSED
);