tst_funcs.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * TEST SUITE FOR MB/WC FUNCTIONS IN C LIBRARY
  3. *
  4. * FILE: tst_funcs.h
  5. *
  6. * Definitions of macros
  7. */
  8. #ifndef TST_FUNCS_H
  9. #define TST_FUNCS_H
  10. #define C_SUCCESS 'S' /* test case test passed */
  11. #define C_FAILURE 'F' /* test case failed */
  12. #define C_IGNORED 'I' /* test case/result ignored (not tested) */
  13. #define C_INVALID 'D' /* test data may be wrong */
  14. #define C_LOCALES 'L' /* can't set locale (skip) */
  15. extern int result (FILE * fp, char res, const char *func, const char *loc,
  16. int rec_no, int seq_num, int case_no, const char *msg);
  17. #define Result(C, S, E, M) \
  18. result (fp, (C), (S), locale, rec+1, seq_num+1, (E), (M))
  19. #define CASE_0 0
  20. #define CASE_1 1
  21. #define CASE_2 2
  22. #define CASE_3 3
  23. #define CASE_4 4
  24. #define CASE_5 5
  25. #define CASE_6 6
  26. #define CASE_7 7
  27. #define CASE_8 8
  28. #define CASE_9 9
  29. #define MS_PASSED "PASSED"
  30. #define MS_SPACE " "
  31. #define MS_FAILED " "
  32. #define MS_NOTEST "NOTEST"
  33. #define MS_ABORTU "ABEND0"
  34. #define MS_ABORT "ABEND1"
  35. #define MK_PASSED 0x00
  36. #define MK_SPACE 0x01
  37. #define MK_NOTEST 0x02
  38. #define MK_ABORTU 0x04
  39. #define MK_ABORT 0x08
  40. /* ------------------ COMMON MACROS ------------------ */
  41. #define TST_ABS(x) (((x) > 0) ? (x) : -(x))
  42. #define TMD_ERRET(_type_) int err_val; \
  43. int ret_flg; \
  44. _type_ ret_val
  45. #define TMD_RECHEAD(_FUNC_) \
  46. \
  47. typedef struct { \
  48. TIN_##_FUNC_##_REC input; \
  49. TEX_##_FUNC_##_REC expect; \
  50. int is_last; \
  51. } TST_##_FUNC_##_REC; \
  52. typedef struct { \
  53. TST_HEAD hd; \
  54. TST_##_FUNC_##_REC rec[ MAX_LOC_TEST ]; \
  55. } TST_##_FUNC_
  56. #define TST_FTYP(func) tst_##func##_loc
  57. #define TST_HEAD(func) tst_##func##_loc[ loc ].hd
  58. #define TST_INPUT(func) tst_##func##_loc[ loc ].rec[ rec ].input
  59. #define TST_EXPECT(func) tst_##func##_loc[ loc ].rec[ rec ].expect
  60. #define TST_INPUT_SEQ(func) \
  61. tst_##func##_loc[ loc ].rec[ rec ].input.seq[ seq_num ]
  62. #define TST_EXPECT_SEQ(func) \
  63. tst_##func##_loc[ loc ].rec[ rec ].expect.seq[ seq_num ]
  64. #define TST_IS_LAST(func) \
  65. tst_##func##_loc[ loc ].rec[ rec ].is_last
  66. #define TST_DECL_VARS(_type_) \
  67. int loc, rec, err_count = 0; \
  68. int warn_count __attribute__ ((unused)); \
  69. int func_id, seq_num = 0; \
  70. const char *locale; \
  71. int err_exp, ret_flg; \
  72. int errno_save = 0; \
  73. _type_ ret_exp; \
  74. _type_ ret
  75. #define TST_DO_TEST(o_func) \
  76. for (loc = 0; strcmp (TST_HEAD (o_func).locale, TST_LOC_end); ++loc)
  77. #define TST_HEAD_LOCALE(ofunc, s_func) \
  78. func_id = TST_HEAD (ofunc).func_id; \
  79. locale = TST_HEAD (ofunc).locale; \
  80. if (setlocale (LC_ALL, locale) == NULL) \
  81. { \
  82. fprintf (stderr, "Warning : can't set locale: %s\nskipping ...\n", \
  83. locale); \
  84. result (fp, C_LOCALES, s_func, locale, 0, 0, 0, "can't set locale"); \
  85. ++err_count; \
  86. continue; \
  87. }
  88. #define TST_DO_REC(ofunc) \
  89. for (rec=0; !TST_IS_LAST (ofunc); ++rec)
  90. #define TST_DO_SEQ(_count_) \
  91. for (seq_num=0; seq_num < _count_; seq_num++)
  92. #define TST_GET_ERRET(_ofunc_) \
  93. err_exp = TST_EXPECT (_ofunc_).err_val; \
  94. ret_flg = TST_EXPECT (_ofunc_).ret_flg; \
  95. ret_exp = TST_EXPECT (_ofunc_).ret_val
  96. #define TST_GET_ERRET_SEQ(_ofunc_) \
  97. err_exp = TST_EXPECT_SEQ (_ofunc_).err_val; \
  98. ret_flg = TST_EXPECT_SEQ (_ofunc_).ret_flg; \
  99. ret_exp = TST_EXPECT_SEQ (_ofunc_).ret_val
  100. #define TST_CLEAR_ERRNO \
  101. errno = 0
  102. #define TST_SAVE_ERRNO \
  103. errno_save = errno
  104. /* Test value of ret and of errno if it should have a value. */
  105. #define TST_IF_RETURN(_s_func_) \
  106. if (err_exp != 0) \
  107. { \
  108. if (errno_save == err_exp) \
  109. { \
  110. result (fp, C_SUCCESS, _s_func_, locale, rec+1, seq_num+1, 1, \
  111. MS_PASSED); \
  112. } \
  113. else \
  114. { \
  115. err_count++; \
  116. result (fp, C_FAILURE, _s_func_, locale, rec+1, seq_num+1, 1, \
  117. "the value of errno is different from an expected value"); \
  118. } \
  119. } \
  120. \
  121. if (ret_flg == 1) \
  122. { \
  123. if (ret == ret_exp) \
  124. { \
  125. result (fp, C_SUCCESS, _s_func_, locale, rec+1, seq_num+1, 2, \
  126. MS_PASSED); \
  127. } \
  128. else \
  129. { \
  130. err_count++; \
  131. result (fp, C_FAILURE, _s_func_, locale, rec+1, seq_num+1, 2, \
  132. "the return value is different from an expected value"); \
  133. } \
  134. } \
  135. else
  136. #define TEX_ERRET_REC(_type_) \
  137. struct { \
  138. TMD_ERRET (_type_); \
  139. }
  140. #define TEX_ERRET_REC_SEQ(_type_, _count_) \
  141. struct { \
  142. struct { \
  143. TMD_ERRET (_type_); \
  144. } seq[ _count_ ]; \
  145. }
  146. /* ------------------ FUNCTION: ISW*() ------------------- */
  147. #define TST_ISW_STRUCT(_FUNC_, _func_) \
  148. typedef \
  149. struct { \
  150. wint_t wc; \
  151. } TIN_ISW##_FUNC_##_REC; \
  152. typedef \
  153. TEX_ERRET_REC (int) TEX_ISW##_FUNC_##_REC; \
  154. TMD_RECHEAD (ISW##_FUNC_)
  155. #define TST_FUNC_ISW(_FUNC_, _func_) \
  156. int \
  157. tst_isw##_func_ (FILE *fp, int debug_flg) \
  158. { \
  159. TST_DECL_VARS(int); \
  160. wint_t wc; \
  161. TST_DO_TEST (isw##_func_) \
  162. { \
  163. TST_HEAD_LOCALE (isw##_func_, S_ISW##_FUNC_); \
  164. TST_DO_REC(isw##_func_) \
  165. { \
  166. TST_GET_ERRET (isw##_func_); \
  167. wc = TST_INPUT (isw##_func_).wc; \
  168. ret = isw##_func_ (wc); \
  169. if (debug_flg) \
  170. { \
  171. fprintf (stdout, "isw*() [ %s : %d ] ret = %d\n", locale, \
  172. rec+1, ret); \
  173. } \
  174. \
  175. TST_IF_RETURN (S_ISW##_FUNC_) \
  176. { \
  177. if (ret != 0) \
  178. { \
  179. result (fp, C_SUCCESS, S_ISW##_FUNC_, locale, rec+1, \
  180. seq_num+1, 3, MS_PASSED); \
  181. } \
  182. else \
  183. { \
  184. err_count++; \
  185. result (fp, C_FAILURE, S_ISW##_FUNC_, locale, rec+1, \
  186. seq_num+1, 3, \
  187. "the function returned 0, but should be non-zero"); \
  188. } \
  189. } \
  190. } \
  191. } \
  192. \
  193. return err_count; \
  194. }
  195. /* ------------------ FUNCTION: TOW*() ------------------ */
  196. #define TST_TOW_STRUCT(_FUNC_, _func_) \
  197. typedef \
  198. struct { \
  199. wint_t wc; \
  200. } TIN_TOW##_FUNC_##_REC; \
  201. typedef \
  202. TEX_ERRET_REC (wint_t) TEX_TOW##_FUNC_##_REC; \
  203. TMD_RECHEAD (TOW##_FUNC_)
  204. #define TST_FUNC_TOW(_FUNC_, _func_) \
  205. int \
  206. tst_tow##_func_ (FILE *fp, int debug_flg) \
  207. { \
  208. TST_DECL_VARS (wint_t); \
  209. wint_t wc; \
  210. TST_DO_TEST (tow##_func_) \
  211. { \
  212. TST_HEAD_LOCALE (tow##_func_, S_TOW##_FUNC_); \
  213. TST_DO_REC (tow##_func_) \
  214. { \
  215. TST_GET_ERRET (tow##_func_); \
  216. wc = TST_INPUT (tow##_func_).wc; \
  217. ret = tow##_func_ (wc); \
  218. if (debug_flg) \
  219. { \
  220. fprintf (stdout, "tow*() [ %s : %d ] ret = 0x%x\n", \
  221. locale, rec+1, ret); \
  222. } \
  223. \
  224. TST_IF_RETURN (S_TOW##_FUNC_) { }; \
  225. } \
  226. } \
  227. \
  228. return err_count; \
  229. }
  230. #endif /* TST_FUNCS_H */