Back to index

glibc  2.9
tst_strfmon.c
Go to the documentation of this file.
00001 /*
00002   STRFMON: size_t strfmon (char *buf, size_t nbyte, const char *fmt, ...)
00003 */
00004 
00005 #define TST_FUNCTION strfmon
00006 
00007 #include "tsp_common.c"
00008 #include "dat_strfmon.c"
00009 #include <monetary.h>
00010 
00011 int
00012 tst_strfmon (FILE * fp, int debug_flg)
00013 {
00014   TST_DECL_VARS (size_t);
00015   char buf[MONSIZE], *mon;
00016   size_t nbt;
00017   char *fmt;
00018   double val;
00019 
00020   TST_DO_TEST (strfmon)
00021   {
00022     TST_HEAD_LOCALE (strfmon, S_STRFMON);
00023     TST_DO_REC (strfmon)
00024     {
00025       TST_GET_ERRET (strfmon);
00026       nbt = TST_INPUT (strfmon).nbytes;
00027       fmt = TST_INPUT (strfmon).fmt;
00028       val = TST_INPUT (strfmon).val;
00029       memset (buf, 0, MONSIZE);
00030       if (nbt > MONSIZE)
00031        {
00032          err_count++;
00033          Result (C_FAILURE, S_STRFMON, CASE_3, "buffer too small in test");
00034          continue;
00035        }
00036 
00037       TST_CLEAR_ERRNO;
00038       ret = strfmon (buf, nbt, fmt, val, val, val);
00039       TST_SAVE_ERRNO;
00040 
00041       if (debug_flg)        /* seems fprintf doesn't update the errno */
00042        {
00043          fprintf (stdout, "strfmon() [ %s : %d ]\n", locale, rec + 1);
00044          fprintf (stdout, "   : err = %d | %s\n", errno_save,
00045                  strerror (errno));
00046          fprintf (stdout, "   : ret = %zd; \t fmt = |%s|\n", ret, fmt);
00047          fprintf (stdout, "   : buf = |%s|\n\n", buf);
00048        }
00049 
00050       TST_IF_RETURN (S_STRFMON)
00051       {
00052       };
00053       if (errno != 0 || ret == -1)
00054        {
00055          continue;
00056        }
00057 
00058       mon = TST_EXPECT (strfmon).mon;
00059 
00060       if (!strcmp (buf, mon))
00061        {
00062          Result (C_SUCCESS, S_STRFMON, CASE_3, MS_PASSED);
00063        }
00064       else
00065        {
00066          err_count++;
00067          Result (C_FAILURE, S_STRFMON, CASE_3, "the formatted string is "
00068                 "different from an expected result");
00069        }
00070     }
00071   }
00072 
00073   return err_count;
00074 }