~ubuntu-branches/ubuntu/hardy/belocs-locales-data/hardy

« back to all changes in this revision

Viewing changes to localedata/tests-mbwc/tst_funcs.h

  • Committer: Bazaar Package Importer
  • Author(s): Denis Barbier
  • Date: 2005-05-17 22:09:38 UTC
  • Revision ID: james.westby@ubuntu.com-20050517220938-814x2iu6tkj3ml2o
Tags: upstream-2.3.4
ImportĀ upstreamĀ versionĀ 2.3.4

Show diffs side-by-side

added added

removed removed

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