tst_wctomb.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. WCTOMB: int wctomb (char *s, wchar_t wc)
  3. */
  4. #define TST_FUNCTION wctomb
  5. #include "tsp_common.c"
  6. #include "dat_wctomb.c"
  7. int
  8. tst_wctomb (FILE * fp, int debug_flg)
  9. {
  10. TST_DECL_VARS (int);
  11. wchar_t wc;
  12. char s[MBSSIZE], *s_in, *s_ex;
  13. int err, i;
  14. TST_DO_TEST (wctomb)
  15. {
  16. TST_HEAD_LOCALE (wctomb, S_WCTOMB);
  17. TST_DO_REC (wctomb)
  18. {
  19. TST_GET_ERRET (wctomb);
  20. wc = TST_INPUT (wctomb).wc;
  21. s_in = ((TST_INPUT (wctomb).s_flg) == 0) ? (char *) NULL : s;
  22. ret = wctomb (s_in, wc);
  23. if (debug_flg)
  24. {
  25. fprintf (stdout, "wctomb() [ %s : %d ] ret = %d\n", locale,
  26. rec + 1, ret);
  27. }
  28. TST_IF_RETURN (S_WCTOMB)
  29. {
  30. if (s_in == NULL) /* state dependency */
  31. {
  32. if (ret_exp == +1) /* state-dependent */
  33. {
  34. if (ret != 0)
  35. {
  36. /* Non-zero means state-dependent encoding. */
  37. Result (C_SUCCESS, S_WCTOMB, CASE_3, MS_PASSED);
  38. }
  39. else
  40. {
  41. err_count++;
  42. Result (C_FAILURE, S_WCTOMB, CASE_3,
  43. "should be state-dependent encoding, "
  44. "but a return value shows it is "
  45. "state-independent");
  46. }
  47. }
  48. if (ret_exp == 0) /* state-independent */
  49. {
  50. if (ret == 0)
  51. {
  52. /* Non-zero means state-dependent encoding. */
  53. Result (C_SUCCESS, S_WCTOMB, CASE_3, MS_PASSED);
  54. }
  55. else
  56. {
  57. err_count++;
  58. Result (C_FAILURE, S_WCTOMB, CASE_3,
  59. "should be state-independent encoding, "
  60. "but a return value shows it is state-dependent");
  61. }
  62. }
  63. }
  64. }
  65. s_ex = TST_EXPECT (wctomb).s;
  66. if (s_in)
  67. {
  68. for (i = 0, err = 0; *(s_ex + i) != 0 && i < MBSSIZE; i++)
  69. {
  70. if (s_in[i] != s_ex[i])
  71. {
  72. err++;
  73. err_count++;
  74. Result (C_FAILURE, S_WCTOMB, CASE_4,
  75. "copied string is different from an"
  76. " expected string");
  77. break;
  78. }
  79. }
  80. if (!err)
  81. {
  82. Result (C_SUCCESS, S_WCTOMB, CASE_4, MS_PASSED);
  83. }
  84. }
  85. }
  86. }
  87. return err_count;
  88. }