tst_mbrtowc.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. MBRTOWC: size_t mbrtowc (wchar_t *pwc, const char *s, size_t n,
  3. mbstate_t *ps)
  4. */
  5. #define TST_FUNCTION mbrtowc
  6. #include "tsp_common.c"
  7. #include "dat_mbrtowc.c"
  8. int
  9. tst_mbrtowc (FILE * fp, int debug_flg)
  10. {
  11. TST_DECL_VARS (size_t);
  12. char w_flg, s_flg;
  13. char *s;
  14. size_t n;
  15. char t_flg;
  16. static mbstate_t t = { 0 };
  17. mbstate_t *pt;
  18. wchar_t wc, *pwc, wc_ex;
  19. TST_DO_TEST (mbrtowc)
  20. {
  21. TST_HEAD_LOCALE (mbrtowc, S_MBRTOWC);
  22. TST_DO_REC (mbrtowc)
  23. {
  24. if (mbrtowc (NULL, "", 0, &t) != 0)
  25. {
  26. err_count++;
  27. Result (C_FAILURE, S_MBRTOWC, CASE_3,
  28. "Initialization failed - skipping this test case.");
  29. continue;
  30. }
  31. TST_DO_SEQ (MBRTOWC_SEQNUM)
  32. {
  33. TST_GET_ERRET_SEQ (mbrtowc);
  34. w_flg = TST_INPUT_SEQ (mbrtowc).w_flg;
  35. s_flg = TST_INPUT_SEQ (mbrtowc).s_flg;
  36. s = TST_INPUT_SEQ (mbrtowc).s;
  37. n = TST_INPUT_SEQ (mbrtowc).n;
  38. t_flg = TST_INPUT_SEQ (mbrtowc).t_flg;
  39. pwc = (w_flg == 0) ? NULL : &wc;
  40. if (s_flg == 0)
  41. {
  42. s = NULL;
  43. }
  44. if (n == USE_MBCURMAX)
  45. {
  46. n = MB_CUR_MAX;
  47. }
  48. pt = (t_flg == 0) ? NULL : &t;
  49. TST_CLEAR_ERRNO;
  50. ret = mbrtowc (pwc, s, n, pt);
  51. TST_SAVE_ERRNO;
  52. if (debug_flg)
  53. {
  54. fprintf (stdout, "mbrtowc() [ %s : %d : %d ] ret = %zd\n",
  55. locale, rec + 1, seq_num + 1, ret);
  56. fprintf (stdout, " errno = %hd\n",
  57. errno_save);
  58. }
  59. TST_IF_RETURN (S_MBRTOWC)
  60. {
  61. };
  62. if (pwc == NULL || s == NULL || ret == (size_t) - 1
  63. || ret == (size_t) - 2)
  64. {
  65. continue;
  66. }
  67. wc_ex = TST_EXPECT_SEQ (mbrtowc).wc;
  68. if (wc_ex == wc)
  69. {
  70. Result (C_SUCCESS, S_MBRTOWC, CASE_4, MS_PASSED);
  71. }
  72. else
  73. {
  74. err_count++;
  75. Result (C_FAILURE, S_MBRTOWC, CASE_4,
  76. "converted wc is different from an expected wc");
  77. }
  78. }
  79. }
  80. }
  81. return err_count;
  82. }