2.9
[glibc/nacl-glibc.git] / localedata / tests-mbwc / tst_mbsrtowcs.c
blob3f3ea716b49b91c24799ee1f57932999dfaeab60
1 /*
2 MBSRTOWCS: size_t mbsrtowcs (wchar_t *ws, const char **s, size_t n,
3 mbstate_t *ps)
4 */
6 #define TST_FUNCTION mbsrtowcs
8 #include "tsp_common.c"
9 #include "dat_mbsrtowcs.c"
11 int
12 tst_mbsrtowcs (FILE * fp, int debug_flg)
14 TST_DECL_VARS (size_t);
15 char w_flg;
16 const char *s, *p;
17 size_t n;
18 char t_flg, t_ini;
19 static mbstate_t t = { 0 };
20 mbstate_t *pt;
21 wchar_t ws[WCSSIZE], *ws_ex, *wp;
22 int err, i;
24 TST_DO_TEST (mbsrtowcs)
26 TST_HEAD_LOCALE (mbsrtowcs, S_MBSRTOWCS);
27 TST_DO_REC (mbsrtowcs)
29 s = "";
30 if (mbsrtowcs (NULL, &s, 0, &t) != 0)
32 err_count++;
33 Result (C_FAILURE, S_MBSRTOWCS, CASE_3,
34 "Initialization failed - skipping this test case.");
35 continue;
38 TST_DO_SEQ (MBSRTOWCS_SEQNUM)
40 TST_GET_ERRET_SEQ (mbsrtowcs);
41 w_flg = TST_INPUT_SEQ (mbsrtowcs).w_flg;
42 p = s = TST_INPUT_SEQ (mbsrtowcs).s;
43 n = TST_INPUT_SEQ (mbsrtowcs).n;
44 t_flg = TST_INPUT_SEQ (mbsrtowcs).t_flg;
45 t_ini = TST_INPUT_SEQ (mbsrtowcs).t_init;
46 wp = (w_flg == 0) ? NULL : ws;
48 if (n == USE_MBCURMAX)
50 n = MB_CUR_MAX;
53 pt = (t_flg == 0) ? NULL : &t;
55 if (t_ini != 0)
57 memset (&t, 0, sizeof (t));
60 TST_CLEAR_ERRNO;
61 ret = mbsrtowcs (wp, &p, n, pt);
62 TST_SAVE_ERRNO;
64 if (debug_flg)
66 fprintf (stderr, "mbsrtowcs: [ %d ] : ret = %zd\n", rec + 1, ret);
69 TST_IF_RETURN (S_MBSRTOWCS)
73 if (wp == NULL || ret == (size_t) - 1 || ret == (size_t) - 2)
75 continue;
78 ws_ex = TST_EXPECT_SEQ (mbsrtowcs).ws;
79 for (err = 0, i = 0; i < ret; i++)
81 if (debug_flg)
83 fprintf (stderr,
84 "mbsrtowcs: ws[%d] => 0x%lx : 0x%lx <= ws_ex[%d]\n",
85 i, (unsigned long int) ws[i],
86 (unsigned long int) ws_ex[i], i);
89 if (ws[i] != ws_ex[i])
91 err++;
92 err_count++;
93 Result (C_FAILURE, S_MBSRTOWCS, CASE_4,
94 "the converted wc string has "
95 "different value from an expected string");
96 break;
100 if (!err)
102 Result (C_SUCCESS, S_MBSRTOWCS, CASE_4, MS_PASSED);
108 return err_count;