Back to index

glibc  2.9
tst_funcs.h
Go to the documentation of this file.
00001 /*
00002  *  TEST SUITE FOR MB/WC FUNCTIONS IN C LIBRARY
00003  *
00004  *      FILE: tst_funcs.h
00005  *
00006  *      Definitions of macros
00007  */
00008 
00009 
00010 #ifndef TST_FUNCS_H
00011 #define TST_FUNCS_H
00012 
00013 #define C_SUCCESS       'S' /* test case test passed            */
00014 #define C_FAILURE       'F' /* test case failed                 */
00015 #define C_IGNORED       'I' /* test case/result ignored (not tested) */
00016 #define C_INVALID       'D' /* test data may be wrong           */
00017 #define C_LOCALES       'L' /* can't set locale (skip)          */
00018 
00019 
00020 extern int result (FILE * fp, char res, const char *func, const char *loc,
00021                  int rec_no, int seq_num, int case_no, const char *msg);
00022 
00023 #define Result(C, S, E, M) \
00024   result (fp, (C), (S), locale, rec+1, seq_num+1, (E), (M))
00025 
00026 #define CASE_0         0
00027 #define CASE_1         1
00028 #define CASE_2         2
00029 #define CASE_3         3
00030 #define CASE_4         4
00031 #define CASE_5         5
00032 #define CASE_6         6
00033 #define CASE_7         7
00034 #define CASE_8         8
00035 #define CASE_9         9
00036 
00037 #define MS_PASSED "PASSED"
00038 #define MS_SPACE  "   "
00039 #define MS_FAILED "   "
00040 #define MS_NOTEST "NOTEST"
00041 #define MS_ABORTU "ABEND0"
00042 #define MS_ABORT  "ABEND1"
00043 
00044 #define MK_PASSED 0x00
00045 #define MK_SPACE  0x01
00046 #define MK_NOTEST 0x02
00047 #define MK_ABORTU 0x04
00048 #define MK_ABORT  0x08
00049 
00050 
00051 
00052 /* ------------------ COMMON MACROS ------------------ */
00053 
00054 #define TST_ABS(x)  (((x) > 0) ? (x) : -(x))
00055 
00056 #define TMD_ERRET(_type_)   int      err_val; \
00057                          int         ret_flg; \
00058                          _type_ ret_val
00059 
00060 #define TMD_RECHEAD(_FUNC_)                            \
00061                                                                 \
00062                            typedef struct {                            \
00063                               TIN_##_FUNC_##_REC  input;               \
00064                               TEX_##_FUNC_##_REC  expect;              \
00065                               int is_last;                             \
00066                            }         TST_##_FUNC_##_REC;                      \
00067                            typedef struct {                            \
00068                               TST_HEAD          hd;             \
00069                               TST_##_FUNC_##_REC  rec[ MAX_LOC_TEST ]; \
00070                            }         TST_##_FUNC_
00071 
00072 #define TST_FTYP(func)             tst_##func##_loc
00073 #define TST_HEAD(func)             tst_##func##_loc[ loc ].hd
00074 #define TST_INPUT(func)            tst_##func##_loc[ loc ].rec[ rec ].input
00075 #define TST_EXPECT(func)    tst_##func##_loc[ loc ].rec[ rec ].expect
00076 #define TST_INPUT_SEQ(func) \
00077        tst_##func##_loc[ loc ].rec[ rec ].input.seq[ seq_num ]
00078 #define TST_EXPECT_SEQ(func) \
00079        tst_##func##_loc[ loc ].rec[ rec ].expect.seq[ seq_num ]
00080 #define TST_IS_LAST(func) \
00081        tst_##func##_loc[ loc ].rec[ rec ].is_last
00082 
00083 
00084 #define TST_DECL_VARS(_type_)                           \
00085        int   loc, rec, err_count = 0;                   \
00086        int   warn_count __attribute__ ((unused));       \
00087        int   func_id, seq_num = 0;               \
00088        const char *locale;                       \
00089        int   err_exp, ret_flg;                          \
00090        int errno_save = 0;                       \
00091        _type_ ret_exp;                                  \
00092        _type_ ret
00093 
00094 #define TST_DO_TEST(o_func) \
00095        for (loc = 0; strcmp (TST_HEAD (o_func).locale, TST_LOC_end); ++loc)
00096 
00097 
00098 #define TST_HEAD_LOCALE(ofunc, s_func) \
00099   func_id = TST_HEAD (ofunc).func_id;                                       \
00100   locale  = TST_HEAD (ofunc).locale;                                        \
00101   if (setlocale (LC_ALL, locale) == NULL)                            \
00102     {                                                                \
00103       fprintf (stderr, "Warning : can't set locale: %s\nskipping ...\n",      \
00104               locale);                                                      \
00105       result (fp, C_LOCALES, s_func, locale, 0, 0, 0, "can't set locale");    \
00106       ++err_count;                                                   \
00107       continue;                                                             \
00108     }
00109 
00110 #define TST_DO_REC(ofunc) \
00111        for (rec=0; !TST_IS_LAST (ofunc); ++rec)
00112 
00113 #define TST_DO_SEQ(_count_) \
00114        for (seq_num=0; seq_num < _count_; seq_num++)
00115 
00116 #define TST_GET_ERRET(_ofunc_)                   \
00117        err_exp = TST_EXPECT (_ofunc_).err_val; \
00118        ret_flg = TST_EXPECT (_ofunc_).ret_flg; \
00119        ret_exp = TST_EXPECT (_ofunc_).ret_val
00120 
00121 #define TST_GET_ERRET_SEQ(_ofunc_)            \
00122        err_exp = TST_EXPECT_SEQ (_ofunc_).err_val; \
00123        ret_flg = TST_EXPECT_SEQ (_ofunc_).ret_flg; \
00124        ret_exp = TST_EXPECT_SEQ (_ofunc_).ret_val
00125 
00126 #define TST_CLEAR_ERRNO \
00127        errno = 0
00128 
00129 #define TST_SAVE_ERRNO \
00130        errno_save = errno
00131 
00132 /* Test value of ret and of errno if it should have a value.  */
00133 #define TST_IF_RETURN(_s_func_) \
00134   if (err_exp != 0)                                                  \
00135     {                                                                \
00136       if (errno_save == err_exp)                                     \
00137        {                                                             \
00138          result (fp, C_SUCCESS, _s_func_, locale, rec+1, seq_num+1, 1,             \
00139                 MS_PASSED);                                          \
00140        }                                                             \
00141       else                                                           \
00142        {                                                             \
00143          err_count++;                                                       \
00144          result (fp, C_FAILURE, _s_func_, locale, rec+1, seq_num+1, 1,             \
00145                 "the value of errno is different from an expected value");  \
00146        }                                                             \
00147     }                                                                \
00148                                                                      \
00149   if (ret_flg == 1)                                                  \
00150     {                                                                \
00151       if (ret == ret_exp)                                            \
00152        {                                                             \
00153          result (fp, C_SUCCESS, _s_func_, locale, rec+1, seq_num+1, 2,             \
00154                 MS_PASSED);                                          \
00155        }                                                             \
00156       else                                                           \
00157        {                                                             \
00158          err_count++;                                                       \
00159          result (fp, C_FAILURE, _s_func_, locale, rec+1, seq_num+1, 2,             \
00160                 "the return value is different from an expected value");    \
00161        }                                                             \
00162     }                                                                \
00163   else
00164 
00165 #define TEX_ERRET_REC(_type_)                    \
00166        struct {                           \
00167            TMD_ERRET (_type_);                   \
00168        }
00169 
00170 #define TEX_ERRET_REC_SEQ(_type_, _count_)       \
00171        struct {                           \
00172            struct {                       \
00173               TMD_ERRET (_type_);         \
00174            } seq[ _count_ ];                     \
00175        }
00176 
00177 
00178 
00179 /* ------------------ FUNCTION: ISW*() ------------------- */
00180 
00181 #define TST_ISW_STRUCT(_FUNC_, _func_)                  \
00182        typedef                                          \
00183        struct {                                  \
00184            wint_t   wc;                          \
00185        } TIN_ISW##_FUNC_##_REC;                  \
00186        typedef                                          \
00187        TEX_ERRET_REC (int)   TEX_ISW##_FUNC_##_REC;     \
00188        TMD_RECHEAD (ISW##_FUNC_)
00189 
00190 #define TST_FUNC_ISW(_FUNC_, _func_) \
00191 int                                                                  \
00192 tst_isw##_func_ (FILE *fp, int debug_flg)                            \
00193 {                                                                    \
00194   TST_DECL_VARS(int);                                                       \
00195   wint_t wc;                                                         \
00196   TST_DO_TEST (isw##_func_)                                          \
00197     {                                                                \
00198       TST_HEAD_LOCALE (isw##_func_, S_ISW##_FUNC_);                         \
00199       TST_DO_REC(isw##_func_)                                               \
00200        {                                                             \
00201          TST_GET_ERRET (isw##_func_);                                       \
00202          wc = TST_INPUT (isw##_func_).wc;                            \
00203          ret = isw##_func_ (wc);                                     \
00204          if (debug_flg)                                              \
00205            {                                                         \
00206              fprintf (stdout, "isw*() [ %s : %d ] ret = %d\n", locale,             \
00207                      rec+1, ret);                                    \
00208            }                                                         \
00209                                                                      \
00210          TST_IF_RETURN (S_ISW##_FUNC_)                                      \
00211            {                                                         \
00212              if (ret != 0)                                           \
00213               {                                                      \
00214                 result (fp, C_SUCCESS, S_ISW##_FUNC_, locale, rec+1,        \
00215                        seq_num+1, 3, MS_PASSED);                     \
00216               }                                                      \
00217              else                                                    \
00218               {                                                      \
00219                 err_count++;                                                \
00220                 result (fp, C_FAILURE, S_ISW##_FUNC_, locale, rec+1,        \
00221                        seq_num+1, 3,                                        \
00222                        "the function returned 0, but should be non-zero"); \
00223               }                                                      \
00224            }                                                         \
00225        }                                                             \
00226     }                                                                \
00227                                                                      \
00228   return err_count;                                                  \
00229 }
00230 
00231 
00232 
00233 /* ------------------ FUNCTION: TOW*() ------------------ */
00234 
00235 #define TST_TOW_STRUCT(_FUNC_, _func_)                  \
00236        typedef                                          \
00237        struct {                                  \
00238            wint_t   wc;                          \
00239        } TIN_TOW##_FUNC_##_REC;                  \
00240        typedef                                          \
00241        TEX_ERRET_REC (wint_t)      TEX_TOW##_FUNC_##_REC;      \
00242        TMD_RECHEAD (TOW##_FUNC_)
00243 
00244 #define TST_FUNC_TOW(_FUNC_, _func_)                                  \
00245 int                                                            \
00246 tst_tow##_func_ (FILE *fp, int debug_flg)                      \
00247 {                                                              \
00248   TST_DECL_VARS (wint_t);                                      \
00249   wint_t wc;                                                   \
00250   TST_DO_TEST (tow##_func_)                                    \
00251     {                                                          \
00252       TST_HEAD_LOCALE (tow##_func_, S_TOW##_FUNC_);                   \
00253       TST_DO_REC (tow##_func_)                                        \
00254        {                                                       \
00255          TST_GET_ERRET (tow##_func_);                                 \
00256          wc = TST_INPUT (tow##_func_).wc;                      \
00257          ret = tow##_func_ (wc);                               \
00258          if (debug_flg)                                        \
00259            {                                                   \
00260              fprintf (stdout, "tow*() [ %s : %d ] ret = 0x%x\n",      \
00261                      locale, rec+1, ret);                      \
00262            }                                                   \
00263                                                                \
00264          TST_IF_RETURN (S_TOW##_FUNC_) { };                           \
00265        }                                                       \
00266     }                                                          \
00267                                                                \
00268   return err_count;                                            \
00269 }
00270 
00271 
00272 #endif /* TST_FUNCS_H */