tst_funcs.h 8.1 KB

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