Remove unused math/Makefile variable libm-test-incs.
[glibc.git] / localedata / tests-mbwc / tst_wcsrtombs.c
blob3a8edccada11ff9bff890d5528c280b163bf1435
1 /*
2 WCSRTOMBS: size_t wcsrtombs (char *s, const wchar_t **ws, size_t n,
3 mbstate_t *ps)
4 */
6 #define TST_FUNCTION wcsrtombs
8 #include "tsp_common.c"
9 #include "dat_wcsrtombs.c"
11 #define MARK_VAL 0x01
13 int
14 tst_wcsrtombs (FILE * fp, int debug_flg)
16 TST_DECL_VARS (size_t);
17 char s_flg, n;
18 const wchar_t *ws, *wp;
19 char s[MBSSIZE], *s_in;
20 char t_flg, t_ini;
21 static mbstate_t t = { 0 };
22 mbstate_t *pt;
23 int err, i;
24 char *s_ex;
26 TST_DO_TEST (wcsrtombs)
28 TST_HEAD_LOCALE (wcsrtombs, S_WCSRTOMBS);
29 TST_DO_REC (wcsrtombs)
31 TST_GET_ERRET (wcsrtombs);
32 memset (s, MARK_VAL, MBSSIZE);
34 s_flg = TST_INPUT (wcsrtombs).s_flg;
35 s_in = (s_flg == 1) ? s : (char *) NULL;
36 wp = ws = TST_INPUT (wcsrtombs).ws;
37 n = TST_INPUT (wcsrtombs).n;
38 t_flg = TST_INPUT (wcsrtombs).t_flg;
39 t_ini = TST_INPUT (wcsrtombs).t_init;
40 pt = (t_flg == 0) ? NULL : &t;
42 if (t_ini != 0)
44 memset (&t, 0, sizeof (t));
47 TST_CLEAR_ERRNO;
48 ret = wcsrtombs (s_in, &wp, n, pt);
49 TST_SAVE_ERRNO;
51 if (debug_flg)
53 fprintf (stderr, "wcsrtombs: ret = %zu\n", ret);
56 TST_IF_RETURN (S_WCSRTOMBS)
60 if (s_in != NULL && ret != (size_t) - 1)
62 /* No definition for s, when error occurs. */
63 s_ex = TST_EXPECT (wcsrtombs).s;
65 for (err = 0, i = 0; i <= ret && i < MBSSIZE; i++)
67 if (debug_flg)
69 fprintf (stderr,
70 " : s[%d] = 0x%hx <-> 0x%hx = s_ex[%d]\n", i,
71 s[i], s_ex[i], i);
74 if (i == ret && ret == n) /* no null termination */
76 if (s[i] == MARK_VAL)
78 Result (C_SUCCESS, S_WCSRTOMBS, CASE_4, MS_PASSED);
80 else
82 err_count++;
83 Result (C_FAILURE, S_WCSRTOMBS, CASE_4,
84 "should not be null terminated "
85 "(it may be a null char), but it is");
88 break;
91 if (i == ret && ret < n) /* null termination */
93 if (s[i] == 0)
95 Result (C_SUCCESS, S_WCSRTOMBS, CASE_5, MS_PASSED);
97 else
99 err_count++;
100 Result (C_FAILURE, S_WCSRTOMBS, CASE_5,
101 "should be null terminated, but it is not");
104 break;
107 if (s[i] != s_ex[i])
109 err++;
110 err_count++;
111 Result (C_FAILURE, S_WCSRTOMBS, CASE_6,
112 "converted string is different from an"
113 " expected string");
114 break;
118 if (!err)
120 Result (C_SUCCESS, S_WCSRTOMBS, CASE_6, MS_PASSED);
126 return err_count;