tst_mbsrtowcs.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. MBSRTOWCS: size_t mbsrtowcs (wchar_t *ws, const char **s, size_t n,
  3. mbstate_t *ps)
  4. */
  5. #define TST_FUNCTION mbsrtowcs
  6. #include "tsp_common.c"
  7. #include "dat_mbsrtowcs.c"
  8. int
  9. tst_mbsrtowcs (FILE * fp, int debug_flg)
  10. {
  11. TST_DECL_VARS (size_t);
  12. char w_flg;
  13. const char *s, *p;
  14. size_t n;
  15. char t_flg, t_ini;
  16. static mbstate_t t = { 0 };
  17. mbstate_t *pt;
  18. wchar_t ws[WCSSIZE], *ws_ex, *wp;
  19. int err, i;
  20. TST_DO_TEST (mbsrtowcs)
  21. {
  22. TST_HEAD_LOCALE (mbsrtowcs, S_MBSRTOWCS);
  23. TST_DO_REC (mbsrtowcs)
  24. {
  25. s = "";
  26. if (mbsrtowcs (NULL, &s, 0, &t) != 0)
  27. {
  28. err_count++;
  29. Result (C_FAILURE, S_MBSRTOWCS, CASE_3,
  30. "Initialization failed - skipping this test case.");
  31. continue;
  32. }
  33. TST_DO_SEQ (MBSRTOWCS_SEQNUM)
  34. {
  35. TST_GET_ERRET_SEQ (mbsrtowcs);
  36. w_flg = TST_INPUT_SEQ (mbsrtowcs).w_flg;
  37. p = s = TST_INPUT_SEQ (mbsrtowcs).s;
  38. n = TST_INPUT_SEQ (mbsrtowcs).n;
  39. t_flg = TST_INPUT_SEQ (mbsrtowcs).t_flg;
  40. t_ini = TST_INPUT_SEQ (mbsrtowcs).t_init;
  41. wp = (w_flg == 0) ? NULL : ws;
  42. if (n == USE_MBCURMAX)
  43. {
  44. n = MB_CUR_MAX;
  45. }
  46. pt = (t_flg == 0) ? NULL : &t;
  47. if (t_ini != 0)
  48. {
  49. memset (&t, 0, sizeof (t));
  50. }
  51. TST_CLEAR_ERRNO;
  52. ret = mbsrtowcs (wp, &p, n, pt);
  53. TST_SAVE_ERRNO;
  54. if (debug_flg)
  55. {
  56. fprintf (stderr, "mbsrtowcs: [ %d ] : ret = %zd\n", rec + 1, ret);
  57. }
  58. TST_IF_RETURN (S_MBSRTOWCS)
  59. {
  60. };
  61. if (wp == NULL || ret == (size_t) - 1 || ret == (size_t) - 2)
  62. {
  63. continue;
  64. }
  65. ws_ex = TST_EXPECT_SEQ (mbsrtowcs).ws;
  66. for (err = 0, i = 0; i < ret; i++)
  67. {
  68. if (debug_flg)
  69. {
  70. fprintf (stderr,
  71. "mbsrtowcs: ws[%d] => 0x%lx : 0x%lx <= ws_ex[%d]\n",
  72. i, (unsigned long int) ws[i],
  73. (unsigned long int) ws_ex[i], i);
  74. }
  75. if (ws[i] != ws_ex[i])
  76. {
  77. err++;
  78. err_count++;
  79. Result (C_FAILURE, S_MBSRTOWCS, CASE_4,
  80. "the converted wc string has "
  81. "different value from an expected string");
  82. break;
  83. }
  84. }
  85. if (!err)
  86. {
  87. Result (C_SUCCESS, S_MBSRTOWCS, CASE_4, MS_PASSED);
  88. }
  89. }
  90. }
  91. }
  92. return err_count;
  93. }