2.9
[glibc/nacl-glibc.git] / localedata / tests-mbwc / tst_mbtowc.c
blob7c274f66c193412196e581aeb7bc456f6a1287c8
1 /*
2 MBTOWC: int mbtowc (wchar_t *wc, char *s, size_t n)
3 */
5 #define TST_FUNCTION mbtowc
7 #include "tsp_common.c"
8 #include "dat_mbtowc.c"
11 int
12 tst_mbtowc (FILE * fp, int debug_flg)
14 TST_DECL_VARS (int);
15 char w_flg, s_flg;
16 const char *s_in;
17 size_t n;
18 wchar_t wc, wc_ex, *wp;
20 TST_DO_TEST (mbtowc)
22 TST_HEAD_LOCALE (mbtowc, S_MBTOWC);
23 TST_DO_REC (mbtowc)
25 if (mbstowcs (NULL, "", 0) != 0)
27 err_count++;
28 Result (C_FAILURE, S_MBSTOWCS, CASE_3,
29 "Initialization failed - skipping this test case.");
30 continue;
33 TST_DO_SEQ (MBTOWC_SEQNUM)
35 TST_GET_ERRET_SEQ (mbtowc);
36 w_flg = TST_INPUT_SEQ (mbtowc).w_flg;
37 s_flg = TST_INPUT_SEQ (mbtowc).s_flg;
38 n = TST_INPUT_SEQ (mbtowc).n;
40 if (n == USE_MBCURMAX)
42 n = MB_CUR_MAX;
45 if (s_flg == 0)
46 s_in = NULL;
47 else
48 s_in = TST_INPUT_SEQ (mbtowc).s;
50 wp = (wchar_t *) ((w_flg == 0) ? NULL : &wc);
52 /* XXX Clear the internal state. We should probably have
53 a flag for this. */
54 mbtowc (NULL, NULL, 0);
56 TST_CLEAR_ERRNO;
57 ret = mbtowc (wp, s_in, n);
58 TST_SAVE_ERRNO;
60 if (debug_flg)
62 fprintf (stdout, "mbtowc() [ %s : %d ] ret = %d\n", locale,
63 rec + 1, ret);
64 fprintf (stdout, " errno = %d\n",
65 errno_save);
68 TST_IF_RETURN (S_MBTOWC)
70 if (s_in == NULL)
71 { /* state dependency */
72 if (ret_exp == +1)
73 { /* state-dependent */
74 if (ret != 0)
76 /* Non-zero: state-dependent encoding. */
77 Result (C_SUCCESS, S_MBTOWC, CASE_3, MS_PASSED);
79 else
81 err_count++;
82 Result (C_FAILURE, S_MBTOWC, CASE_3,
83 "should be state-dependent encoding, "
84 "but a return value shows it is "
85 "state-independent");
89 if (ret_exp == 0)
90 { /* state-independent */
91 if (ret == 0)
93 /* Non-zero: state-dependent encoding. */
94 Result (C_SUCCESS, S_MBTOWC, CASE_3, MS_PASSED);
96 else
98 err_count++;
99 Result (C_FAILURE, S_MBTOWC, CASE_3,
100 "should be state-independent encoding, "
101 "but a return value shows it is "
102 "state-dependent");
108 if ((wp == NULL || s_in == NULL || s_in[0] == 0) || ret <= 0)
110 continue;
113 wc_ex = TST_EXPECT_SEQ (mbtowc).wc;
115 if (wc_ex == wc)
117 Result (C_SUCCESS, S_MBTOWC, CASE_4, MS_PASSED);
119 else
121 err_count++;
122 Result (C_FAILURE, S_MBTOWC, CASE_4,
123 "converted wc is different from an expected wc");
129 return err_count;