tst_strxfrm.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. STRXFRM: size_t strxfrm (char *s1, const char *s2, size_t n)
  3. */
  4. #define TST_FUNCTION strxfrm
  5. #include "tsp_common.c"
  6. #include "dat_strxfrm.c"
  7. int
  8. tst_strxfrm (FILE * fp, int debug_flg)
  9. {
  10. TST_DECL_VARS (size_t);
  11. const char *org1, *org2;
  12. char frm1[MBSSIZE], frm2[MBSSIZE];
  13. size_t n1, n2;
  14. int ret_coll, ret_cmp;
  15. TST_DO_TEST (strxfrm)
  16. {
  17. TST_HEAD_LOCALE (strxfrm, S_STRXFRM);
  18. TST_DO_REC (strxfrm)
  19. {
  20. TST_GET_ERRET (strxfrm);
  21. org1 = TST_INPUT (strxfrm).org1;
  22. org2 = TST_INPUT (strxfrm).org2;
  23. n1 = TST_INPUT (strxfrm).n1;
  24. n2 = TST_INPUT (strxfrm).n2;
  25. if (n1 < 0 || sizeof (frm1) < n1 || sizeof (frm2) < n2)
  26. {
  27. warn_count++;
  28. Result (C_IGNORED, S_STRXFRM, 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 strxfrm() call.
  34. A result of 1st call is used for comparing
  35. those 2 values by using strcmp().
  36. */
  37. /*-- First call --*/
  38. TST_CLEAR_ERRNO;
  39. ret = strxfrm (frm1, org1, n1);
  40. TST_SAVE_ERRNO;
  41. if (debug_flg)
  42. {
  43. fprintf (stdout, "strxfrm() [ %s : %d ] ( 1st call )\n", locale,
  44. rec + 1);
  45. fprintf (stdout, " : err = %d | %s\n", errno_save,
  46. strerror (errno));
  47. fprintf (stdout, " : ret = %zu\n", ret);
  48. fprintf (stdout, " : org = %s\n", org1);
  49. }
  50. if (ret >= n1 || errno != 0)
  51. {
  52. warn_count++;
  53. Result (C_INVALID, S_STRXFRM, CASE_8,
  54. "got an error in fist strxfrm() call");
  55. continue;
  56. }
  57. /*-- Second call --*/
  58. TST_CLEAR_ERRNO;
  59. ret = strxfrm (((n2 == 0) ? NULL : frm2), org2, n2);
  60. TST_SAVE_ERRNO;
  61. if (debug_flg)
  62. {
  63. fprintf (stderr, " ..............( 2nd call )\n");
  64. fprintf (stdout, " : err = %d | %s\n", errno,
  65. strerror (errno));
  66. fprintf (stdout, " : ret = %zu\n", ret);
  67. fprintf (stdout, " : org = %s\n", org2);
  68. }
  69. TST_IF_RETURN (S_STRXFRM)
  70. {
  71. };
  72. if (n2 == 0 || ret >= n2 || errno != 0)
  73. {
  74. #if 0
  75. warn_count++;
  76. Result (C_IGNORED, S_STRXFRM, CASE_7, "did not get a result");
  77. #endif
  78. continue;
  79. }
  80. /*-- strcoll & strcmp --*/
  81. TST_CLEAR_ERRNO;
  82. /* Depends on strcoll() ... not good though ... */
  83. ret_coll = strcoll (org1, org2);
  84. if (errno != 0)
  85. {
  86. /* bug * bug may get correct results ... */
  87. warn_count++;
  88. Result (C_INVALID, S_STRXFRM, CASE_6,
  89. "got an error in strcoll() call");
  90. continue;
  91. }
  92. ret_cmp = strcmp (frm1, frm2);
  93. if ((ret_coll == 0 && ret_cmp == 0)
  94. || (ret_coll < 0 && ret_cmp < 0) || (ret_coll > 0 && ret_cmp > 0))
  95. {
  96. Result (C_SUCCESS, S_STRXFRM, CASE_3,
  97. MS_PASSED "(depends on strcoll & strcmp)");
  98. }
  99. else
  100. {
  101. err_count++;
  102. Result (C_FAILURE, S_STRXFRM, CASE_3,
  103. "results from strcoll & strcmp() do not match");
  104. }
  105. if (debug_flg)
  106. {
  107. fprintf (stdout, ".......... strcoll = %d <-> %d = strcmp\n",
  108. ret_coll, ret_cmp);
  109. }
  110. }
  111. }
  112. return err_count;
  113. }