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