Blame localedata/tests-mbwc/tst_wcsncpy.c

Packit 6c4009
/*
Packit 6c4009
  WCSNCPY: wchar_t *wcsncpy (wchar_t *ws1, const wchar_t *ws2, size_t n);
Packit 6c4009
*/
Packit 6c4009
Packit 6c4009
#define TST_FUNCTION wcsncpy
Packit 6c4009
Packit 6c4009
#include "tsp_common.c"
Packit 6c4009
#include "dat_wcsncpy.c"
Packit 6c4009
Packit 6c4009
#define WCSNUM_NCPY 7
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
tst_wcsncpy (FILE *fp, int debug_flg)
Packit 6c4009
{
Packit 6c4009
  TST_DECL_VARS (wchar_t *);
Packit 6c4009
  wchar_t ws1[WCSSIZE] =
Packit 6c4009
    { 0x9999, 0x9999, 0x9999, 0x9999, 0x9999, 0x9999, 0x0000 };
Packit 6c4009
  wchar_t *ws2, *ws_ex;
Packit 6c4009
  int err, i;
Packit 6c4009
  size_t n;
Packit 6c4009
Packit 6c4009
  TST_DO_TEST (wcsncpy)
Packit 6c4009
  {
Packit 6c4009
    TST_HEAD_LOCALE (wcsncpy, S_WCSNCPY);
Packit 6c4009
    TST_DO_REC (wcsncpy)
Packit 6c4009
    {
Packit 6c4009
      TST_GET_ERRET (wcsncpy);
Packit 6c4009
Packit 6c4009
      for (n = 0; n < WCSNUM_NCPY - 1; ++n)
Packit 6c4009
	{
Packit 6c4009
	  ws1[n] = 0x9999;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      ws1[n] = 0;
Packit 6c4009
      ws2 = TST_INPUT (wcsncpy).ws;	/* external value: size WCSSIZE */
Packit 6c4009
      n = TST_INPUT (wcsncpy).n;
Packit 6c4009
      ret = wcsncpy (ws1, ws2, n);
Packit 6c4009
Packit 6c4009
      TST_IF_RETURN (S_WCSNCPY)
Packit 6c4009
      {
Packit 6c4009
	if (ret == ws1)
Packit 6c4009
	  {
Packit 6c4009
	    Result (C_SUCCESS, S_WCSNCPY, CASE_3, MS_PASSED);
Packit 6c4009
	  }
Packit 6c4009
	else
Packit 6c4009
	  {
Packit 6c4009
	    err_count++;
Packit 6c4009
	    Result (C_FAILURE, S_WCSNCPY, CASE_3,
Packit 6c4009
		    "the return address may not be correct");
Packit 6c4009
	  }
Packit 6c4009
      }
Packit 6c4009
Packit 6c4009
      if (ret == ws1)
Packit 6c4009
	{
Packit 6c4009
	  if (debug_flg)
Packit 6c4009
	    {
Packit 6c4009
	      fprintf (stderr, "\nwcsncpy: n = %zu\n\n", n);
Packit 6c4009
	    }
Packit 6c4009
Packit 6c4009
	  ws_ex = TST_EXPECT (wcsncpy).ws;
Packit 6c4009
Packit 6c4009
	  for (err = 0, i = 0; i < WCSNUM_NCPY && i < WCSSIZE; i++)
Packit 6c4009
	    {
Packit 6c4009
	      if (debug_flg)
Packit 6c4009
		fprintf (stderr,
Packit 6c4009
			 "wcsncpy: ws1[ %d ] = 0x%lx <-> wx_ex[ %d ] = 0x%lx\n",
Packit 6c4009
			 i, (unsigned long int) ws1[i], i,
Packit 6c4009
			 (unsigned long int) ws_ex[i]);
Packit 6c4009
Packit 6c4009
	      if (ws1[i] != ws_ex[i])
Packit 6c4009
		{
Packit 6c4009
		  err++;
Packit 6c4009
		  err_count++;
Packit 6c4009
		  Result (C_FAILURE, S_WCSNCPY, CASE_4,
Packit 6c4009
			  "copied string is different from an "
Packit 6c4009
			  "expected string");
Packit 6c4009
		  break;
Packit 6c4009
		}
Packit 6c4009
	    }
Packit 6c4009
Packit 6c4009
	  if (!err)
Packit 6c4009
	    {
Packit 6c4009
	      Result (C_SUCCESS, S_WCSNCPY, CASE_4, MS_PASSED);
Packit 6c4009
	    }
Packit 6c4009
Packit 6c4009
	  /* A null terminate character is not supposed to be copied
Packit 6c4009
	     unless (num chars of ws2)
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
  }
Packit 6c4009
Packit 6c4009
  return err_count;
Packit 6c4009
}