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