Back to index

glibc  2.9
tst_mbrtowc.c
Go to the documentation of this file.
00001 /*
00002   MBRTOWC: size_t mbrtowc (wchar_t *pwc, const char *s, size_t n,
00003                         mbstate_t *ps)
00004 */
00005 
00006 #define TST_FUNCTION mbrtowc
00007 
00008 #include "tsp_common.c"
00009 #include "dat_mbrtowc.c"
00010 
00011 
00012 int
00013 tst_mbrtowc (FILE * fp, int debug_flg)
00014 {
00015   TST_DECL_VARS (size_t);
00016   char w_flg, s_flg;
00017   char *s;
00018   size_t n;
00019   char t_flg, t_ini;
00020   static mbstate_t t = { 0 };
00021   mbstate_t *pt;
00022   wchar_t wc, *pwc, wc_ex;
00023 
00024   TST_DO_TEST (mbrtowc)
00025   {
00026     TST_HEAD_LOCALE (mbrtowc, S_MBRTOWC);
00027     TST_DO_REC (mbrtowc)
00028     {
00029       if (mbrtowc (NULL, "", 0, &t) != 0)
00030        {
00031          err_count++;
00032          Result (C_FAILURE, S_MBRTOWC, CASE_3,
00033                 "Initialization failed - skipping this test case.");
00034          continue;
00035        }
00036 
00037       TST_DO_SEQ (MBRTOWC_SEQNUM)
00038       {
00039        TST_GET_ERRET_SEQ (mbrtowc);
00040        w_flg = TST_INPUT_SEQ (mbrtowc).w_flg;
00041        s_flg = TST_INPUT_SEQ (mbrtowc).s_flg;
00042        s = TST_INPUT_SEQ (mbrtowc).s;
00043        n = TST_INPUT_SEQ (mbrtowc).n;
00044        t_flg = TST_INPUT_SEQ (mbrtowc).t_flg;
00045        t_ini = TST_INPUT_SEQ (mbrtowc).t_init;
00046        pwc = (w_flg == 0) ? NULL : &wc;
00047 
00048        if (s_flg == 0)
00049          {
00050            s = NULL;
00051          }
00052 
00053        if (n == USE_MBCURMAX)
00054          {
00055            n = MB_CUR_MAX;
00056          }
00057 
00058        pt = (t_flg == 0) ? NULL : &t;
00059 #if 0
00060        if (t_ini != 0)
00061          {
00062            memset (&t, 0, sizeof (t));
00063          }
00064 #endif
00065        TST_CLEAR_ERRNO;
00066        ret = mbrtowc (pwc, s, n, pt);
00067        TST_SAVE_ERRNO;
00068 
00069        if (debug_flg)
00070          {
00071            fprintf (stdout, "mbrtowc() [ %s : %d : %d ] ret = %zd\n",
00072                    locale, rec + 1, seq_num + 1, ret);
00073            fprintf (stdout, "                        errno = %hd\n",
00074                    errno_save);
00075          }
00076 
00077        TST_IF_RETURN (S_MBRTOWC)
00078        {
00079        };
00080 
00081        if (pwc == NULL || s == NULL || ret == (size_t) - 1
00082            || ret == (size_t) - 2)
00083          {
00084            continue;
00085          }
00086 
00087        wc_ex = TST_EXPECT_SEQ (mbrtowc).wc;
00088        if (wc_ex == wc)
00089          {
00090            Result (C_SUCCESS, S_MBRTOWC, CASE_4, MS_PASSED);
00091          }
00092        else
00093          {
00094            err_count++;
00095            Result (C_FAILURE, S_MBRTOWC, CASE_4,
00096                   "converted wc is different from an expected wc");
00097          }
00098       }
00099     }
00100   }
00101 
00102   return err_count;
00103 }