1 /* cunit - A little C Unit facility */
3 /* Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 /* This is partially inspirated from the OSSP ts (Test Suite Library) */
14 #include "xbt/sysdep.h" /* XBT_GNU_PRINTF */
19 /* test suite object type */
20 typedef struct s_xbt_test_suite *xbt_test_suite_t;
22 /* test object type */
23 typedef struct s_xbt_test_unit *xbt_test_unit_t;
25 /* test callback function type */
26 typedef void (*ts_test_cb_t) (void);
28 /* test suite operations */
29 XBT_PUBLIC(xbt_test_suite_t) xbt_test_suite_new(const char *name,
30 const char *fmt, ...);
31 XBT_PUBLIC(xbt_test_suite_t) xbt_test_suite_by_name(const char *name,
32 const char *fmt, ...);
33 XBT_PUBLIC(void) xbt_test_suite_dump(xbt_test_suite_t suite);
34 XBT_PUBLIC(void) xbt_test_suite_push(xbt_test_suite_t suite,
35 const char *name, ts_test_cb_t func,
36 const char *fmt, ...);
38 /* Run all the specified tests. what_to_do allows to disable some tests.
39 * It is a coma (,) separated list of directives. They are applied from left to right.
41 * Each of them of form:
43 * [-|+]suitename[:unitname[:testname]]
46 * if it's a '-', the directive disables something
47 * if it's a '+', the directive enables something
48 * By default, everything is enabled, but you can disable a suite and reenable some parts
49 * * Suitename: the suite on which the directive acts
50 * * unitname: if given, the unit on which the directive acts. If not, acts on any units.
51 * * testname: if given, the test on which the directive acts. If not, acts on any tests.
54 XBT_PUBLIC(int) xbt_test_run(char *selection, int verbosity);
55 /* Show information about the selection of tests */
56 XBT_PUBLIC(void) xbt_test_dump(char *selection);
57 /* Cleanup the mess */
58 XBT_PUBLIC(void) xbt_test_exit(void);
61 XBT_PUBLIC(void) _xbt_test_add(const char *file, int line, const char *fmt,
62 ...) _XBT_GNUC_PRINTF(3, 4);
63 XBT_PUBLIC(void) _xbt_test_fail(const char *file, int line,
64 const char *fmt, ...) _XBT_GNUC_PRINTF(3,
66 XBT_PUBLIC(void) _xbt_test_log(const char *file, int line, const char *fmt,
67 ...) _XBT_GNUC_PRINTF(3, 4);
69 #define xbt_test_add(...) _xbt_test_add(__FILE__, __LINE__, __VA_ARGS__)
70 #define xbt_test_fail(...) _xbt_test_fail(__FILE__, __LINE__, __VA_ARGS__)
71 #define xbt_test_assert(...) _XBT_IF_ONE_ARG(_xbt_test_assert_ARG1, \
72 _xbt_test_assert_ARGN, \
73 __VA_ARGS__)(__VA_ARGS__)
74 #define _xbt_test_assert_ARG1(cond) _xbt_test_assert_CHECK(cond, \
76 #define _xbt_test_assert_ARGN(cond, ...) _xbt_test_assert_CHECK(cond, \
78 #define _xbt_test_assert_CHECK(cond, ...) \
79 do { if (!(cond)) xbt_test_fail(__VA_ARGS__); } while (0)
80 #define xbt_test_log(...) _xbt_test_log(__FILE__, __LINE__, __VA_ARGS__)
82 XBT_PUBLIC(void) xbt_test_exception(xbt_ex_t e);
84 XBT_PUBLIC(void) xbt_test_expect_failure(void);
85 XBT_PUBLIC(void) xbt_test_skip(void);
87 /* test suite short-cut macros */
88 #define XBT_TEST_UNIT(name,func,title) \
89 void func(void); /*prototype*/ \
92 #ifdef XBT_USE_DEPRECATED
94 /* Kept for backward compatibility. */
96 #define xbt_test_add0(...) xbt_test_add(__VA_ARGS__)
97 #define xbt_test_add1(...) xbt_test_add(__VA_ARGS__)
98 #define xbt_test_add2(...) xbt_test_add(__VA_ARGS__)
99 #define xbt_test_add3(...) xbt_test_add(__VA_ARGS__)
100 #define xbt_test_add4(...) xbt_test_add(__VA_ARGS__)
101 #define xbt_test_add5(...) xbt_test_add(__VA_ARGS__)
103 #define xbt_test_fail0(...) xbt_test_fail(__VA_ARGS__)
104 #define xbt_test_fail1(...) xbt_test_fail(__VA_ARGS__)
105 #define xbt_test_fail2(...) xbt_test_fail(__VA_ARGS__)
106 #define xbt_test_fail3(...) xbt_test_fail(__VA_ARGS__)
107 #define xbt_test_fail4(...) xbt_test_fail(__VA_ARGS__)
108 #define xbt_test_fail5(...) xbt_test_fail(__VA_ARGS__)
110 #define xbt_test_assert0(...) xbt_test_assert(__VA_ARGS__)
111 #define xbt_test_assert1(...) xbt_test_assert(__VA_ARGS__)
112 #define xbt_test_assert2(...) xbt_test_assert(__VA_ARGS__)
113 #define xbt_test_assert3(...) xbt_test_assert(__VA_ARGS__)
114 #define xbt_test_assert4(...) xbt_test_assert(__VA_ARGS__)
115 #define xbt_test_assert5(...) xbt_test_assert(__VA_ARGS__)
117 #define xbt_test_log0(...) xbt_test_log(__VA_ARGS__)
118 #define xbt_test_log1(...) xbt_test_log(__VA_ARGS__)
119 #define xbt_test_log2(...) xbt_test_log(__VA_ARGS__)
120 #define xbt_test_log3(...) xbt_test_log(__VA_ARGS__)
121 #define xbt_test_log4(...) xbt_test_log(__VA_ARGS__)
122 #define xbt_test_log5(...) xbt_test_log(__VA_ARGS__)