tst_mbstowcs.c 1.7 KB

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