(root)/
glibc-2.38/
localedata/
tests-mbwc/
tst_wcsxfrm.c
       1  /*
       2    WCSXFRM: size_t wcsxfrm (wchar_t *ws1, const wchar_t *ws2, size_t n);
       3  */
       4  
       5  #define TST_FUNCTION wcsxfrm
       6  
       7  #include "tsp_common.c"
       8  #include "dat_wcsxfrm.c"
       9  
      10  int
      11  tst_wcsxfrm (FILE * fp, int debug_flg)
      12  {
      13    TST_DECL_VARS (size_t);
      14    wchar_t *org1, *org2;
      15    wchar_t frm1[MBSSIZE], frm2[MBSSIZE];
      16    size_t n1, n2;
      17    int ret_coll, ret_cmp;
      18  
      19    TST_DO_TEST (wcsxfrm)
      20    {
      21      TST_HEAD_LOCALE (wcsxfrm, S_WCSXFRM);
      22      TST_DO_REC (wcsxfrm)
      23      {
      24        TST_GET_ERRET (wcsxfrm);
      25        org1 = TST_INPUT (wcsxfrm).org1;
      26        org2 = TST_INPUT (wcsxfrm).org2;
      27        n1 = TST_INPUT (wcsxfrm).n1;
      28        n2 = TST_INPUT (wcsxfrm).n2;
      29        if (n1 < 0 || sizeof (frm1) < n1 || sizeof (frm2) < n2)
      30  	{
      31  	  Result (C_IGNORED, S_WCSXFRM, CASE_9,
      32  		  "input data n1 or n2 is invalid");
      33  	  continue;
      34  	}
      35  
      36        /* an errno and a return value are checked
      37  	 only for 2nd wcsxfrm() call.
      38  	 A result of 1st call is used to compare
      39  	 those 2 values by using wcscmp().
      40         */
      41  
      42        TST_CLEAR_ERRNO;
      43        ret = wcsxfrm (frm1, org1, n1);	/* First call */
      44        TST_SAVE_ERRNO;
      45  
      46        if (debug_flg)
      47  	{
      48  	  fprintf (stdout, "tst_wcsxfrm() : REC = %d\n", rec + 1);
      49  	  fprintf (stdout, "tst_wcsxfrm() : 1st ret = %zu\n", ret);
      50  	}
      51  
      52        if (ret == -1 || ret >= n1 || errno_save != 0)
      53  	{
      54  	  Result (C_INVALID, S_WCSXFRM, CASE_8,
      55  		  "got an error in fist wcsxfrm() call");
      56  	  continue;
      57  	}
      58  
      59        TST_CLEAR_ERRNO;
      60        /* Second call */
      61        ret = wcsxfrm (((n2 == 0) ? NULL : frm2), org2, n2);
      62        TST_SAVE_ERRNO;
      63  
      64        TST_IF_RETURN (S_WCSXFRM)
      65        {
      66        };
      67  
      68        if (n2 == 0 || ret >= n2 || errno != 0)
      69  	{
      70  #if 0
      71  	  Result (C_IGNORED, S_WCSXFRM, CASE_7, "did not get a result");
      72  #endif
      73  	  continue;
      74  	}
      75  
      76        if (debug_flg)
      77  	{
      78  	  fprintf (stdout, "tst_wcsxfrm() : 2nd ret = %zu\n", ret);
      79  	}
      80  
      81        /* wcscoll() */
      82        TST_CLEAR_ERRNO;
      83        /* depends on wcscoll() ... not good though ... */
      84        ret_coll = wcscoll (org1, org2);
      85        TST_SAVE_ERRNO;
      86  
      87        if (errno != 0)		/* bugs * bugs may got correct results ... */
      88  	{
      89  	  Result (C_INVALID, S_WCSXFRM, CASE_6,
      90  		  "got an error in wcscoll() call");
      91  	  continue;
      92  	}
      93        /* wcscmp() */
      94        ret_cmp = wcscmp (frm1, frm2);
      95  
      96        if ((ret_coll == ret_cmp) || (ret_coll > 0 && ret_cmp > 0)
      97  	  || (ret_coll < 0 && ret_cmp < 0))
      98  	{
      99  	  Result (C_SUCCESS, S_WCSXFRM, CASE_3,
     100  		  MS_PASSED " (depends on wcscoll & wcscmp)");
     101  	}
     102        else
     103  	{
     104  	  err_count++;
     105  	  Result (C_FAILURE, S_WCSXFRM, CASE_3,
     106  		  "results from wcscoll & wcscmp() do not match");
     107  	}
     108  
     109        if (debug_flg)
     110  	{
     111  	  fprintf (stdout, "tst_wcsxfrm() : coll = %d <-> %d = cmp\n",
     112  		   ret_coll, ret_cmp);
     113  	}
     114      }
     115    }
     116  
     117    return err_count;
     118  }