2 * TEST SUITE FOR MB/WC FUNCTIONS IN C LIBRARY
6 * Definitions of macros
13 #define C_SUCCESS 'S' /* test case test passed */
14 #define C_FAILURE 'F' /* test case failed */
15 #define C_IGNORED 'I' /* test case/result ignored (not tested) */
16 #define C_INVALID 'D' /* test data may be wrong */
17 #define C_LOCALES 'L' /* can't set locale (skip) */
20 extern int result (FILE * fp, char res, const char *func, const char *loc,
21 int rec_no, int seq_num, int case_no, const char *msg);
23 #define Result(C, S, E, M) \
24 result (fp, (C), (S), locale, rec+1, seq_num+1, (E), (M))
37 #define MS_PASSED "PASSED"
40 #define MS_NOTEST "NOTEST"
41 #define MS_ABORTU "ABEND0"
42 #define MS_ABORT "ABEND1"
44 #define MK_PASSED 0x00
46 #define MK_NOTEST 0x02
47 #define MK_ABORTU 0x04
52 /* ------------------ COMMON MACROS ------------------ */
54 #define TST_ABS(x) (((x) > 0) ? (x) : -(x))
56 #define TMD_ERRET(_type_) int err_val; \
60 #define TMD_RECHEAD(_FUNC_) \
63 TIN_##_FUNC_##_REC input; \
64 TEX_##_FUNC_##_REC expect; \
66 } TST_##_FUNC_##_REC; \
69 TST_##_FUNC_##_REC rec[ MAX_LOC_TEST ]; \
72 #define TST_FTYP(func) tst_##func##_loc
73 #define TST_HEAD(func) tst_##func##_loc[ loc ].hd
74 #define TST_INPUT(func) tst_##func##_loc[ loc ].rec[ rec ].input
75 #define TST_EXPECT(func) tst_##func##_loc[ loc ].rec[ rec ].expect
76 #define TST_INPUT_SEQ(func) \
77 tst_##func##_loc[ loc ].rec[ rec ].input.seq[ seq_num ]
78 #define TST_EXPECT_SEQ(func) \
79 tst_##func##_loc[ loc ].rec[ rec ].expect.seq[ seq_num ]
80 #define TST_IS_LAST(func) \
81 tst_##func##_loc[ loc ].rec[ rec ].is_last
84 #define TST_DECL_VARS(_type_) \
85 int loc, rec, err_count = 0; \
86 int warn_count __attribute__ ((unused)); \
89 int err_exp, ret_flg; \
94 #define TST_DO_TEST(o_func) \
95 for (loc = 0; strcmp (TST_HEAD (o_func).locale, TST_LOC_end); ++loc)
98 #define TST_HEAD_LOCALE(ofunc, s_func) \
99 locale = TST_HEAD (ofunc).locale; \
100 if (setlocale (LC_ALL, locale) == NULL) \
102 fprintf (stderr, "Warning : can't set locale: %s\nskipping ...\n", \
104 result (fp, C_LOCALES, s_func, locale, 0, 0, 0, "can't set locale"); \
109 #define TST_DO_REC(ofunc) \
110 for (rec=0; !TST_IS_LAST (ofunc); ++rec)
112 #define TST_DO_SEQ(_count_) \
113 for (seq_num=0; seq_num < _count_; seq_num++)
115 #define TST_GET_ERRET(_ofunc_) \
116 err_exp = TST_EXPECT (_ofunc_).err_val; \
117 ret_flg = TST_EXPECT (_ofunc_).ret_flg; \
118 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
125 #define TST_CLEAR_ERRNO \
128 #define TST_SAVE_ERRNO \
131 /* Test value of ret and of errno if it should have a value. */
132 #define TST_IF_RETURN(_s_func_) \
135 if (errno_save == err_exp) \
137 result (fp, C_SUCCESS, _s_func_, locale, rec+1, seq_num+1, 1, \
143 result (fp, C_FAILURE, _s_func_, locale, rec+1, seq_num+1, 1, \
144 "the value of errno is different from an expected value"); \
150 if (ret == ret_exp) \
152 result (fp, C_SUCCESS, _s_func_, locale, rec+1, seq_num+1, 2, \
158 result (fp, C_FAILURE, _s_func_, locale, rec+1, seq_num+1, 2, \
159 "the return value is different from an expected value"); \
164 #define TEX_ERRET_REC(_type_) \
166 TMD_ERRET (_type_); \
169 #define TEX_ERRET_REC_SEQ(_type_, _count_) \
172 TMD_ERRET (_type_); \
178 /* ------------------ FUNCTION: ISW*() ------------------- */
180 #define TST_ISW_STRUCT(_FUNC_, _func_) \
184 } TIN_ISW##_FUNC_##_REC; \
186 TEX_ERRET_REC (int) TEX_ISW##_FUNC_##_REC; \
187 TMD_RECHEAD (ISW##_FUNC_)
189 #define TST_FUNC_ISW(_FUNC_, _func_) \
191 tst_isw##_func_ (FILE *fp, int debug_flg) \
193 TST_DECL_VARS(int); \
195 TST_DO_TEST (isw##_func_) \
197 TST_HEAD_LOCALE (isw##_func_, S_ISW##_FUNC_); \
198 TST_DO_REC(isw##_func_) \
200 TST_GET_ERRET (isw##_func_); \
201 wc = TST_INPUT (isw##_func_).wc; \
202 ret = isw##_func_ (wc); \
205 fprintf (stdout, "isw*() [ %s : %d ] ret = %d\n", locale, \
209 TST_IF_RETURN (S_ISW##_FUNC_) \
213 result (fp, C_SUCCESS, S_ISW##_FUNC_, locale, rec+1, \
214 seq_num+1, 3, MS_PASSED); \
219 result (fp, C_FAILURE, S_ISW##_FUNC_, locale, rec+1, \
221 "the function returned 0, but should be non-zero"); \
232 /* ------------------ FUNCTION: TOW*() ------------------ */
234 #define TST_TOW_STRUCT(_FUNC_, _func_) \
238 } TIN_TOW##_FUNC_##_REC; \
240 TEX_ERRET_REC (wint_t) TEX_TOW##_FUNC_##_REC; \
241 TMD_RECHEAD (TOW##_FUNC_)
243 #define TST_FUNC_TOW(_FUNC_, _func_) \
245 tst_tow##_func_ (FILE *fp, int debug_flg) \
247 TST_DECL_VARS (wint_t); \
249 TST_DO_TEST (tow##_func_) \
251 TST_HEAD_LOCALE (tow##_func_, S_TOW##_FUNC_); \
252 TST_DO_REC (tow##_func_) \
254 TST_GET_ERRET (tow##_func_); \
255 wc = TST_INPUT (tow##_func_).wc; \
256 ret = tow##_func_ (wc); \
259 fprintf (stdout, "tow*() [ %s : %d ] ret = 0x%x\n", \
260 locale, rec+1, ret); \
263 TST_IF_RETURN (S_TOW##_FUNC_) { }; \
271 #endif /* TST_FUNCS_H */