Back to index

glibc  2.9
tst_wcrtomb.c
Go to the documentation of this file.
00001 /*
00002   WCRTOMB: wchar_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
00003 */
00004 
00005 #define TST_FUNCTION wcrtomb
00006 
00007 #include "tsp_common.c"
00008 #include "dat_wcrtomb.c"
00009 
00010 
00011 int
00012 tst_wcrtomb (FILE * fp, int debug_flg)
00013 {
00014   TST_DECL_VARS (wchar_t);
00015   wchar_t wc;
00016   char s[MBSSIZE], *s_in, *s_ex;
00017   char t_flg, t_ini;
00018   static mbstate_t t = { 0 };
00019   mbstate_t *pt;
00020   int err, i;
00021 
00022   TST_DO_TEST (wcrtomb)
00023   {
00024     TST_HEAD_LOCALE (wcrtomb, S_WCRTOMB);
00025     TST_DO_REC (wcrtomb)
00026     {
00027       TST_GET_ERRET (wcrtomb);
00028       s_in = ((TST_INPUT (wcrtomb).s_flg) == 0) ? (char *) NULL : s;
00029       wc = TST_INPUT (wcrtomb).wc;
00030       t_flg = TST_INPUT (wcrtomb).t_flg;
00031       t_ini = TST_INPUT (wcrtomb).t_init;
00032       pt = (t_flg == 0) ? NULL : &t;
00033 
00034       if (t_ini != 0)
00035        {
00036          memset (&t, 0, sizeof (t));
00037        }
00038 
00039       TST_CLEAR_ERRNO;
00040       ret = wcrtomb (s_in, wc, pt);
00041       TST_SAVE_ERRNO;
00042 
00043       if (debug_flg)
00044        {
00045          fprintf (stdout, "wcrtomb() [ %s : %d ] ret = %lu\n", locale,
00046                  rec + 1, (unsigned long int) ret);
00047          fprintf (stdout, "               errno = %d\n", errno_save);
00048        }
00049 
00050       TST_IF_RETURN (S_WCRTOMB)
00051       {
00052       };
00053 
00054       s_ex = TST_EXPECT (wcrtomb).s;
00055 
00056       if (s_in)
00057        {
00058          for (i = 0, err = 0; *(s_ex + i) != 0 && i < MBSSIZE; i++)
00059            {
00060              if (s_in[i] != s_ex[i])
00061               {
00062                 err++;
00063                 err_count++;
00064                 Result (C_FAILURE, S_WCRTOMB, CASE_4,
00065                        "copied string is different from an "
00066                        "expected string");
00067                 break;
00068               }
00069            }
00070          if (!err)
00071            {
00072              Result (C_SUCCESS, S_WCRTOMB, CASE_4, MS_PASSED);
00073            }
00074        }
00075     }
00076   }
00077 
00078   return err_count;
00079 }