lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* |
| 2 | SWSCANF: int swscanf (const wchar_t *ws, const wchar_t *fmt, ...); |
| 3 | */ |
| 4 | |
| 5 | #define TST_FUNCTION swscanf |
| 6 | |
| 7 | #include "tsp_common.c" |
| 8 | #include "dat_swscanf.c" |
| 9 | |
| 10 | int |
| 11 | tst_swscanf (FILE * fp, int debug_flg) |
| 12 | { |
| 13 | TST_DECL_VARS (int); |
| 14 | wchar_t *ws; |
| 15 | wchar_t *fmt; |
| 16 | int val_int1; |
| 17 | unsigned val_int2; |
| 18 | float val_flt; |
| 19 | char val_c; |
| 20 | char val_s[MBSSIZE * 3]; |
| 21 | wchar_t val_S[WCSSIZE * 3], *exp_S; |
| 22 | int i; |
| 23 | |
| 24 | TST_DO_TEST (swscanf) |
| 25 | { |
| 26 | TST_HEAD_LOCALE (swscanf, S_SWSCANF); |
| 27 | TST_DO_REC (swscanf) |
| 28 | { |
| 29 | TST_GET_ERRET (swscanf); |
| 30 | ws = TST_INPUT (swscanf).ws; |
| 31 | fmt = TST_INPUT (swscanf).fmt; |
| 32 | val_int1 = val_int2 = val_flt = val_c = 0; |
| 33 | memset (val_s, 0, sizeof (val_s)); |
| 34 | memset (val_S, 0, sizeof (val_S)); |
| 35 | |
| 36 | TST_CLEAR_ERRNO; |
| 37 | |
| 38 | if (TST_INPUT (swscanf).wch) |
| 39 | { |
| 40 | ret = swscanf (ws, fmt, val_S); |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | ret = |
| 45 | swscanf (ws, fmt, &val_int1, &val_int2, &val_flt, &val_c, val_s); |
| 46 | } |
| 47 | |
| 48 | TST_SAVE_ERRNO; |
| 49 | |
| 50 | if (debug_flg) |
| 51 | { /* seems fprintf doesn't update errno */ |
| 52 | fprintf (stdout, "swscanf() [ %s : %d ] ret = %d\n", locale, |
| 53 | rec + 1, ret); |
| 54 | fprintf (stdout, " errno = %d\n", |
| 55 | errno_save); |
| 56 | fprintf (stdout, " collate = %s\n", |
| 57 | (setlocale (LC_COLLATE, NULL)) ? setlocale (LC_COLLATE, |
| 58 | NULL) : ""); |
| 59 | |
| 60 | if (TST_INPUT (swscanf).wch) |
| 61 | { |
| 62 | fprintf (stdout, " val_S[ 0 ] = 0x%lx\n", |
| 63 | (unsigned long int) val_S[0]); |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | fprintf (stdout, " val_int1 = %d\n", |
| 68 | val_int1); |
| 69 | fprintf (stdout, " val_int2 = %d\n", |
| 70 | val_int2); |
| 71 | fprintf (stdout, " val_flt = %f\n", |
| 72 | val_flt); |
| 73 | fprintf (stdout, " val_c = %c\n", |
| 74 | val_c); |
| 75 | fprintf (stdout, " val_s = %s\n", |
| 76 | val_s); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | TST_IF_RETURN (S_SWSCANF) |
| 81 | { |
| 82 | }; |
| 83 | |
| 84 | if (errno == 0 && TST_INPUT (swscanf).wch) |
| 85 | { |
| 86 | for (exp_S = TST_EXPECT (swscanf).val_S, i = 0; i < WCSSIZE * 3; |
| 87 | i++) |
| 88 | { |
| 89 | if (val_S[i] == L'\0' || exp_S[i] == L'\0') |
| 90 | { |
| 91 | if (val_S[i] != exp_S[i] && TST_INPUT (swscanf).wch == 'C') |
| 92 | { |
| 93 | err_count++; |
| 94 | Result (C_FAILURE, S_SWSCANF, CASE_4, |
| 95 | "the converted wide-char string is different" |
| 96 | " from an expected value."); |
| 97 | } |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | if (val_S[i] != exp_S[i]) |
| 102 | { |
| 103 | err_count++; |
| 104 | Result (C_FAILURE, S_SWSCANF, CASE_4, |
| 105 | "the converted wide-char string is different from" |
| 106 | " an expected value."); |
| 107 | break; |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | Result (C_SUCCESS, S_SWSCANF, CASE_4, MS_PASSED); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | if (errno == 0 && !TST_INPUT (swscanf).wch) |
| 117 | { |
| 118 | if (val_int1 != TST_EXPECT (swscanf).val_int || |
| 119 | val_int2 != TST_EXPECT (swscanf).val_uns || |
| 120 | val_flt != TST_EXPECT (swscanf).val_flt || |
| 121 | val_c != TST_EXPECT (swscanf).val_c || |
| 122 | strcmp (val_s, TST_EXPECT (swscanf).val_s)) |
| 123 | { |
| 124 | err_count++; |
| 125 | Result (C_FAILURE, S_SWSCANF, CASE_3, |
| 126 | "the converted values are different from expected values."); |
| 127 | } |
| 128 | else |
| 129 | { |
| 130 | Result (C_SUCCESS, S_SWSCANF, CASE_3, MS_PASSED); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return err_count; |
| 137 | } |