Back to index

glibc  2.9
tst_mbtowc.c
Go to the documentation of this file.
00001 /*
00002   MBTOWC: int mbtowc (wchar_t *wc, char *s, size_t n)
00003 */
00004 
00005 #define TST_FUNCTION mbtowc
00006 
00007 #include "tsp_common.c"
00008 #include "dat_mbtowc.c"
00009 
00010 
00011 int
00012 tst_mbtowc (FILE * fp, int debug_flg)
00013 {
00014   TST_DECL_VARS (int);
00015   char w_flg, s_flg;
00016   const char *s_in;
00017   size_t n;
00018   wchar_t wc, wc_ex, *wp;
00019 
00020   TST_DO_TEST (mbtowc)
00021   {
00022     TST_HEAD_LOCALE (mbtowc, S_MBTOWC);
00023     TST_DO_REC (mbtowc)
00024     {
00025       if (mbstowcs (NULL, "", 0) != 0)
00026        {
00027          err_count++;
00028          Result (C_FAILURE, S_MBSTOWCS, CASE_3,
00029                 "Initialization failed - skipping this test case.");
00030          continue;
00031        }
00032 
00033       TST_DO_SEQ (MBTOWC_SEQNUM)
00034       {
00035        TST_GET_ERRET_SEQ (mbtowc);
00036        w_flg = TST_INPUT_SEQ (mbtowc).w_flg;
00037        s_flg = TST_INPUT_SEQ (mbtowc).s_flg;
00038        n = TST_INPUT_SEQ (mbtowc).n;
00039 
00040        if (n == USE_MBCURMAX)
00041          {
00042            n = MB_CUR_MAX;
00043          }
00044 
00045        if (s_flg == 0)
00046          s_in = NULL;
00047        else
00048          s_in = TST_INPUT_SEQ (mbtowc).s;
00049 
00050        wp = (wchar_t *) ((w_flg == 0) ? NULL : &wc);
00051 
00052        /* XXX Clear the internal state.  We should probably have
00053           a flag for this.  */
00054        mbtowc (NULL, NULL, 0);
00055 
00056        TST_CLEAR_ERRNO;
00057        ret = mbtowc (wp, s_in, n);
00058        TST_SAVE_ERRNO;
00059 
00060        if (debug_flg)
00061          {
00062            fprintf (stdout, "mbtowc() [ %s : %d ] ret = %d\n", locale,
00063                    rec + 1, ret);
00064            fprintf (stdout, "                       errno      = %d\n",
00065                    errno_save);
00066          }
00067 
00068        TST_IF_RETURN (S_MBTOWC)
00069        {
00070          if (s_in == NULL)
00071            {                /* state dependency */
00072              if (ret_exp == +1)
00073               {             /* state-dependent  */
00074                 if (ret != 0)
00075                   {
00076                     /* Non-zero: state-dependent encoding.  */
00077                     Result (C_SUCCESS, S_MBTOWC, CASE_3, MS_PASSED);
00078                   }
00079                 else
00080                   {
00081                     err_count++;
00082                     Result (C_FAILURE, S_MBTOWC, CASE_3,
00083                            "should be state-dependent encoding, "
00084                            "but a return value shows it is "
00085                            "state-independent");
00086                   }
00087               }
00088 
00089              if (ret_exp == 0)
00090               {             /* state-independent */
00091                 if (ret == 0)
00092                   {
00093                     /* Non-zero: state-dependent encoding.  */
00094                     Result (C_SUCCESS, S_MBTOWC, CASE_3, MS_PASSED);
00095                   }
00096                 else
00097                   {
00098                     err_count++;
00099                     Result (C_FAILURE, S_MBTOWC, CASE_3,
00100                            "should be state-independent encoding, "
00101                            "but a return value shows it is "
00102                            "state-dependent");
00103                   }
00104               }
00105            }
00106        }
00107 
00108        if ((wp == NULL || s_in == NULL || s_in[0] == 0) || ret <= 0)
00109          {
00110            continue;
00111          }
00112 
00113        wc_ex = TST_EXPECT_SEQ (mbtowc).wc;
00114 
00115        if (wc_ex == wc)
00116          {
00117            Result (C_SUCCESS, S_MBTOWC, CASE_4, MS_PASSED);
00118          }
00119        else
00120          {
00121            err_count++;
00122            Result (C_FAILURE, S_MBTOWC, CASE_4,
00123                   "converted wc is different from an expected wc");
00124          }
00125       }
00126     }
00127   }
00128 
00129   return err_count;
00130 }