tst_swscanf.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. SWSCANF: int swscanf (const wchar_t *ws, const wchar_t *fmt, ...);
  3. */
  4. #define TST_FUNCTION swscanf
  5. #include "tsp_common.c"
  6. #include "dat_swscanf.c"
  7. int
  8. tst_swscanf (FILE * fp, int debug_flg)
  9. {
  10. TST_DECL_VARS (int);
  11. wchar_t *ws;
  12. wchar_t *fmt;
  13. int val_int1;
  14. unsigned val_int2;
  15. float val_flt;
  16. char val_c;
  17. char val_s[MBSSIZE * 3];
  18. wchar_t val_S[WCSSIZE * 3], *exp_S;
  19. int i;
  20. TST_DO_TEST (swscanf)
  21. {
  22. TST_HEAD_LOCALE (swscanf, S_SWSCANF);
  23. TST_DO_REC (swscanf)
  24. {
  25. TST_GET_ERRET (swscanf);
  26. ws = TST_INPUT (swscanf).ws;
  27. fmt = TST_INPUT (swscanf).fmt;
  28. val_int1 = val_int2 = val_flt = val_c = 0;
  29. memset (val_s, 0, sizeof (val_s));
  30. memset (val_S, 0, sizeof (val_S));
  31. TST_CLEAR_ERRNO;
  32. if (TST_INPUT (swscanf).wch)
  33. {
  34. ret = swscanf (ws, fmt, val_S);
  35. }
  36. else
  37. {
  38. ret =
  39. swscanf (ws, fmt, &val_int1, &val_int2, &val_flt, &val_c, val_s);
  40. }
  41. TST_SAVE_ERRNO;
  42. if (debug_flg)
  43. { /* seems fprintf doesn't update errno */
  44. fprintf (stdout, "swscanf() [ %s : %d ] ret = %d\n", locale,
  45. rec + 1, ret);
  46. fprintf (stdout, " errno = %d\n",
  47. errno_save);
  48. fprintf (stdout, " collate = %s\n",
  49. (setlocale (LC_COLLATE, NULL)) ? setlocale (LC_COLLATE,
  50. NULL) : "");
  51. if (TST_INPUT (swscanf).wch)
  52. {
  53. fprintf (stdout, " val_S[ 0 ] = 0x%lx\n",
  54. (unsigned long int) val_S[0]);
  55. }
  56. else
  57. {
  58. fprintf (stdout, " val_int1 = %d\n",
  59. val_int1);
  60. fprintf (stdout, " val_int2 = %d\n",
  61. val_int2);
  62. fprintf (stdout, " val_flt = %f\n",
  63. val_flt);
  64. fprintf (stdout, " val_c = %c\n",
  65. val_c);
  66. fprintf (stdout, " val_s = %s\n",
  67. val_s);
  68. }
  69. }
  70. TST_IF_RETURN (S_SWSCANF)
  71. {
  72. };
  73. if (errno == 0 && TST_INPUT (swscanf).wch)
  74. {
  75. for (exp_S = TST_EXPECT (swscanf).val_S, i = 0; i < WCSSIZE * 3;
  76. i++)
  77. {
  78. if (val_S[i] == L'\0' || exp_S[i] == L'\0')
  79. {
  80. if (val_S[i] != exp_S[i] && TST_INPUT (swscanf).wch == 'C')
  81. {
  82. err_count++;
  83. Result (C_FAILURE, S_SWSCANF, CASE_4,
  84. "the converted wide-char string is different"
  85. " from an expected value.");
  86. }
  87. break;
  88. }
  89. if (val_S[i] != exp_S[i])
  90. {
  91. err_count++;
  92. Result (C_FAILURE, S_SWSCANF, CASE_4,
  93. "the converted wide-char string is different from"
  94. " an expected value.");
  95. break;
  96. }
  97. else
  98. {
  99. Result (C_SUCCESS, S_SWSCANF, CASE_4, MS_PASSED);
  100. }
  101. }
  102. }
  103. if (errno == 0 && !TST_INPUT (swscanf).wch)
  104. {
  105. if (val_int1 != TST_EXPECT (swscanf).val_int ||
  106. val_int2 != TST_EXPECT (swscanf).val_uns ||
  107. val_flt != TST_EXPECT (swscanf).val_flt ||
  108. val_c != TST_EXPECT (swscanf).val_c ||
  109. strcmp (val_s, TST_EXPECT (swscanf).val_s))
  110. {
  111. err_count++;
  112. Result (C_FAILURE, S_SWSCANF, CASE_3,
  113. "the converted values are different from expected values.");
  114. }
  115. else
  116. {
  117. Result (C_SUCCESS, S_SWSCANF, CASE_3, MS_PASSED);
  118. }
  119. }
  120. }
  121. }
  122. return err_count;
  123. }