Back to index

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