Back to index

glibc  2.9
tst_wcsncpy.c
Go to the documentation of this file.
00001 /*
00002   WCSNCPY: wchar_t *wcsncpy (wchar_t *ws1, const wchar_t *ws2, size_t n);
00003 */
00004 
00005 #define TST_FUNCTION wcsncpy
00006 
00007 #include "tsp_common.c"
00008 #include "dat_wcsncpy.c"
00009 
00010 #define WCSNUM_NCPY 7
00011 
00012 int
00013 tst_wcsncpy (FILE *fp, int debug_flg)
00014 {
00015   TST_DECL_VARS (wchar_t *);
00016   wchar_t ws1[WCSSIZE] =
00017     { 0x9999, 0x9999, 0x9999, 0x9999, 0x9999, 0x9999, 0x0000 };
00018   wchar_t *ws2, *ws_ex;
00019   int err, i;
00020   size_t n;
00021 
00022   TST_DO_TEST (wcsncpy)
00023   {
00024     TST_HEAD_LOCALE (wcsncpy, S_WCSNCPY);
00025     TST_DO_REC (wcsncpy)
00026     {
00027       TST_GET_ERRET (wcsncpy);
00028 
00029       for (n = 0; n < WCSNUM_NCPY - 1; ++n)
00030        {
00031          ws1[n] = 0x9999;
00032        }
00033 
00034       ws1[n] = 0;
00035       ws2 = TST_INPUT (wcsncpy).ws;       /* external value: size WCSSIZE */
00036       n = TST_INPUT (wcsncpy).n;
00037       ret = wcsncpy (ws1, ws2, n);
00038 
00039       TST_IF_RETURN (S_WCSNCPY)
00040       {
00041        if (ret == ws1)
00042          {
00043            Result (C_SUCCESS, S_WCSNCPY, CASE_3, MS_PASSED);
00044          }
00045        else
00046          {
00047            err_count++;
00048            Result (C_FAILURE, S_WCSNCPY, CASE_3,
00049                   "the return address may not be correct");
00050          }
00051       }
00052 
00053       if (ret == ws1)
00054        {
00055          if (debug_flg)
00056            {
00057              fprintf (stderr, "\nwcsncpy: n = %zu\n\n", n);
00058            }
00059 
00060          ws_ex = TST_EXPECT (wcsncpy).ws;
00061 
00062          for (err = 0, i = 0; i < WCSNUM_NCPY && i < WCSSIZE; i++)
00063            {
00064              if (debug_flg)
00065               fprintf (stderr,
00066                       "wcsncpy: ws1[ %d ] = 0x%lx <-> wx_ex[ %d ] = 0x%lx\n",
00067                       i, (unsigned long int) ws1[i], i,
00068                       (unsigned long int) ws_ex[i]);
00069 
00070              if (ws1[i] != ws_ex[i])
00071               {
00072                 err++;
00073                 err_count++;
00074                 Result (C_FAILURE, S_WCSNCPY, CASE_4,
00075                        "copied string is different from an "
00076                        "expected string");
00077                 break;
00078               }
00079            }
00080 
00081          if (!err)
00082            {
00083              Result (C_SUCCESS, S_WCSNCPY, CASE_4, MS_PASSED);
00084            }
00085 
00086          /* A null terminate character is not supposed to be copied
00087             unless (num chars of ws2)<n. */
00088        }
00089     }
00090   }
00091 
00092   return err_count;
00093 }