test.h

00001 /*
00002  * Copyright (c) 2005-2012 by KoanLogic s.r.l. - All rights reserved.
00003  */
00004 
00005 #ifndef _U_TEST_H_
00006 #define _U_TEST_H_
00007 
00008 #include <u/libu_conf.h>
00009 
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif  /* __cplusplus */
00013 
00019 struct u_test_case_s;
00020 struct u_test_suite_s;
00021 struct u_test_s;
00022 
00024 #define u_test_err_if(a)        \
00025     do { if (a) { u_test_case_printf(tc, "%s", #a); goto err; } } while (0)
00026 
00028 #define u_test_err_ifm(a, ...)  \
00029     do { if (a) { u_test_case_printf(tc, __VA_ARGS__); goto err; } } while (0)
00030 
00032 typedef struct u_test_case_s u_test_case_t;
00033 
00035 typedef struct u_test_suite_s u_test_suite_t;
00036 
00038 typedef struct u_test_s u_test_t;
00039 
00041 enum { 
00042     U_TEST_SUCCESS = 0,
00045     U_TEST_FAILURE = 1,
00048     U_TEST_ABORTED = 2,
00051     U_TEST_SKIPPED = 3
00053 };
00054 
00057 typedef enum { U_TEST_REP_HEAD, U_TEST_REP_TAIL } u_test_rep_tag_t;
00058 
00060 typedef int (*u_test_f)(u_test_case_t *);
00061 
00063 typedef int (*u_test_rep_f)(FILE *, u_test_t *, u_test_rep_tag_t);
00064 typedef int (*u_test_case_rep_f)(FILE *, u_test_case_t *);
00065 typedef int (*u_test_suite_rep_f)(FILE *, u_test_suite_t *, u_test_rep_tag_t);
00066 
00068 #ifndef U_TEST_MAX_PARALLEL
00069 #define U_TEST_MAX_PARALLEL   32
00070 #endif  /* !U_TEST_MAX_PARALLEL */
00071 
00073 #ifndef U_TEST_ID_MAX
00074 #define U_TEST_ID_MAX     128
00075 #endif  /* !U_TEST_ID_MAX */
00076 
00078 #ifndef U_TEST_OUTFN_DFL
00079 #define U_TEST_OUTFN_DFL  "./unitest-report.out"
00080 #endif  /* !U_TEST_OUTFN_DFL */
00081 
00082 int u_test_case_new (const char *id, u_test_f func, u_test_case_t **ptc);
00083 int u_test_case_add (u_test_case_t *tc, u_test_suite_t *ts);
00084 void u_test_case_free (u_test_case_t *tc);
00085 int u_test_case_register (const char *id, u_test_f func, u_test_suite_t *ts);
00086 int u_test_case_dep_register (const char *id, u_test_case_t *tc);
00087 int u_test_case_depends_on (const char *tcid, const char *depid, 
00088         u_test_suite_t *ts);
00089 int u_test_case_printf (u_test_case_t *tc, const char *fmt, ...);
00090 
00091 int u_test_suite_add (u_test_suite_t *to, u_test_t *t);
00092 void u_test_suite_free (u_test_suite_t *ts);
00093 int u_test_suite_new (const char *id, u_test_suite_t **pts);
00094 int u_test_suite_dep_register (const char *id, u_test_suite_t *ts);
00095 int u_test_suite_depends_on (const char *tsid, const char *depid, u_test_t *t);
00096 
00097 int u_test_new (const char *id, u_test_t **pt);
00098 int u_test_set_outfn (u_test_t *t, const char *outfn);
00099 int u_test_set_u_test_suite_rep (u_test_t *t, u_test_suite_rep_f func);
00100 int u_test_set_u_test_case_rep (u_test_t *t, u_test_case_rep_f func);
00101 int u_test_set_u_test_rep (u_test_t *t, u_test_rep_f func);
00102 
00103 void u_test_free (u_test_t *t);
00104 int u_test_run (int ac, char *av[], u_test_t *t);
00105 
00110 #ifdef __cplusplus
00111 }
00112 #endif  /* __cplusplus */
00113 
00114 #endif  /* !_U_TEST_H_ */

←Products
© 2005-2012 - KoanLogic S.r.l. - All rights reserved