12 #define ATF_PLAN_SUITE_MAX 128
13 #define ATF_SUITE_TEST_MAX 128
25 void (*
run)(atf_test *, atf_test_result *);
40 #define TEST(__test_name, __test_desc) \
41 static void test_spec__##__test_name(atf_test *, atf_test_result *); \
42 static atf_test test__##__test_name = { \
43 .name = #__test_name, \
44 .desc = __test_desc, \
45 .run = test_spec__##__test_name \
47 atf_test * __test_name = & test__##__test_name; \
48 static void test_spec__##__test_name(atf_test * self, atf_test_result * __result__)
62 void (*
init)(atf_suite *);
63 bool (*
before)(atf_suite *);
64 bool (*
after)(atf_suite *);
74 atf_suite *
atf_suite_add(atf_suite * suite, atf_test * test);
78 atf_suite *
atf_suite_after(atf_suite * suite,
bool (* after)(atf_suite * suite));
79 atf_suite *
atf_suite_before(atf_suite * suite,
bool (* before)(atf_suite * suite));
84 atf_suite_result *
atf_suite_result_add(atf_suite_result * suite_result, atf_test_result * test_result);
88 #define SUITE(__suite_name, __suite_desc) \
89 static void suite_spec__##__suite_name(atf_suite *); \
90 static atf_suite suite__##__suite_name = { \
91 .name = #__suite_name, \
92 .desc = __suite_desc, \
95 .init = suite_spec__##__suite_name, \
99 atf_suite * __suite_name = & suite__##__suite_name; \
100 static void suite_spec__##__suite_name(atf_suite * self)
102 #define suite_add(__test) \
103 extern atf_test * __test; \
104 atf_suite_add(self, __test)
106 #define suite_before(__func) \
107 atf_suite_before(self, __func)
109 #define suite_after(__func) \
110 atf_suite_after(self, __func)
124 bool (*
before)(atf_plan *);
125 bool (*
after)(atf_plan *);
134 atf_plan *
atf_plan_add(atf_plan *
self, atf_suite * suite);
135 int atf_plan_run(atf_plan *
self, atf_plan_result * result);
137 atf_plan *
atf_plan_after(atf_plan * plan,
bool (* after)(atf_plan * plan));
138 atf_plan *
atf_plan_before(atf_plan * plan,
bool (* before)(atf_plan * plan));
140 atf_plan_result *
atf_plan_result_add(atf_plan_result * plan_result, atf_suite_result * suite_result);
146 #define PLAN(__plan_name)\
147 static void plan_spec__##__plan_name(atf_plan * self); \
148 static atf_plan plan__##__plan_name = { \
149 .name = #__plan_name, \
155 atf_plan * __plan_name = & plan__##__plan_name; \
156 int main(int argc, char ** args) { \
159 atf_plan_result * result = atf_plan_result_new(__plan_name); \
160 plan_spec__##__plan_name(__plan_name); \
161 int rc = atf_plan_run(__plan_name, result); \
164 static void plan_spec__##__plan_name(atf_plan * self) \
167 #define plan_add(__suite) \
168 extern atf_suite * __suite; \
169 atf_plan_add(self, __suite)
171 #define plan_before(__func) \
172 atf_plan_before(self, __func)
174 #define plan_after(__func) \
175 atf_plan_after(self, __func)
181 void atf_assert(atf_test_result * test_result,
const char * exp,
const char * file,
int line);
183 void atf_assert_true(atf_test_result * test_result,
const char * exp,
const char * file,
int line);
184 void atf_assert_false(atf_test_result * test_result,
const char * exp,
const char * file,
int line);
186 void atf_assert_null(atf_test_result * test_result,
const char * exp,
const char * file,
int line);
187 void atf_assert_not_null(atf_test_result * test_result,
const char * exp,
const char * file,
int line);
189 void atf_assert_int_eq(atf_test_result * result,
const char * actual_exp, int64_t actual, int64_t expected,
const char * file,
int line);
190 void atf_assert_int_ne(atf_test_result * result,
const char * actual_exp, int64_t actual, int64_t expected,
const char * file,
int line);
192 void atf_assert_string_eq(atf_test_result * result,
const char * actual_exp,
const char * actual,
const char * expected,
const char * file,
int line);
194 void atf_assert_log(atf_test_result * result,
const char * exp,
const char * file,
int line,
const char * fmt, ...);
197 #define assert(EXP) \
198 if ( (EXP) != true ) return atf_assert(__result__, #EXP, __FILE__, __LINE__);
200 #define assert_true(EXP) \
201 if ( (EXP) != true ) return atf_assert_true(__result__, #EXP, __FILE__, __LINE__);
203 #define assert_false(EXP) \
204 if ( (EXP) == true ) return atf_assert_false(__result__, #EXP, __FILE__, __LINE__);
206 #define assert_null(EXP) \
207 if ( (EXP) != NULL ) return atf_assert_null(__result__, #EXP, __FILE__, __LINE__);
209 #define assert_not_null(EXP) \
210 if ( (EXP) == NULL ) return atf_assert_not_null(__result__, #EXP, __FILE__, __LINE__);
213 #define assert_int_eq(ACTUAL, EXPECTED) \
214 if ( (ACTUAL) != (EXPECTED) ) return atf_assert_int_eq(__result__, #ACTUAL, ACTUAL, EXPECTED, __FILE__, __LINE__);
216 #define assert_int_ne(ACTUAL, EXPECTED) \
217 if ( (ACTUAL) == (EXPECTED) ) return atf_assert_int_ne(__result__, #ACTUAL, ACTUAL, EXPECTED, __FILE__, __LINE__);
220 #define assert_string_eq(ACTUAL, EXPECTED) \
221 if ( strcmp(ACTUAL, EXPECTED) != 0 ) return atf_assert_string_eq(__result__, #ACTUAL, ACTUAL, EXPECTED, __FILE__, __LINE__);
224 #define assert_log(EXP, fmt, args ... ) \
225 if ( (EXP) == true ) return atf_assert_log(__result__, #EXP, __FILE__, __LINE__, fmt, ##args );
231 #define ATF_LOG_PREFIX " "
233 #define debug(fmt, args...) \
234 atf_log_line(stderr, "DEBUG", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ## args);
236 #define info(fmt, args...) \
237 atf_log(stderr, "INFO", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ## args);
239 #define warn(fmt, args...) \
240 atf_log(stderr, "WARN", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ## args);
242 #define error(fmt, args...) \
243 atf_log(stderr, "ERROR", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ## args);
245 void atf_log(FILE *
f,
const char * level,
const char * prefix,
const char * file,
int line,
const char * fmt, ...);
247 void atf_logv(FILE *
f,
const char * level,
const char * prefix,
const char * file,
int line,
const char * fmt, va_list ap);
249 void atf_log_line(FILE *
f,
const char * level,
const char * prefix,
const char * file,
int line,
const char * fmt, ...);
251 void atf_log_line(FILE *
f,
const char * level,
const char * prefix,
const char * file,
int line,
const char * fmt, ...);
atf_plan_result * atf_plan_result_add(atf_plan_result *plan_result, atf_suite_result *suite_result)
atf_test_result * tests[ATF_SUITE_TEST_MAX]
void atf_log(FILE *f, const char *level, const char *prefix, const char *file, int line, const char *fmt,...)
uint32_t atf_suite_size(atf_suite *suite)
atf_plan * atf_plan_before(atf_plan *plan, bool(*before)(atf_plan *plan))
atf_test_result * atf_test_result_new(atf_test *test)
bool(* after)(atf_suite *)
bool(* after)(atf_plan *)
atf_suite_result * atf_suite_run(atf_suite *suite)
void atf_logv(FILE *f, const char *level, const char *prefix, const char *file, int line, const char *fmt, va_list ap)
atf_plan * atf_plan_add(atf_plan *self, atf_suite *suite)
int atf_plan_run(atf_plan *self, atf_plan_result *result)
void atf_assert_not_null(atf_test_result *test_result, const char *exp, const char *file, int line)
void atf_assert_string_eq(atf_test_result *result, const char *actual_exp, const char *actual, const char *expected, const char *file, int line)
void(* init)(atf_suite *)
atf_suite * atf_suite_before(atf_suite *suite, bool(*before)(atf_suite *suite))
#define ATF_SUITE_TEST_MAX
atf_suite_result * atf_suite_result_new(atf_suite *suite)
void atf_assert_int_eq(atf_test_result *result, const char *actual_exp, int64_t actual, int64_t expected, const char *file, int line)
atf_suite * atf_suite_after(atf_suite *suite, bool(*after)(atf_suite *suite))
bool(* before)(atf_plan *)
#define ATF_PLAN_SUITE_MAX
atf_test_result * atf_test_run(atf_test *test)
void atf_assert_true(atf_test_result *test_result, const char *exp, const char *file, int line)
void atf_log_line(FILE *f, const char *level, const char *prefix, const char *file, int line, const char *fmt,...)
atf_plan_result * atf_plan_result_new(atf_plan *plan)
atf_suite * atf_suite_add(atf_suite *suite, atf_test *test)
void atf_assert_log(atf_test_result *result, const char *exp, const char *file, int line, const char *fmt,...)
void(* run)(atf_test *, atf_test_result *)
atf_plan * atf_plan_after(atf_plan *plan, bool(*after)(atf_plan *plan))
void atf_test_result_destroy(atf_test_result *test_result)
void atf_assert(atf_test_result *test_result, const char *exp, const char *file, int line)
atf_suite_result * suites[ATF_PLAN_SUITE_MAX]
atf_suite_result * atf_suite_result_add(atf_suite_result *suite_result, atf_test_result *test_result)
bool(* before)(atf_suite *)
atf_test * tests[ATF_SUITE_TEST_MAX]
void atf_assert_null(atf_test_result *test_result, const char *exp, const char *file, int line)
void atf_suite_result_print(atf_suite_result *suite_result)
void atf_suite_result_destroy(atf_suite_result *result)
void atf_plan_result_destroy(atf_plan_result *result)
atf_suite * suites[ATF_PLAN_SUITE_MAX]
void atf_assert_int_ne(atf_test_result *result, const char *actual_exp, int64_t actual, int64_t expected, const char *file, int line)
void atf_assert_false(atf_test_result *test_result, const char *exp, const char *file, int line)