Back to index

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