Back to index

glibc  2.9
tst_wctomb.c
Go to the documentation of this file.
00001 /*
00002   WCTOMB: int wctomb (char *s, wchar_t wc)
00003 */
00004 
00005 #define TST_FUNCTION wctomb
00006 
00007 #include "tsp_common.c"
00008 #include "dat_wctomb.c"
00009 
00010 int
00011 tst_wctomb (FILE * fp, int debug_flg)
00012 {
00013   TST_DECL_VARS (int);
00014   wchar_t wc;
00015   char s[MBSSIZE], *s_in, *s_ex;
00016   int err, i;
00017 
00018   TST_DO_TEST (wctomb)
00019   {
00020     TST_HEAD_LOCALE (wctomb, S_WCTOMB);
00021     TST_DO_REC (wctomb)
00022     {
00023       TST_GET_ERRET (wctomb);
00024       wc = TST_INPUT (wctomb).wc;
00025       s_in = ((TST_INPUT (wctomb).s_flg) == 0) ? (char *) NULL : s;
00026       ret = wctomb (s_in, wc);
00027 
00028       if (debug_flg)
00029        {
00030          fprintf (stdout, "wctomb() [ %s : %d ] ret  = %d\n", locale,
00031                  rec + 1, ret);
00032        }
00033 
00034       TST_IF_RETURN (S_WCTOMB)
00035       {
00036        if (s_in == NULL)    /* state dependency */
00037          {
00038            if (ret_exp == +1)      /* state-dependent  */
00039              {
00040               if (ret != 0)
00041                 {
00042                   /* Non-zero means state-dependent encoding.   */
00043                   Result (C_SUCCESS, S_WCTOMB, CASE_3, MS_PASSED);
00044                 }
00045               else
00046                 {
00047                   err_count++;
00048                   Result (C_FAILURE, S_WCTOMB, CASE_3,
00049                          "should be state-dependent encoding, "
00050                          "but a return value shows it is "
00051                          "state-independent");
00052                 }
00053              }
00054 
00055            if (ret_exp == 0)       /* state-independent */
00056              {
00057               if (ret == 0)
00058                 {
00059                   /* Non-zero means state-dependent encoding.   */
00060                   Result (C_SUCCESS, S_WCTOMB, CASE_3, MS_PASSED);
00061                 }
00062               else
00063                 {
00064                   err_count++;
00065                   Result (C_FAILURE, S_WCTOMB, CASE_3,
00066                          "should be state-independent encoding, "
00067                          "but a return value shows it is state-dependent");
00068                 }
00069              }
00070          }
00071       }
00072 
00073       s_ex = TST_EXPECT (wctomb).s;
00074 
00075       if (s_in)
00076        {
00077          for (i = 0, err = 0; *(s_ex + i) != 0 && i < MBSSIZE; i++)
00078            {
00079              if (s_in[i] != s_ex[i])
00080               {
00081                 err++;
00082                 err_count++;
00083                 Result (C_FAILURE, S_WCTOMB, CASE_4,
00084                        "copied string is different from an"
00085                        " expected string");
00086                 break;
00087               }
00088            }
00089 
00090          if (!err)
00091            {
00092              Result (C_SUCCESS, S_WCTOMB, CASE_4, MS_PASSED);
00093            }
00094        }
00095     }
00096   }
00097 
00098   return err_count;
00099 }