tst_wcsrtombs.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. WCSRTOMBS: size_t wcsrtombs (char *s, const wchar_t **ws, size_t n,
  3. mbstate_t *ps)
  4. */
  5. #define TST_FUNCTION wcsrtombs
  6. #include "tsp_common.c"
  7. #include "dat_wcsrtombs.c"
  8. #define MARK_VAL 0x01
  9. int
  10. tst_wcsrtombs (FILE * fp, int debug_flg)
  11. {
  12. TST_DECL_VARS (size_t);
  13. char s_flg, n;
  14. const wchar_t *ws, *wp;
  15. char s[MBSSIZE], *s_in;
  16. char t_flg, t_ini;
  17. static mbstate_t t = { 0 };
  18. mbstate_t *pt;
  19. int err, i;
  20. char *s_ex;
  21. TST_DO_TEST (wcsrtombs)
  22. {
  23. TST_HEAD_LOCALE (wcsrtombs, S_WCSRTOMBS);
  24. TST_DO_REC (wcsrtombs)
  25. {
  26. TST_GET_ERRET (wcsrtombs);
  27. memset (s, MARK_VAL, MBSSIZE);
  28. s_flg = TST_INPUT (wcsrtombs).s_flg;
  29. s_in = (s_flg == 1) ? s : (char *) NULL;
  30. wp = ws = TST_INPUT (wcsrtombs).ws;
  31. n = TST_INPUT (wcsrtombs).n;
  32. t_flg = TST_INPUT (wcsrtombs).t_flg;
  33. t_ini = TST_INPUT (wcsrtombs).t_init;
  34. pt = (t_flg == 0) ? NULL : &t;
  35. if (t_ini != 0)
  36. {
  37. memset (&t, 0, sizeof (t));
  38. }
  39. TST_CLEAR_ERRNO;
  40. ret = wcsrtombs (s_in, &wp, n, pt);
  41. TST_SAVE_ERRNO;
  42. if (debug_flg)
  43. {
  44. fprintf (stderr, "wcsrtombs: ret = %zu\n", ret);
  45. }
  46. TST_IF_RETURN (S_WCSRTOMBS)
  47. {
  48. };
  49. if (s_in != NULL && ret != (size_t) - 1)
  50. {
  51. /* No definition for s, when error occurs. */
  52. s_ex = TST_EXPECT (wcsrtombs).s;
  53. for (err = 0, i = 0; i <= ret && i < MBSSIZE; i++)
  54. {
  55. if (debug_flg)
  56. {
  57. fprintf (stderr,
  58. " : s[%d] = 0x%hx <-> 0x%hx = s_ex[%d]\n", i,
  59. s[i], s_ex[i], i);
  60. }
  61. if (i == ret && ret == n) /* no null termination */
  62. {
  63. if (s[i] == MARK_VAL)
  64. {
  65. Result (C_SUCCESS, S_WCSRTOMBS, CASE_4, MS_PASSED);
  66. }
  67. else
  68. {
  69. err_count++;
  70. Result (C_FAILURE, S_WCSRTOMBS, CASE_4,
  71. "should not be null terminated "
  72. "(it may be a null char), but it is");
  73. }
  74. break;
  75. }
  76. if (i == ret && ret < n) /* null termination */
  77. {
  78. if (s[i] == 0)
  79. {
  80. Result (C_SUCCESS, S_WCSRTOMBS, CASE_5, MS_PASSED);
  81. }
  82. else
  83. {
  84. err_count++;
  85. Result (C_FAILURE, S_WCSRTOMBS, CASE_5,
  86. "should be null terminated, but it is not");
  87. }
  88. break;
  89. }
  90. if (s[i] != s_ex[i])
  91. {
  92. err++;
  93. err_count++;
  94. Result (C_FAILURE, S_WCSRTOMBS, CASE_6,
  95. "converted string is different from an"
  96. " expected string");
  97. break;
  98. }
  99. }
  100. if (!err)
  101. {
  102. Result (C_SUCCESS, S_WCSRTOMBS, CASE_6, MS_PASSED);
  103. }
  104. }
  105. }
  106. }
  107. return err_count;
  108. }