tst_wcsncpy.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. WCSNCPY: wchar_t *wcsncpy (wchar_t *ws1, const wchar_t *ws2, size_t n);
  3. */
  4. #define TST_FUNCTION wcsncpy
  5. #include "tsp_common.c"
  6. #include "dat_wcsncpy.c"
  7. #define WCSNUM_NCPY 7
  8. int
  9. tst_wcsncpy (FILE *fp, int debug_flg)
  10. {
  11. TST_DECL_VARS (wchar_t *);
  12. wchar_t ws1[WCSSIZE] =
  13. { 0x9999, 0x9999, 0x9999, 0x9999, 0x9999, 0x9999, 0x0000 };
  14. wchar_t *ws2, *ws_ex;
  15. int err, i;
  16. size_t n;
  17. TST_DO_TEST (wcsncpy)
  18. {
  19. TST_HEAD_LOCALE (wcsncpy, S_WCSNCPY);
  20. TST_DO_REC (wcsncpy)
  21. {
  22. TST_GET_ERRET (wcsncpy);
  23. for (n = 0; n < WCSNUM_NCPY - 1; ++n)
  24. {
  25. ws1[n] = 0x9999;
  26. }
  27. ws1[n] = 0;
  28. ws2 = TST_INPUT (wcsncpy).ws; /* external value: size WCSSIZE */
  29. n = TST_INPUT (wcsncpy).n;
  30. ret = wcsncpy (ws1, ws2, n);
  31. TST_IF_RETURN (S_WCSNCPY)
  32. {
  33. if (ret == ws1)
  34. {
  35. Result (C_SUCCESS, S_WCSNCPY, CASE_3, MS_PASSED);
  36. }
  37. else
  38. {
  39. err_count++;
  40. Result (C_FAILURE, S_WCSNCPY, CASE_3,
  41. "the return address may not be correct");
  42. }
  43. }
  44. if (ret == ws1)
  45. {
  46. if (debug_flg)
  47. {
  48. fprintf (stderr, "\nwcsncpy: n = %zu\n\n", n);
  49. }
  50. ws_ex = TST_EXPECT (wcsncpy).ws;
  51. for (err = 0, i = 0; i < WCSNUM_NCPY && i < WCSSIZE; i++)
  52. {
  53. if (debug_flg)
  54. fprintf (stderr,
  55. "wcsncpy: ws1[ %d ] = 0x%lx <-> wx_ex[ %d ] = 0x%lx\n",
  56. i, (unsigned long int) ws1[i], i,
  57. (unsigned long int) ws_ex[i]);
  58. if (ws1[i] != ws_ex[i])
  59. {
  60. err++;
  61. err_count++;
  62. Result (C_FAILURE, S_WCSNCPY, CASE_4,
  63. "copied string is different from an "
  64. "expected string");
  65. break;
  66. }
  67. }
  68. if (!err)
  69. {
  70. Result (C_SUCCESS, S_WCSNCPY, CASE_4, MS_PASSED);
  71. }
  72. /* A null terminate character is not supposed to be copied
  73. unless (num chars of ws2)<n. */
  74. }
  75. }
  76. }
  77. return err_count;
  78. }