tst_wcstombs.c 2.2 KB

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