Silence warnings.
[glibc/history.git] / localedata / tests-mbwc / tst_wcstombs.c
blobc0851a4305fce5e4a6a9ee84de40020f19928cce
1 /*
2 WCSTOMBS: size_t wcstombs (char *s, const wchar_t *ws, size_t n)
3 */
5 #define TST_FUNCTION wcstombs
7 #include "tsp_common.c"
8 #include "dat_wcstombs.c"
10 #define MARK_VAL 0x01
12 int
13 tst_wcstombs (FILE * fp, int debug_flg)
15 TST_DECL_VARS (size_t);
16 char s_flg, n;
17 wchar_t *ws;
18 char s[MBSSIZE], *s_in;
19 int err, i;
20 char *s_ex;
22 TST_DO_TEST (wcstombs)
24 TST_HEAD_LOCALE (wcstombs, S_WCSTOMBS);
25 TST_DO_REC (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;
35 TST_CLEAR_ERRNO;
36 ret = wcstombs (s_in, ws, n);
37 TST_SAVE_ERRNO;
39 if (debug_flg)
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++)
55 if (debug_flg)
57 fprintf (stdout,
58 " : s[%d] = 0x%hx <-> 0x%hx = s_ex[%d]\n", i,
59 s[i], s_ex[i], i);
62 if (i == ret && ret == n) /* no null termination */
64 if (s[i] == MARK_VAL)
66 Result (C_SUCCESS, S_WCSTOMBS, CASE_4, MS_PASSED);
68 else
70 err_count++;
71 Result (C_FAILURE, S_WCSTOMBS, CASE_4,
72 "should not be null terminated "
73 "(it may be a null char), but it is");
76 break;
79 if (i == ret && ret < n) /* null termination */
81 if (s[i] == 0)
83 Result (C_SUCCESS, S_WCSTOMBS, CASE_5, MS_PASSED);
85 else
87 err_count++;
88 Result (C_FAILURE, S_WCSTOMBS, CASE_5,
89 "should be null terminated, but it is not");
92 break;
95 if (s[i] != s_ex[i])
97 err++;
98 err_count++;
99 Result (C_FAILURE, S_WCSTOMBS, CASE_6,
100 "converted string is different from an "
101 "expected string");
102 break;
106 if (!err)
108 Result (C_SUCCESS, S_WCSTOMBS, CASE_6, MS_PASSED);
114 return err_count;