1/*
2 WCSRTOMBS: size_t wcsrtombs (char *s, const wchar_t **ws, size_t n,
3 mbstate_t *ps)
4*/
5
6#define TST_FUNCTION wcsrtombs
7
8#include "tsp_common.c"
9#include "dat_wcsrtombs.c"
10
11#define MARK_VAL 0x01
12
13int
14tst_wcsrtombs (FILE * fp, int debug_flg)
15{
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;
25
26 TST_DO_TEST (wcsrtombs)
27 {
28 TST_HEAD_LOCALE (wcsrtombs, S_WCSRTOMBS);
29 TST_DO_REC (wcsrtombs)
30 {
31 TST_GET_ERRET (wcsrtombs);
32 memset (s, MARK_VAL, MBSSIZE);
33
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;
41
42 if (t_ini != 0)
43 {
44 memset (&t, 0, sizeof (t));
45 }
46
47 TST_CLEAR_ERRNO;
48 ret = wcsrtombs (dst: s_in, src: &wp, len: n, ps: pt);
49 TST_SAVE_ERRNO;
50
51 if (debug_flg)
52 {
53 fprintf (stderr, "wcsrtombs: ret = %zu\n", ret);
54 }
55
56 TST_IF_RETURN (S_WCSRTOMBS)
57 {
58 };
59
60 if (s_in != NULL && ret != (size_t) - 1)
61 {
62 /* No definition for s, when error occurs. */
63 s_ex = TST_EXPECT (wcsrtombs).s;
64
65 for (err = 0, i = 0; i <= ret && i < MBSSIZE; i++)
66 {
67 if (debug_flg)
68 {
69 fprintf (stderr,
70 " : s[%d] = 0x%hx <-> 0x%hx = s_ex[%d]\n", i,
71 s[i], s_ex[i], i);
72 }
73
74 if (i == ret && ret == n) /* no null termination */
75 {
76 if (s[i] == MARK_VAL)
77 {
78 Result (C_SUCCESS, S_WCSRTOMBS, CASE_4, MS_PASSED);
79 }
80 else
81 {
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");
86 }
87
88 break;
89 }
90
91 if (i == ret && ret < n) /* null termination */
92 {
93 if (s[i] == 0)
94 {
95 Result (C_SUCCESS, S_WCSRTOMBS, CASE_5, MS_PASSED);
96 }
97 else
98 {
99 err_count++;
100 Result (C_FAILURE, S_WCSRTOMBS, CASE_5,
101 "should be null terminated, but it is not");
102 }
103
104 break;
105 }
106
107 if (s[i] != s_ex[i])
108 {
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;
115 }
116 }
117
118 if (!err)
119 {
120 Result (C_SUCCESS, S_WCSRTOMBS, CASE_6, MS_PASSED);
121 }
122 }
123 }
124 }
125
126 return err_count;
127}
128

source code of glibc/localedata/tests-mbwc/tst_wcsrtombs.c