tst_wcsxfrm.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. WCSXFRM: size_t wcsxfrm (wchar_t *ws1, const wchar_t *ws2, size_t n);
  3. */
  4. #define TST_FUNCTION wcsxfrm
  5. #include "tsp_common.c"
  6. #include "dat_wcsxfrm.c"
  7. int
  8. tst_wcsxfrm (FILE * fp, int debug_flg)
  9. {
  10. TST_DECL_VARS (size_t);
  11. wchar_t *org1, *org2;
  12. wchar_t frm1[MBSSIZE], frm2[MBSSIZE];
  13. size_t n1, n2;
  14. int ret_coll, ret_cmp;
  15. TST_DO_TEST (wcsxfrm)
  16. {
  17. TST_HEAD_LOCALE (wcsxfrm, S_WCSXFRM);
  18. TST_DO_REC (wcsxfrm)
  19. {
  20. TST_GET_ERRET (wcsxfrm);
  21. org1 = TST_INPUT (wcsxfrm).org1;
  22. org2 = TST_INPUT (wcsxfrm).org2;
  23. n1 = TST_INPUT (wcsxfrm).n1;
  24. n2 = TST_INPUT (wcsxfrm).n2;
  25. if (n1 < 0 || sizeof (frm1) < n1 || sizeof (frm2) < n2)
  26. {
  27. warn_count++;
  28. Result (C_IGNORED, S_WCSXFRM, CASE_9,
  29. "input data n1 or n2 is invalid");
  30. continue;
  31. }
  32. /* an errno and a return value are checked
  33. only for 2nd wcsxfrm() call.
  34. A result of 1st call is used to compare
  35. those 2 values by using wcscmp().
  36. */
  37. TST_CLEAR_ERRNO;
  38. ret = wcsxfrm (frm1, org1, n1); /* First call */
  39. TST_SAVE_ERRNO;
  40. if (debug_flg)
  41. {
  42. fprintf (stdout, "tst_wcsxfrm() : REC = %d\n", rec + 1);
  43. fprintf (stdout, "tst_wcsxfrm() : 1st ret = %zu\n", ret);
  44. }
  45. if (ret == -1 || ret >= n1 || errno_save != 0)
  46. {
  47. warn_count++;
  48. Result (C_INVALID, S_WCSXFRM, CASE_8,
  49. "got an error in fist wcsxfrm() call");
  50. continue;
  51. }
  52. TST_CLEAR_ERRNO;
  53. /* Second call */
  54. ret = wcsxfrm (((n2 == 0) ? NULL : frm2), org2, n2);
  55. TST_SAVE_ERRNO;
  56. TST_IF_RETURN (S_WCSXFRM)
  57. {
  58. };
  59. if (n2 == 0 || ret >= n2 || errno != 0)
  60. {
  61. #if 0
  62. warn_count++;
  63. Result (C_IGNORED, S_WCSXFRM, CASE_7, "did not get a result");
  64. #endif
  65. continue;
  66. }
  67. if (debug_flg)
  68. {
  69. fprintf (stdout, "tst_wcsxfrm() : 2nd ret = %zu\n", ret);
  70. }
  71. /* wcscoll() */
  72. TST_CLEAR_ERRNO;
  73. /* depends on wcscoll() ... not good though ... */
  74. ret_coll = wcscoll (org1, org2);
  75. TST_SAVE_ERRNO;
  76. if (errno != 0) /* bugs * bugs may got correct results ... */
  77. {
  78. warn_count++;
  79. Result (C_INVALID, S_WCSXFRM, CASE_6,
  80. "got an error in wcscoll() call");
  81. continue;
  82. }
  83. /* wcscmp() */
  84. ret_cmp = wcscmp (frm1, frm2);
  85. if ((ret_coll == ret_cmp) || (ret_coll > 0 && ret_cmp > 0)
  86. || (ret_coll < 0 && ret_cmp < 0))
  87. {
  88. Result (C_SUCCESS, S_WCSXFRM, CASE_3,
  89. MS_PASSED " (depends on wcscoll & wcscmp)");
  90. }
  91. else
  92. {
  93. err_count++;
  94. Result (C_FAILURE, S_WCSXFRM, CASE_3,
  95. "results from wcscoll & wcscmp() do not match");
  96. }
  97. if (debug_flg)
  98. {
  99. fprintf (stdout, "tst_wcsxfrm() : coll = %d <-> %d = cmp\n",
  100. ret_coll, ret_cmp);
  101. }
  102. }
  103. }
  104. return err_count;
  105. }