Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do allow malloc(0) again, since it breaks user code on non-broken platforms
[simgrid.git] / include / xbt / cunit.h
1 /* $Id$ */
2
3 /* cunit - A little C Unit facility                                         */
4
5 /* Copyright (c) 2005 Martin Quinson. All rights reserved.                  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 /* This is partially inspirated from the OSSP ts (Test Suite Library)       */
11
12 #ifndef _XBT_CUNIT_H_
13 #define _XBT_CUNIT_H_
14
15 #include "xbt/sysdep.h"    /* XBT_GNU_PRINTF */
16 #include "xbt/ex.h"
17
18 SG_BEGIN_DECL()
19
20 /* test suite object type */
21 typedef struct s_xbt_test_suite *xbt_test_suite_t;
22
23 /* test object type */
24 typedef struct s_xbt_test_unit *xbt_test_unit_t;
25
26 /* test callback function type */
27 typedef void (*ts_test_cb_t)(void);
28
29 /* test suite operations */
30 XBT_PUBLIC(xbt_test_suite_t) xbt_test_suite_new  (const char *name,const char *fmt, ...);
31 XBT_PUBLIC(xbt_test_suite_t) xbt_test_suite_by_name(const char *name,const char *fmt, ...);
32 XBT_PUBLIC(void)             xbt_test_suite_dump (xbt_test_suite_t suite);
33 XBT_PUBLIC(void)             xbt_test_suite_push (xbt_test_suite_t suite, const char *name,
34                                                   ts_test_cb_t func, const char *fmt, ...);
35
36 /* Run all the specified tests. what_to_do allows to disable some tests.
37  * It is a coma (,) separated list of directives. They are applied from left to right.
38  *
39  * Each of them of form:
40  * 
41  * [-|+]suitename[:unitname[:testname]]
42  * 
43  * * First char: 
44  *   if it's a '-', the directive disables something
45  *   if it's a '+', the directive enables something
46  *   By default, everything is enabled, but you can disable a suite and reenable some parts
47  * * Suitename: the suite on which the directive acts
48  * * unitname: if given, the unit on which the directive acts. If not, acts on any units.
49  * * testname: if given, the test on which the directive acts. If not, acts on any tests.
50  */
51
52 XBT_PUBLIC(int) xbt_test_run(char *selection);
53 /* Show information about the selection of tests */
54 XBT_PUBLIC(void) xbt_test_dump(char *selection);
55 /* Cleanup the mess */
56 XBT_PUBLIC(void) xbt_test_exit(void);
57
58 /* test operations */
59 XBT_PUBLIC(void)    _xbt_test_add(const char*file,int line, const char *fmt, ...)_XBT_GNUC_PRINTF(3,4);
60 #define xbt_test_add0(fmt)           _xbt_test_add(__FILE__,__LINE__,fmt)
61 #define xbt_test_add1(fmt,a)         _xbt_test_add(__FILE__,__LINE__,fmt,a)
62 #define xbt_test_add2(fmt,a,b)       _xbt_test_add(__FILE__,__LINE__,fmt,a,b)
63 #define xbt_test_add3(fmt,a,b,c)     _xbt_test_add(__FILE__,__LINE__,fmt,a,b,c)
64 #define xbt_test_add4(fmt,a,b,c,d)   _xbt_test_add(__FILE__,__LINE__,fmt,a,b,c,d)
65 #define xbt_test_add5(fmt,a,b,c,d,e) _xbt_test_add(__FILE__,__LINE__,fmt,a,b,c,d,e)
66
67 XBT_PUBLIC(void)    _xbt_test_fail(const char*file,int line, const char *fmt, ...) _XBT_GNUC_PRINTF(3,4);
68 #define xbt_test_fail0(fmt)           _xbt_test_fail(__FILE__, __LINE__, fmt)
69 #define xbt_test_fail1(fmt,a)         _xbt_test_fail(__FILE__, __LINE__, fmt,a)
70 #define xbt_test_fail2(fmt,a,b)       _xbt_test_fail(__FILE__, __LINE__, fmt,a,b)
71 #define xbt_test_fail3(fmt,a,b,c)     _xbt_test_fail(__FILE__, __LINE__, fmt,a,b,c)
72 #define xbt_test_fail4(fmt,a,b,c,d)   _xbt_test_fail(__FILE__, __LINE__, fmt,a,b,c,d)
73 #define xbt_test_fail5(fmt,a,b,c,d,e) _xbt_test_fail(__FILE__, __LINE__, fmt,a,b,c,d,e)
74
75 #define xbt_test_assert0(cond,fmt)           if(!(cond)) xbt_test_fail0(fmt)
76 #define xbt_test_assert1(cond,fmt,a)         if(!(cond)) xbt_test_fail1(fmt,a)
77 #define xbt_test_assert2(cond,fmt,a,b)       if(!(cond)) xbt_test_fail2(fmt,a,b)
78 #define xbt_test_assert3(cond,fmt,a,b,c)     if(!(cond)) xbt_test_fail3(fmt,a,b,c)
79 #define xbt_test_assert4(cond,fmt,a,b,c,d)   if(!(cond)) xbt_test_fail4(fmt,a,b,c,d)
80 #define xbt_test_assert5(cond,fmt,a,b,c,d,e) if(!(cond)) xbt_test_fail5(fmt,a,b,c,d,e)
81 #define xbt_test_assert(cond)                xbt_test_assert0(cond,#cond)
82
83 XBT_PUBLIC(void)    _xbt_test_log (const char*file,int line, const char *fmt, ...)_XBT_GNUC_PRINTF(3,4);
84 #define xbt_test_log0(fmt)           _xbt_test_log(__FILE__, __LINE__, fmt)
85 #define xbt_test_log1(fmt,a)         _xbt_test_log(__FILE__, __LINE__, fmt,a)
86 #define xbt_test_log2(fmt,a,b)       _xbt_test_log(__FILE__, __LINE__, fmt,a,b)
87 #define xbt_test_log3(fmt,a,b,c)     _xbt_test_log(__FILE__, __LINE__, fmt,a,b,c)
88 #define xbt_test_log4(fmt,a,b,c,d)   _xbt_test_log(__FILE__, __LINE__, fmt,a,b,c,d)
89 #define xbt_test_log5(fmt,a,b,c,d,e) _xbt_test_log(__FILE__, __LINE__, fmt,a,b,c,d,e)
90
91 XBT_PUBLIC(void) xbt_test_exception(xbt_ex_t e);
92
93 XBT_PUBLIC(void) xbt_test_expect_failure(void);
94 XBT_PUBLIC(void) xbt_test_skip(void);
95
96 /* test suite short-cut macros */
97 #define XBT_TEST_UNIT(name,func,title)    \
98     void func(void);  /*prototype*/       \
99     void func(void)
100     
101 SG_END_DECL() 
102
103 #endif /* _TS_H_ */
104