lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* |
| 2 | WCSXFRM: size_t wcsxfrm (wchar_t *ws1, const wchar_t *ws2, size_t n); |
| 3 | */ |
| 4 | |
| 5 | #define TST_FUNCTION wcsxfrm |
| 6 | |
| 7 | #include "tsp_common.c" |
| 8 | #include "dat_wcsxfrm.c" |
| 9 | |
| 10 | int |
| 11 | tst_wcsxfrm (FILE * fp, int debug_flg) |
| 12 | { |
| 13 | TST_DECL_VARS (size_t); |
| 14 | wchar_t *org1, *org2; |
| 15 | wchar_t frm1[MBSSIZE], frm2[MBSSIZE]; |
| 16 | size_t n1, n2; |
| 17 | int ret_coll, ret_cmp; |
| 18 | |
| 19 | TST_DO_TEST (wcsxfrm) |
| 20 | { |
| 21 | TST_HEAD_LOCALE (wcsxfrm, S_WCSXFRM); |
| 22 | TST_DO_REC (wcsxfrm) |
| 23 | { |
| 24 | TST_GET_ERRET (wcsxfrm); |
| 25 | org1 = TST_INPUT (wcsxfrm).org1; |
| 26 | org2 = TST_INPUT (wcsxfrm).org2; |
| 27 | n1 = TST_INPUT (wcsxfrm).n1; |
| 28 | n2 = TST_INPUT (wcsxfrm).n2; |
| 29 | if (n1 < 0 || sizeof (frm1) < n1 || sizeof (frm2) < n2) |
| 30 | { |
| 31 | warn_count++; |
| 32 | Result (C_IGNORED, S_WCSXFRM, CASE_9, |
| 33 | "input data n1 or n2 is invalid"); |
| 34 | continue; |
| 35 | } |
| 36 | |
| 37 | /* an errno and a return value are checked |
| 38 | only for 2nd wcsxfrm() call. |
| 39 | A result of 1st call is used to compare |
| 40 | those 2 values by using wcscmp(). |
| 41 | */ |
| 42 | |
| 43 | TST_CLEAR_ERRNO; |
| 44 | ret = wcsxfrm (frm1, org1, n1); /* First call */ |
| 45 | TST_SAVE_ERRNO; |
| 46 | |
| 47 | if (debug_flg) |
| 48 | { |
| 49 | fprintf (stdout, "tst_wcsxfrm() : REC = %d\n", rec + 1); |
| 50 | fprintf (stdout, "tst_wcsxfrm() : 1st ret = %zu\n", ret); |
| 51 | } |
| 52 | |
| 53 | if (ret == -1 || ret >= n1 || errno_save != 0) |
| 54 | { |
| 55 | warn_count++; |
| 56 | Result (C_INVALID, S_WCSXFRM, CASE_8, |
| 57 | "got an error in fist wcsxfrm() call"); |
| 58 | continue; |
| 59 | } |
| 60 | |
| 61 | TST_CLEAR_ERRNO; |
| 62 | /* Second call */ |
| 63 | ret = wcsxfrm (((n2 == 0) ? NULL : frm2), org2, n2); |
| 64 | TST_SAVE_ERRNO; |
| 65 | |
| 66 | TST_IF_RETURN (S_WCSXFRM) |
| 67 | { |
| 68 | }; |
| 69 | |
| 70 | if (n2 == 0 || ret >= n2 || errno != 0) |
| 71 | { |
| 72 | #if 0 |
| 73 | warn_count++; |
| 74 | Result (C_IGNORED, S_WCSXFRM, CASE_7, "did not get a result"); |
| 75 | #endif |
| 76 | continue; |
| 77 | } |
| 78 | |
| 79 | if (debug_flg) |
| 80 | { |
| 81 | fprintf (stdout, "tst_wcsxfrm() : 2nd ret = %zu\n", ret); |
| 82 | } |
| 83 | |
| 84 | /* wcscoll() */ |
| 85 | TST_CLEAR_ERRNO; |
| 86 | /* depends on wcscoll() ... not good though ... */ |
| 87 | ret_coll = wcscoll (org1, org2); |
| 88 | TST_SAVE_ERRNO; |
| 89 | |
| 90 | if (errno != 0) /* bugs * bugs may got correct results ... */ |
| 91 | { |
| 92 | warn_count++; |
| 93 | Result (C_INVALID, S_WCSXFRM, CASE_6, |
| 94 | "got an error in wcscoll() call"); |
| 95 | continue; |
| 96 | } |
| 97 | /* wcscmp() */ |
| 98 | ret_cmp = wcscmp (frm1, frm2); |
| 99 | |
| 100 | if ((ret_coll == ret_cmp) || (ret_coll > 0 && ret_cmp > 0) |
| 101 | || (ret_coll < 0 && ret_cmp < 0)) |
| 102 | { |
| 103 | Result (C_SUCCESS, S_WCSXFRM, CASE_3, |
| 104 | MS_PASSED " (depends on wcscoll & wcscmp)"); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | err_count++; |
| 109 | Result (C_FAILURE, S_WCSXFRM, CASE_3, |
| 110 | "results from wcscoll & wcscmp() do not match"); |
| 111 | } |
| 112 | |
| 113 | if (debug_flg) |
| 114 | { |
| 115 | fprintf (stdout, "tst_wcsxfrm() : coll = %d <-> %d = cmp\n", |
| 116 | ret_coll, ret_cmp); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return err_count; |
| 122 | } |