tst_mblen.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. MBLEN: int mblen (char *s, size_t n)
  3. */
  4. #define TST_FUNCTION mblen
  5. #include "tsp_common.c"
  6. #include "dat_mblen.c"
  7. int
  8. tst_mblen (FILE * fp, int debug_flg)
  9. {
  10. TST_DECL_VARS (int);
  11. char s_flg;
  12. const char *s_in;
  13. size_t n;
  14. TST_DO_TEST (mblen)
  15. {
  16. TST_HEAD_LOCALE (mblen, S_MBLEN);
  17. TST_DO_REC (mblen)
  18. {
  19. TST_GET_ERRET (mblen);
  20. s_flg = TST_INPUT (mblen).s_flg;
  21. s_in = TST_INPUT (mblen).s;
  22. n = TST_INPUT (mblen).n;
  23. if (s_flg == 0)
  24. {
  25. s_in = NULL;
  26. }
  27. if (n == USE_MBCURMAX)
  28. {
  29. n = MB_CUR_MAX;
  30. }
  31. TST_CLEAR_ERRNO;
  32. ret = mblen (s_in, n);
  33. TST_SAVE_ERRNO;
  34. TST_IF_RETURN (S_MBLEN)
  35. {
  36. if (s_in == NULL)
  37. { /* state dependency */
  38. if (ret_exp == +1)
  39. { /* state-dependent */
  40. if (ret != 0)
  41. {
  42. /* non-zero: state-dependent encoding */
  43. Result (C_SUCCESS, S_MBLEN, CASE_3, MS_PASSED);
  44. }
  45. else
  46. {
  47. err_count++;
  48. Result (C_FAILURE, S_MBLEN, CASE_3,
  49. "should be state-dependent encoding, "
  50. "but the return value shows it is"
  51. " state-independent");
  52. }
  53. }
  54. if (ret_exp == 0)
  55. { /* state-independent */
  56. if (ret == 0)
  57. {
  58. /* non-zero: state-dependent encoding */
  59. Result (C_SUCCESS, S_MBLEN, CASE_3, MS_PASSED);
  60. }
  61. else
  62. {
  63. err_count++;
  64. Result (C_FAILURE, S_MBLEN, CASE_3,
  65. "should be state-independent encoding, "
  66. "but the return value shows it is"
  67. " state-dependent");
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. return err_count;
  75. }