lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* |
| 2 | MBSRTOWCS: size_t mbsrtowcs (wchar_t *ws, const char **s, size_t n, |
| 3 | mbstate_t *ps) |
| 4 | */ |
| 5 | |
| 6 | #define TST_FUNCTION mbsrtowcs |
| 7 | |
| 8 | #include "tsp_common.c" |
| 9 | #include "dat_mbsrtowcs.c" |
| 10 | |
| 11 | int |
| 12 | tst_mbsrtowcs (FILE * fp, int debug_flg) |
| 13 | { |
| 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; |
| 23 | |
| 24 | TST_DO_TEST (mbsrtowcs) |
| 25 | { |
| 26 | TST_HEAD_LOCALE (mbsrtowcs, S_MBSRTOWCS); |
| 27 | TST_DO_REC (mbsrtowcs) |
| 28 | { |
| 29 | s = ""; |
| 30 | if (mbsrtowcs (NULL, &s, 0, &t) != 0) |
| 31 | { |
| 32 | err_count++; |
| 33 | Result (C_FAILURE, S_MBSRTOWCS, CASE_3, |
| 34 | "Initialization failed - skipping this test case."); |
| 35 | continue; |
| 36 | } |
| 37 | |
| 38 | TST_DO_SEQ (MBSRTOWCS_SEQNUM) |
| 39 | { |
| 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; |
| 47 | |
| 48 | if (n == USE_MBCURMAX) |
| 49 | { |
| 50 | n = MB_CUR_MAX; |
| 51 | } |
| 52 | |
| 53 | pt = (t_flg == 0) ? NULL : &t; |
| 54 | |
| 55 | if (t_ini != 0) |
| 56 | { |
| 57 | memset (&t, 0, sizeof (t)); |
| 58 | } |
| 59 | |
| 60 | TST_CLEAR_ERRNO; |
| 61 | ret = mbsrtowcs (wp, &p, n, pt); |
| 62 | TST_SAVE_ERRNO; |
| 63 | |
| 64 | if (debug_flg) |
| 65 | { |
| 66 | fprintf (stderr, "mbsrtowcs: [ %d ] : ret = %zd\n", rec + 1, ret); |
| 67 | } |
| 68 | |
| 69 | TST_IF_RETURN (S_MBSRTOWCS) |
| 70 | { |
| 71 | }; |
| 72 | |
| 73 | if (wp == NULL || ret == (size_t) - 1 || ret == (size_t) - 2) |
| 74 | { |
| 75 | continue; |
| 76 | } |
| 77 | |
| 78 | ws_ex = TST_EXPECT_SEQ (mbsrtowcs).ws; |
| 79 | for (err = 0, i = 0; i < ret; i++) |
| 80 | { |
| 81 | if (debug_flg) |
| 82 | { |
| 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); |
| 87 | } |
| 88 | |
| 89 | if (ws[i] != ws_ex[i]) |
| 90 | { |
| 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; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if (!err) |
| 101 | { |
| 102 | Result (C_SUCCESS, S_MBSRTOWCS, CASE_4, MS_PASSED); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | return err_count; |
| 109 | } |