Back to index

glibc  2.9
tst_strxfrm.c
Go to the documentation of this file.
00001 /*
00002   STRXFRM: size_t strxfrm (char *s1, const char *s2, size_t n)
00003 */
00004 
00005 #define TST_FUNCTION strxfrm
00006 
00007 #include "tsp_common.c"
00008 #include "dat_strxfrm.c"
00009 
00010 
00011 int
00012 tst_strxfrm (FILE * fp, int debug_flg)
00013 {
00014   TST_DECL_VARS (size_t);
00015   const char *org1, *org2;
00016   char frm1[MBSSIZE], frm2[MBSSIZE];
00017   size_t n1, n2;
00018   int ret_coll, ret_cmp;
00019 
00020   TST_DO_TEST (strxfrm)
00021   {
00022     TST_HEAD_LOCALE (strxfrm, S_STRXFRM);
00023     TST_DO_REC (strxfrm)
00024     {
00025       TST_GET_ERRET (strxfrm);
00026       org1 = TST_INPUT (strxfrm).org1;
00027       org2 = TST_INPUT (strxfrm).org2;
00028       n1 = TST_INPUT (strxfrm).n1;
00029       n2 = TST_INPUT (strxfrm).n2;
00030 
00031       if (n1 < 0 || sizeof (frm1) < n1 || sizeof (frm2) < n2)
00032        {
00033          warn_count++;
00034          Result (C_IGNORED, S_STRXFRM, CASE_9,
00035                 "input data n1 or n2 is invalid");
00036          continue;
00037        }
00038 
00039       /* An errno and a return value are checked
00040         only for 2nd strxfrm() call.
00041         A result of 1st call is used for comparing
00042         those 2 values by using strcmp().
00043       */
00044 
00045       /*-- First call --*/
00046 
00047       TST_CLEAR_ERRNO;
00048       ret = strxfrm (frm1, org1, n1);
00049       TST_SAVE_ERRNO;
00050 
00051       if (debug_flg)
00052        {
00053          fprintf (stdout, "strxfrm() [ %s : %d ] ( 1st call )\n", locale,
00054                  rec + 1);
00055          fprintf (stdout, "   : err = %d | %s\n", errno_save,
00056                  strerror (errno));
00057          fprintf (stdout, "   : ret = %zu\n", ret);
00058          fprintf (stdout, "   : org = %s\n", org1);
00059        }
00060 
00061       if (ret >= n1 || errno != 0)
00062        {
00063          warn_count++;
00064          Result (C_INVALID, S_STRXFRM, CASE_8,
00065                 "got an error in fist strxfrm() call");
00066          continue;
00067        }
00068 
00069       /*-- Second call --*/
00070 
00071       TST_CLEAR_ERRNO;
00072       ret = strxfrm (((n2 == 0) ? NULL : frm2), org2, n2);
00073       TST_SAVE_ERRNO;
00074 
00075       if (debug_flg)
00076        {
00077          fprintf (stderr, "   ..............( 2nd call )\n");
00078          fprintf (stdout, "   : err = %d | %s\n", errno,
00079                  strerror (errno));
00080          fprintf (stdout, "   : ret = %zu\n", ret);
00081          fprintf (stdout, "   : org = %s\n", org2);
00082        }
00083 
00084       TST_IF_RETURN (S_STRXFRM)
00085       {
00086       };
00087 
00088       if (n2 == 0 || ret >= n2 || errno != 0)
00089        {
00090 #if 0
00091          warn_count++;
00092          Result (C_IGNORED, S_STRXFRM, CASE_7, "did not get a result");
00093 #endif
00094          continue;
00095        }
00096 
00097       /*-- strcoll & strcmp --*/
00098 
00099       TST_CLEAR_ERRNO;
00100       /* Depends on strcoll() ... not good though ... */
00101       ret_coll = strcoll (org1, org2);
00102 
00103       if (errno != 0)
00104        {
00105          /* bug * bug may get correct results ...         */
00106          warn_count++;
00107          Result (C_INVALID, S_STRXFRM, CASE_6,
00108                 "got an error in strcoll() call");
00109          continue;
00110        }
00111 
00112       ret_cmp = strcmp (frm1, frm2);
00113 
00114       if ((ret_coll == 0 && ret_cmp == 0)
00115          || (ret_coll < 0 && ret_cmp < 0) || (ret_coll > 0 && ret_cmp > 0))
00116        {
00117          Result (C_SUCCESS, S_STRXFRM, CASE_3,
00118                 MS_PASSED "(depends on strcoll & strcmp)");
00119        }
00120       else
00121        {
00122          err_count++;
00123          Result (C_FAILURE, S_STRXFRM, CASE_3,
00124                 "results from strcoll & strcmp() do not match");
00125        }
00126 
00127       if (debug_flg)
00128        {
00129          fprintf (stdout, ".......... strcoll = %d <-> %d = strcmp\n",
00130                  ret_coll, ret_cmp);
00131        }
00132     }
00133   }
00134 
00135   return err_count;
00136 }