tst_mbtowc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. MBTOWC: int mbtowc (wchar_t *wc, char *s, size_t n)
  3. */
  4. #define TST_FUNCTION mbtowc
  5. #include "tsp_common.c"
  6. #include "dat_mbtowc.c"
  7. int
  8. tst_mbtowc (FILE * fp, int debug_flg)
  9. {
  10. TST_DECL_VARS (int);
  11. char w_flg, s_flg;
  12. const char *s_in;
  13. size_t n;
  14. wchar_t wc, wc_ex, *wp;
  15. TST_DO_TEST (mbtowc)
  16. {
  17. TST_HEAD_LOCALE (mbtowc, S_MBTOWC);
  18. TST_DO_REC (mbtowc)
  19. {
  20. if (mbstowcs (NULL, "", 0) != 0)
  21. {
  22. err_count++;
  23. Result (C_FAILURE, S_MBSTOWCS, CASE_3,
  24. "Initialization failed - skipping this test case.");
  25. continue;
  26. }
  27. TST_DO_SEQ (MBTOWC_SEQNUM)
  28. {
  29. TST_GET_ERRET_SEQ (mbtowc);
  30. w_flg = TST_INPUT_SEQ (mbtowc).w_flg;
  31. s_flg = TST_INPUT_SEQ (mbtowc).s_flg;
  32. n = TST_INPUT_SEQ (mbtowc).n;
  33. if (n == USE_MBCURMAX)
  34. {
  35. n = MB_CUR_MAX;
  36. }
  37. if (s_flg == 0)
  38. s_in = NULL;
  39. else
  40. s_in = TST_INPUT_SEQ (mbtowc).s;
  41. wp = (wchar_t *) ((w_flg == 0) ? NULL : &wc);
  42. /* XXX Clear the internal state. We should probably have
  43. a flag for this. */
  44. mbtowc (NULL, NULL, 0);
  45. TST_CLEAR_ERRNO;
  46. ret = mbtowc (wp, s_in, n);
  47. TST_SAVE_ERRNO;
  48. if (debug_flg)
  49. {
  50. fprintf (stdout, "mbtowc() [ %s : %d ] ret = %d\n", locale,
  51. rec + 1, ret);
  52. fprintf (stdout, " errno = %d\n",
  53. errno_save);
  54. }
  55. TST_IF_RETURN (S_MBTOWC)
  56. {
  57. if (s_in == NULL)
  58. { /* state dependency */
  59. if (ret_exp == +1)
  60. { /* state-dependent */
  61. if (ret != 0)
  62. {
  63. /* Non-zero: state-dependent encoding. */
  64. Result (C_SUCCESS, S_MBTOWC, CASE_3, MS_PASSED);
  65. }
  66. else
  67. {
  68. err_count++;
  69. Result (C_FAILURE, S_MBTOWC, CASE_3,
  70. "should be state-dependent encoding, "
  71. "but a return value shows it is "
  72. "state-independent");
  73. }
  74. }
  75. if (ret_exp == 0)
  76. { /* state-independent */
  77. if (ret == 0)
  78. {
  79. /* Non-zero: state-dependent encoding. */
  80. Result (C_SUCCESS, S_MBTOWC, CASE_3, MS_PASSED);
  81. }
  82. else
  83. {
  84. err_count++;
  85. Result (C_FAILURE, S_MBTOWC, CASE_3,
  86. "should be state-independent encoding, "
  87. "but a return value shows it is "
  88. "state-dependent");
  89. }
  90. }
  91. }
  92. }
  93. if ((wp == NULL || s_in == NULL || s_in[0] == 0) || ret <= 0)
  94. {
  95. continue;
  96. }
  97. wc_ex = TST_EXPECT_SEQ (mbtowc).wc;
  98. if (wc_ex == wc)
  99. {
  100. Result (C_SUCCESS, S_MBTOWC, CASE_4, MS_PASSED);
  101. }
  102. else
  103. {
  104. err_count++;
  105. Result (C_FAILURE, S_MBTOWC, CASE_4,
  106. "converted wc is different from an expected wc");
  107. }
  108. }
  109. }
  110. }
  111. return err_count;
  112. }