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; \
88 int err_exp, ret_flg; \
93 #define TST_DO_TEST(o_func) \
94 for (loc = 0; strcmp (TST_HEAD (o_func).locale, TST_LOC_end); ++loc)
97 #define TST_HEAD_LOCALE(ofunc, s_func) \
98 locale = TST_HEAD (ofunc).locale; \
99 if (setlocale (LC_ALL, locale) == NULL) \
101 fprintf (stderr, "Warning : can't set locale: %s\nskipping ...\n", \
103 result (fp, C_LOCALES, s_func, locale, 0, 0, 0, "can't set locale"); \
108 #define TST_DO_REC(ofunc) \
109 for (rec=0; !TST_IS_LAST (ofunc); ++rec)
111 #define TST_DO_SEQ(_count_) \
112 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
119 #define TST_GET_ERRET_SEQ(_ofunc_) \
120 err_exp = TST_EXPECT_SEQ (_ofunc_).err_val; \
121 ret_flg = TST_EXPECT_SEQ (_ofunc_).ret_flg; \
122 ret_exp = TST_EXPECT_SEQ (_ofunc_).ret_val
124 #define TST_CLEAR_ERRNO \
127 #define TST_SAVE_ERRNO \
130 /* Test value of ret and of errno if it should have a value. */
131 #define TST_IF_RETURN(_s_func_) \
134 if (errno_save == err_exp) \
136 result (fp, C_SUCCESS, _s_func_, locale, rec+1, seq_num+1, 1, \
142 result (fp, C_FAILURE, _s_func_, locale, rec+1, seq_num+1, 1, \
143 "the value of errno is different from an expected value"); \
149 if (ret == ret_exp) \
151 result (fp, C_SUCCESS, _s_func_, locale, rec+1, seq_num+1, 2, \
157 result (fp, C_FAILURE, _s_func_, locale, rec+1, seq_num+1, 2, \
158 "the return value is different from an expected value"); \
163 #define TEX_ERRET_REC(_type_) \
165 TMD_ERRET (_type_); \
168 #define TEX_ERRET_REC_SEQ(_type_, _count_) \
171 TMD_ERRET (_type_); \
177 /* ------------------ FUNCTION: ISW*() ------------------- */
179 #define TST_ISW_STRUCT(_FUNC_, _func_) \
183 } TIN_ISW##_FUNC_##_REC; \
185 TEX_ERRET_REC (int) TEX_ISW##_FUNC_##_REC; \
186 TMD_RECHEAD (ISW##_FUNC_)
188 #define TST_FUNC_ISW(_FUNC_, _func_) \
190 tst_isw##_func_ (FILE *fp, int debug_flg) \
192 TST_DECL_VARS(int); \
194 TST_DO_TEST (isw##_func_) \
196 TST_HEAD_LOCALE (isw##_func_, S_ISW##_FUNC_); \
197 TST_DO_REC(isw##_func_) \
199 TST_GET_ERRET (isw##_func_); \
200 wc = TST_INPUT (isw##_func_).wc; \
201 ret = isw##_func_ (wc); \
204 fprintf (stdout, "isw*() [ %s : %d ] ret = %d\n", locale, \
208 TST_IF_RETURN (S_ISW##_FUNC_) \
212 result (fp, C_SUCCESS, S_ISW##_FUNC_, locale, rec+1, \
213 seq_num+1, 3, MS_PASSED); \
218 result (fp, C_FAILURE, S_ISW##_FUNC_, locale, rec+1, \
220 "the function returned 0, but should be non-zero"); \
231 /* ------------------ FUNCTION: TOW*() ------------------ */
233 #define TST_TOW_STRUCT(_FUNC_, _func_) \
237 } TIN_TOW##_FUNC_##_REC; \
239 TEX_ERRET_REC (wint_t) TEX_TOW##_FUNC_##_REC; \
240 TMD_RECHEAD (TOW##_FUNC_)
242 #define TST_FUNC_TOW(_FUNC_, _func_) \
244 tst_tow##_func_ (FILE *fp, int debug_flg) \
246 TST_DECL_VARS (wint_t); \
248 TST_DO_TEST (tow##_func_) \
250 TST_HEAD_LOCALE (tow##_func_, S_TOW##_FUNC_); \
251 TST_DO_REC (tow##_func_) \
253 TST_GET_ERRET (tow##_func_); \
254 wc = TST_INPUT (tow##_func_).wc; \
255 ret = tow##_func_ (wc); \
258 fprintf (stdout, "tow*() [ %s : %d ] ret = 0x%x\n", \
259 locale, rec+1, ret); \
262 TST_IF_RETURN (S_TOW##_FUNC_) { }; \
270 #endif /* TST_FUNCS_H */