Back to index

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