(root)/
glibc-2.38/
localedata/
tests-mbwc/
tst_mbstowcs.c
       1  /*
       2    MBSTOWCS: size_t mbstowcs (wchar_t *ws, char *s, size_t n)
       3  */
       4  
       5  #define TST_FUNCTION mbstowcs
       6  
       7  #include "tsp_common.c"
       8  #include "dat_mbstowcs.c"
       9  
      10  int
      11  tst_mbstowcs (FILE * fp, int debug_flg)
      12  {
      13    TST_DECL_VARS (size_t);
      14    char w_flg, s_flg;
      15    const char *s;
      16    size_t n;
      17    wchar_t ws[WCSSIZE], *ws_ex, *wp;
      18    int err, i;
      19  
      20    TST_DO_TEST (mbstowcs)
      21    {
      22      TST_HEAD_LOCALE (mbstowcs, S_MBSTOWCS);
      23      TST_DO_REC (mbstowcs)
      24      {
      25        if (mbstowcs (NULL, "", 0) != 0)
      26  	{
      27  	  err_count++;
      28  	  Result (C_FAILURE, S_MBSTOWCS, CASE_3,
      29  		  "Initialization failed - skipping this test case.");
      30  	  continue;
      31  	}
      32  
      33        TST_DO_SEQ (MBSTOWCS_SEQNUM)
      34        {
      35  	TST_GET_ERRET_SEQ (mbstowcs);
      36  	w_flg = TST_INPUT_SEQ (mbstowcs).w_flg;
      37  	s_flg = TST_INPUT_SEQ (mbstowcs).s_flg;
      38  	n = TST_INPUT_SEQ (mbstowcs).n;
      39  
      40  	if (s_flg == 0)
      41  	  s = NULL;
      42  	else
      43  	  s = TST_INPUT_SEQ (mbstowcs).s;
      44  
      45  
      46  	wp = (wchar_t *) ((w_flg == 0) ? NULL : ws);
      47  
      48  	TST_CLEAR_ERRNO;
      49  	ret = mbstowcs (wp, s, n);
      50  	TST_SAVE_ERRNO;
      51  
      52  	if (debug_flg)
      53  	  {
      54  	    fprintf (stderr, "mbstowcs: ret = %zd\n", ret);
      55  	  }
      56  
      57  	TST_IF_RETURN (S_MBSTOWCS)
      58  	{
      59  	};
      60  
      61  	if (s == NULL || wp == NULL || ret == (size_t) - 1)
      62  	  {
      63  	    continue;
      64  	  }
      65  
      66  	ws_ex = TST_EXPECT_SEQ (mbstowcs).ws;
      67  
      68  	for (err = 0, i = 0; i < ret; i++)
      69  	  {
      70  	    if (debug_flg)
      71  	      {
      72  		fprintf (stderr,
      73  			 "mbstowcs: ws[%d] => 0x%lx : 0x%lx <= ws_ex[%d]\n",
      74  			 i, (unsigned long int) ws[i],
      75  			 (unsigned long int) ws_ex[i], i);
      76  	      }
      77  
      78  	    if (ws[i] != ws_ex[i])
      79  	      {
      80  		err++;
      81  		err_count++;
      82  		Result (C_FAILURE, S_MBSTOWCS, CASE_4,
      83  			"the converted wc string has "
      84  			"different value from an expected string");
      85  		break;
      86  	      }
      87  	  }
      88  
      89  	if (!err)
      90  	  {
      91  	    Result (C_SUCCESS, S_MBSTOWCS, CASE_4, MS_PASSED);
      92  	  }
      93        }
      94      }
      95    }
      96  
      97    return err_count;
      98  }