blob: 3a6070a870550552a60f6fcce20aeee490c073d8 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 MBRTOWC: size_t mbrtowc (wchar_t *pwc, const char *s, size_t n,
3 mbstate_t *ps)
4*/
5
6#define TST_FUNCTION mbrtowc
7
8#include "tsp_common.c"
9#include "dat_mbrtowc.c"
10
11
12int
13tst_mbrtowc (FILE * fp, int debug_flg)
14{
15 TST_DECL_VARS (size_t);
16 char w_flg, s_flg;
17 char *s;
18 size_t n;
19 char t_flg, t_ini;
20 static mbstate_t t = { 0 };
21 mbstate_t *pt;
22 wchar_t wc, *pwc, wc_ex;
23
24 TST_DO_TEST (mbrtowc)
25 {
26 TST_HEAD_LOCALE (mbrtowc, S_MBRTOWC);
27 TST_DO_REC (mbrtowc)
28 {
29 if (mbrtowc (NULL, "", 0, &t) != 0)
30 {
31 err_count++;
32 Result (C_FAILURE, S_MBRTOWC, CASE_3,
33 "Initialization failed - skipping this test case.");
34 continue;
35 }
36
37 TST_DO_SEQ (MBRTOWC_SEQNUM)
38 {
39 TST_GET_ERRET_SEQ (mbrtowc);
40 w_flg = TST_INPUT_SEQ (mbrtowc).w_flg;
41 s_flg = TST_INPUT_SEQ (mbrtowc).s_flg;
42 s = TST_INPUT_SEQ (mbrtowc).s;
43 n = TST_INPUT_SEQ (mbrtowc).n;
44 t_flg = TST_INPUT_SEQ (mbrtowc).t_flg;
45 t_ini = TST_INPUT_SEQ (mbrtowc).t_init;
46 pwc = (w_flg == 0) ? NULL : &wc;
47
48 if (s_flg == 0)
49 {
50 s = NULL;
51 }
52
53 if (n == USE_MBCURMAX)
54 {
55 n = MB_CUR_MAX;
56 }
57
58 pt = (t_flg == 0) ? NULL : &t;
59#if 0
60 if (t_ini != 0)
61 {
62 memset (&t, 0, sizeof (t));
63 }
64#endif
65 TST_CLEAR_ERRNO;
66 ret = mbrtowc (pwc, s, n, pt);
67 TST_SAVE_ERRNO;
68
69 if (debug_flg)
70 {
71 fprintf (stdout, "mbrtowc() [ %s : %d : %d ] ret = %zd\n",
72 locale, rec + 1, seq_num + 1, ret);
73 fprintf (stdout, " errno = %hd\n",
74 errno_save);
75 }
76
77 TST_IF_RETURN (S_MBRTOWC)
78 {
79 };
80
81 if (pwc == NULL || s == NULL || ret == (size_t) - 1
82 || ret == (size_t) - 2)
83 {
84 continue;
85 }
86
87 wc_ex = TST_EXPECT_SEQ (mbrtowc).wc;
88 if (wc_ex == wc)
89 {
90 Result (C_SUCCESS, S_MBRTOWC, CASE_4, MS_PASSED);
91 }
92 else
93 {
94 err_count++;
95 Result (C_FAILURE, S_MBRTOWC, CASE_4,
96 "converted wc is different from an expected wc");
97 }
98 }
99 }
100 }
101
102 return err_count;
103}