tst_strfmon.c 1.5 KB

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