Back to index

glibc  2.9
tst_wcstombs.c
Go to the documentation of this file.
00001 /*
00002   WCSTOMBS: size_t wcstombs (char *s, const wchar_t *ws, size_t n)
00003 */
00004 
00005 #define TST_FUNCTION wcstombs
00006 
00007 #include "tsp_common.c"
00008 #include "dat_wcstombs.c"
00009 
00010 #define MARK_VAL 0x01
00011 
00012 int
00013 tst_wcstombs (FILE * fp, int debug_flg)
00014 {
00015   TST_DECL_VARS (size_t);
00016   char s_flg, n;
00017   wchar_t *ws;
00018   char s[MBSSIZE], *s_in;
00019   int err, i;
00020   char *s_ex;
00021 
00022   TST_DO_TEST (wcstombs)
00023   {
00024     TST_HEAD_LOCALE (wcstombs, S_WCSTOMBS);
00025     TST_DO_REC (wcstombs)
00026     {
00027       TST_GET_ERRET (wcstombs);
00028       memset (s, MARK_VAL, MBSSIZE);
00029 
00030       s_flg = TST_INPUT (wcstombs).s_flg;
00031       s_in = (s_flg == 1) ? s : (char *) NULL;
00032       ws = TST_INPUT (wcstombs).ws;
00033       n = TST_INPUT (wcstombs).n;
00034 
00035       TST_CLEAR_ERRNO;
00036       ret = wcstombs (s_in, ws, n);
00037       TST_SAVE_ERRNO;
00038 
00039       if (debug_flg)
00040        {
00041          fprintf (stdout, "wcstombs: ret  = %zu\n", ret);
00042        }
00043 
00044       TST_IF_RETURN (S_WCSTOMBS)
00045       {
00046       };
00047 
00048       if (s_in != NULL && ret != (size_t) - 1)
00049        {
00050          /* No definition for s, when error occurs.  */
00051          s_ex = TST_EXPECT (wcstombs).s;
00052 
00053          for (err = 0, i = 0; i <= ret && i < MBSSIZE; i++)
00054            {
00055              if (debug_flg)
00056               {
00057                 fprintf (stdout,
00058                         "   : s[%d] = 0x%hx <-> 0x%hx = s_ex[%d]\n", i,
00059                         s[i], s_ex[i], i);
00060               }
00061 
00062              if (i == ret && ret == n)    /* no null termination */
00063               {
00064                 if (s[i] == MARK_VAL)
00065                   {
00066                     Result (C_SUCCESS, S_WCSTOMBS, CASE_4, MS_PASSED);
00067                   }
00068                 else
00069                   {
00070                     err_count++;
00071                     Result (C_FAILURE, S_WCSTOMBS, CASE_4,
00072                            "should not be null terminated "
00073                            "(it may be a null char), but it is");
00074                   }
00075 
00076                 break;
00077               }
00078 
00079              if (i == ret && ret < n)     /* null termination */
00080               {
00081                 if (s[i] == 0)
00082                   {
00083                     Result (C_SUCCESS, S_WCSTOMBS, CASE_5, MS_PASSED);
00084                   }
00085                 else
00086                   {
00087                     err_count++;
00088                     Result (C_FAILURE, S_WCSTOMBS, CASE_5,
00089                            "should be null terminated, but it is not");
00090                   }
00091 
00092                 break;
00093               }
00094 
00095              if (s[i] != s_ex[i])
00096               {
00097                 err++;
00098                 err_count++;
00099                 Result (C_FAILURE, S_WCSTOMBS, CASE_6,
00100                        "converted string is different from an "
00101                        "expected string");
00102                 break;
00103               }
00104            }
00105 
00106          if (!err)
00107            {
00108              Result (C_SUCCESS, S_WCSTOMBS, CASE_6, MS_PASSED);
00109            }
00110        }
00111     }
00112   }
00113 
00114   return err_count;
00115 }