tst_mbrtowc.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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, t_ini;
  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. t_ini = TST_INPUT_SEQ (mbrtowc).t_init;
  40. pwc = (w_flg == 0) ? NULL : &wc;
  41. if (s_flg == 0)
  42. {
  43. s = NULL;
  44. }
  45. if (n == USE_MBCURMAX)
  46. {
  47. n = MB_CUR_MAX;
  48. }
  49. pt = (t_flg == 0) ? NULL : &t;
  50. #if 0
  51. if (t_ini != 0)
  52. {
  53. memset (&t, 0, sizeof (t));
  54. }
  55. #endif
  56. TST_CLEAR_ERRNO;
  57. ret = mbrtowc (pwc, s, n, pt);
  58. TST_SAVE_ERRNO;
  59. if (debug_flg)
  60. {
  61. fprintf (stdout, "mbrtowc() [ %s : %d : %d ] ret = %zd\n",
  62. locale, rec + 1, seq_num + 1, ret);
  63. fprintf (stdout, " errno = %hd\n",
  64. errno_save);
  65. }
  66. TST_IF_RETURN (S_MBRTOWC)
  67. {
  68. };
  69. if (pwc == NULL || s == NULL || ret == (size_t) - 1
  70. || ret == (size_t) - 2)
  71. {
  72. continue;
  73. }
  74. wc_ex = TST_EXPECT_SEQ (mbrtowc).wc;
  75. if (wc_ex == wc)
  76. {
  77. Result (C_SUCCESS, S_MBRTOWC, CASE_4, MS_PASSED);
  78. }
  79. else
  80. {
  81. err_count++;
  82. Result (C_FAILURE, S_MBRTOWC, CASE_4,
  83. "converted wc is different from an expected wc");
  84. }
  85. }
  86. }
  87. }
  88. return err_count;
  89. }