lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* |
| 2 | STRFMON: size_t strfmon (char *buf, size_t nbyte, const char *fmt, ...) |
| 3 | */ |
| 4 | |
| 5 | #define TST_FUNCTION strfmon |
| 6 | |
| 7 | #include "tsp_common.c" |
| 8 | #include "dat_strfmon.c" |
| 9 | #include <monetary.h> |
| 10 | |
| 11 | int |
| 12 | tst_strfmon (FILE * fp, int debug_flg) |
| 13 | { |
| 14 | TST_DECL_VARS (size_t); |
| 15 | char buf[MONSIZE], *mon; |
| 16 | size_t nbt; |
| 17 | char *fmt; |
| 18 | double val; |
| 19 | |
| 20 | TST_DO_TEST (strfmon) |
| 21 | { |
| 22 | TST_HEAD_LOCALE (strfmon, S_STRFMON); |
| 23 | TST_DO_REC (strfmon) |
| 24 | { |
| 25 | TST_GET_ERRET (strfmon); |
| 26 | nbt = TST_INPUT (strfmon).nbytes; |
| 27 | fmt = TST_INPUT (strfmon).fmt; |
| 28 | val = TST_INPUT (strfmon).val; |
| 29 | memset (buf, 0, MONSIZE); |
| 30 | if (nbt > MONSIZE) |
| 31 | { |
| 32 | err_count++; |
| 33 | Result (C_FAILURE, S_STRFMON, CASE_3, "buffer too small in test"); |
| 34 | continue; |
| 35 | } |
| 36 | |
| 37 | TST_CLEAR_ERRNO; |
| 38 | ret = strfmon (buf, nbt, fmt, val, val, val); |
| 39 | TST_SAVE_ERRNO; |
| 40 | |
| 41 | if (debug_flg) /* seems fprintf doesn't update the errno */ |
| 42 | { |
| 43 | fprintf (stdout, "strfmon() [ %s : %d ]\n", locale, rec + 1); |
| 44 | fprintf (stdout, " : err = %d | %s\n", errno_save, |
| 45 | strerror (errno)); |
| 46 | fprintf (stdout, " : ret = %zd; \t fmt = |%s|\n", ret, fmt); |
| 47 | fprintf (stdout, " : buf = |%s|\n\n", buf); |
| 48 | } |
| 49 | |
| 50 | TST_IF_RETURN (S_STRFMON) |
| 51 | { |
| 52 | }; |
| 53 | if (errno != 0 || ret == -1) |
| 54 | { |
| 55 | continue; |
| 56 | } |
| 57 | |
| 58 | mon = TST_EXPECT (strfmon).mon; |
| 59 | |
| 60 | if (!strcmp (buf, mon)) |
| 61 | { |
| 62 | Result (C_SUCCESS, S_STRFMON, CASE_3, MS_PASSED); |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | err_count++; |
| 67 | Result (C_FAILURE, S_STRFMON, CASE_3, "the formatted string is " |
| 68 | "different from an expected result"); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | return err_count; |
| 74 | } |