tst_funcs.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 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. #ifdef __UCLIBC_HAS_LOCALE__
  78. #define TST_HEAD_LOCALE(ofunc, s_func) \
  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. #else
  89. #define TST_HEAD_LOCALE(ofunc, s_func) \
  90. locale = TST_HEAD (ofunc).locale; \
  91. if (strcmp(locale, "C") == 0) \
  92. { \
  93. if (setlocale (LC_ALL, locale) == NULL) \
  94. { \
  95. fprintf (stderr, "Warning : can't set locale: %s\nskipping ...\n", \
  96. locale); \
  97. result (fp, C_LOCALES, s_func, locale, 0, 0, 0, "can't set locale"); \
  98. ++err_count; \
  99. continue; \
  100. } \
  101. } \
  102. else \
  103. { \
  104. fprintf (stderr, "Warning : locale %s unsupported\n\n", \
  105. locale); \
  106. result (fp, C_LOCALES, s_func, locale, 0, 0, 0, "unsupported"); \
  107. continue; \
  108. }
  109. #endif
  110. #define TST_DO_REC(ofunc) \
  111. for (rec=0; !TST_IS_LAST (ofunc); ++rec)
  112. #define TST_DO_SEQ(_count_) \
  113. for (seq_num=0; seq_num < _count_; seq_num++)
  114. #define TST_GET_ERRET(_ofunc_) \
  115. err_exp = TST_EXPECT (_ofunc_).err_val; \
  116. ret_flg = TST_EXPECT (_ofunc_).ret_flg; \
  117. ret_exp = TST_EXPECT (_ofunc_).ret_val
  118. #define TST_GET_ERRET_SEQ(_ofunc_) \
  119. err_exp = TST_EXPECT_SEQ (_ofunc_).err_val; \
  120. ret_flg = TST_EXPECT_SEQ (_ofunc_).ret_flg; \
  121. ret_exp = TST_EXPECT_SEQ (_ofunc_).ret_val
  122. #define TST_CLEAR_ERRNO \
  123. errno = 0
  124. #define TST_SAVE_ERRNO \
  125. errno_save = errno
  126. /* Test value of ret and of errno if it should have a value. */
  127. #define TST_IF_RETURN(_s_func_) \
  128. if (err_exp != 0) \
  129. { \
  130. if (errno_save == err_exp) \
  131. { \
  132. result (fp, C_SUCCESS, _s_func_, locale, rec+1, seq_num+1, 1, \
  133. MS_PASSED); \
  134. } \
  135. else \
  136. { \
  137. err_count++; \
  138. result (fp, C_FAILURE, _s_func_, locale, rec+1, seq_num+1, 1, \
  139. "the value of errno is different from an expected value"); \
  140. } \
  141. } \
  142. \
  143. if (ret_flg == 1) \
  144. { \
  145. if (ret == ret_exp) \
  146. { \
  147. result (fp, C_SUCCESS, _s_func_, locale, rec+1, seq_num+1, 2, \
  148. MS_PASSED); \
  149. } \
  150. else \
  151. { \
  152. err_count++; \
  153. result (fp, C_FAILURE, _s_func_, locale, rec+1, seq_num+1, 2, \
  154. "the return value is different from an expected value"); \
  155. } \
  156. } \
  157. else
  158. #define TEX_ERRET_REC(_type_) \
  159. struct { \
  160. TMD_ERRET (_type_); \
  161. }
  162. #define TEX_ERRET_REC_SEQ(_type_, _count_) \
  163. struct { \
  164. struct { \
  165. TMD_ERRET (_type_); \
  166. } seq[ _count_ ]; \
  167. }
  168. /* ------------------ FUNCTION: ISW*() ------------------- */
  169. #define TST_ISW_STRUCT(_FUNC_, _func_) \
  170. typedef \
  171. struct { \
  172. wint_t wc; \
  173. } TIN_ISW##_FUNC_##_REC; \
  174. typedef \
  175. TEX_ERRET_REC (int) TEX_ISW##_FUNC_##_REC; \
  176. TMD_RECHEAD (ISW##_FUNC_)
  177. #define TST_FUNC_ISW(_FUNC_, _func_) \
  178. int \
  179. tst_isw##_func_ (FILE *fp, int debug_flg) \
  180. { \
  181. TST_DECL_VARS(int); \
  182. wint_t wc; \
  183. TST_DO_TEST (isw##_func_) \
  184. { \
  185. TST_HEAD_LOCALE (isw##_func_, S_ISW##_FUNC_); \
  186. TST_DO_REC(isw##_func_) \
  187. { \
  188. TST_GET_ERRET (isw##_func_); \
  189. wc = TST_INPUT (isw##_func_).wc; \
  190. ret = isw##_func_ (wc); \
  191. if (debug_flg) \
  192. { \
  193. fprintf (stdout, "isw*() [ %s : %d ] ret = %d\n", locale, \
  194. rec+1, ret); \
  195. } \
  196. \
  197. TST_IF_RETURN (S_ISW##_FUNC_) \
  198. { \
  199. if (ret != 0) \
  200. { \
  201. result (fp, C_SUCCESS, S_ISW##_FUNC_, locale, rec+1, \
  202. seq_num+1, 3, MS_PASSED); \
  203. } \
  204. else \
  205. { \
  206. err_count++; \
  207. result (fp, C_FAILURE, S_ISW##_FUNC_, locale, rec+1, \
  208. seq_num+1, 3, \
  209. "the function returned 0, but should be non-zero"); \
  210. } \
  211. } \
  212. } \
  213. } \
  214. \
  215. return err_count; \
  216. }
  217. /* ------------------ FUNCTION: TOW*() ------------------ */
  218. #define TST_TOW_STRUCT(_FUNC_, _func_) \
  219. typedef \
  220. struct { \
  221. wint_t wc; \
  222. } TIN_TOW##_FUNC_##_REC; \
  223. typedef \
  224. TEX_ERRET_REC (wint_t) TEX_TOW##_FUNC_##_REC; \
  225. TMD_RECHEAD (TOW##_FUNC_)
  226. #define TST_FUNC_TOW(_FUNC_, _func_) \
  227. int \
  228. tst_tow##_func_ (FILE *fp, int debug_flg) \
  229. { \
  230. TST_DECL_VARS (wint_t); \
  231. wint_t wc; \
  232. TST_DO_TEST (tow##_func_) \
  233. { \
  234. TST_HEAD_LOCALE (tow##_func_, S_TOW##_FUNC_); \
  235. TST_DO_REC (tow##_func_) \
  236. { \
  237. TST_GET_ERRET (tow##_func_); \
  238. wc = TST_INPUT (tow##_func_).wc; \
  239. ret = tow##_func_ (wc); \
  240. if (debug_flg) \
  241. { \
  242. fprintf (stdout, "tow*() [ %s : %d ] ret = 0x%x\n", \
  243. locale, rec+1, ret); \
  244. } \
  245. \
  246. TST_IF_RETURN (S_TOW##_FUNC_) { }; \
  247. } \
  248. } \
  249. \
  250. return err_count; \
  251. }
  252. #endif /* TST_FUNCS_H */