tst_wcrtomb.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. WCRTOMB: wchar_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
  3. */
  4. #define TST_FUNCTION wcrtomb
  5. #include "tsp_common.c"
  6. #include "dat_wcrtomb.c"
  7. int
  8. tst_wcrtomb (FILE * fp, int debug_flg)
  9. {
  10. TST_DECL_VARS (wchar_t);
  11. wchar_t wc;
  12. char s[MBSSIZE], *s_in, *s_ex;
  13. char t_flg, t_ini;
  14. static mbstate_t t = { 0 };
  15. mbstate_t *pt;
  16. int err, i;
  17. TST_DO_TEST (wcrtomb)
  18. {
  19. TST_HEAD_LOCALE (wcrtomb, S_WCRTOMB);
  20. TST_DO_REC (wcrtomb)
  21. {
  22. TST_GET_ERRET (wcrtomb);
  23. s_in = ((TST_INPUT (wcrtomb).s_flg) == 0) ? (char *) NULL : s;
  24. wc = TST_INPUT (wcrtomb).wc;
  25. t_flg = TST_INPUT (wcrtomb).t_flg;
  26. t_ini = TST_INPUT (wcrtomb).t_init;
  27. pt = (t_flg == 0) ? NULL : &t;
  28. if (t_ini != 0)
  29. {
  30. memset (&t, 0, sizeof (t));
  31. }
  32. TST_CLEAR_ERRNO;
  33. ret = wcrtomb (s_in, wc, pt);
  34. TST_SAVE_ERRNO;
  35. if (debug_flg)
  36. {
  37. fprintf (stdout, "wcrtomb() [ %s : %d ] ret = %lu\n", locale,
  38. rec + 1, (unsigned long int) ret);
  39. fprintf (stdout, " errno = %d\n", errno_save);
  40. }
  41. TST_IF_RETURN (S_WCRTOMB)
  42. {
  43. };
  44. s_ex = TST_EXPECT (wcrtomb).s;
  45. if (s_in)
  46. {
  47. for (i = 0, err = 0; *(s_ex + i) != 0 && i < MBSSIZE; i++)
  48. {
  49. if (s_in[i] != s_ex[i])
  50. {
  51. err++;
  52. err_count++;
  53. Result (C_FAILURE, S_WCRTOMB, CASE_4,
  54. "copied string is different from an "
  55. "expected string");
  56. break;
  57. }
  58. }
  59. if (!err)
  60. {
  61. Result (C_SUCCESS, S_WCRTOMB, CASE_4, MS_PASSED);
  62. }
  63. }
  64. }
  65. }
  66. return err_count;
  67. }