13 #define ATF_PLAN_SUITE_MAX 128
14 #define ATF_SUITE_TEST_MAX 128
26 void (*
run)(atf_test *, atf_test_result *);
41 #define TEST(__test_name, __test_desc) \
42 static void test_spec__##__test_name(atf_test *, atf_test_result *); \
43 static atf_test test__##__test_name = { \
44 .name = #__test_name, \
45 .desc = __test_desc, \
46 .run = test_spec__##__test_name \
48 atf_test * __test_name = & test__##__test_name; \
49 static void test_spec__##__test_name(atf_test * self, atf_test_result * __result__)
63 void (*
init)(atf_suite *);
64 bool (*
before)(atf_suite *);
65 bool (*
after)(atf_suite *);
75 atf_suite *
atf_suite_add(atf_suite * suite, atf_test * test);
79 atf_suite *
atf_suite_after(atf_suite * suite,
bool (* after)(atf_suite * suite));
80 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);
87 #define SUITE(__suite_name, __suite_desc) \
88 static void suite_spec__##__suite_name(atf_suite *); \
89 static atf_suite suite__##__suite_name = { \
90 .name = #__suite_name, \
91 .desc = __suite_desc, \
94 .init = suite_spec__##__suite_name, \
98 atf_suite * __suite_name = & suite__##__suite_name; \
99 static void suite_spec__##__suite_name(atf_suite * self)
101 #define suite_add(__test) \
102 atf_suite_add(self, __test)
104 #define suite_before(__func) \
105 atf_suite_before(self, __func)
107 #define suite_after(__func) \
108 atf_suite_after(self, __func)
122 bool (*
before)(atf_plan *);
123 bool (*
after)(atf_plan *);
132 atf_plan *
atf_plan_add(atf_plan *
self, atf_suite * suite);
133 int atf_plan_run(atf_plan *
self, atf_plan_result * result);
135 atf_plan *
atf_plan_after(atf_plan * plan,
bool (* after)(atf_plan * plan));
136 atf_plan *
atf_plan_before(atf_plan * plan,
bool (* before)(atf_plan * plan));
138 atf_plan_result *
atf_plan_result_add(atf_plan_result * plan_result, atf_suite_result * suite_result);
140 #define PLAN(__plan_name)\
141 static void plan_spec__##__plan_name(atf_plan * self); \
142 static atf_plan plan__##__plan_name = { \
143 .name = #__plan_name, \
149 atf_plan * __plan_name = & plan__##__plan_name; \
150 int main(int argc, char ** args) { \
151 atf_plan atfp = {#__plan_name}; \
152 atf_plan_result result = { \
154 .suites = { NULL }, \
157 plan_spec__##__plan_name(__plan_name); \
158 return atf_plan_run(__plan_name, &result); \
160 static void plan_spec__##__plan_name(atf_plan * self) \
163 #define plan_add(__suite) \
164 extern atf_suite * __suite; \
165 atf_plan_add(self, __suite)
167 #define plan_before(__func) \
168 atf_plan_before(self, __func)
170 #define plan_after(__func) \
171 atf_plan_after(self, __func)
177 void atf_assert(atf_test_result * test_result,
const char * exp,
const char * file,
int line);
179 void atf_assert_true(atf_test_result * test_result,
const char * exp,
const char * file,
int line);
180 void atf_assert_false(atf_test_result * test_result,
const char * exp,
const char * file,
int line);
182 void atf_assert_null(atf_test_result * test_result,
const char * exp,
const char * file,
int line);
183 void atf_assert_not_null(atf_test_result * test_result,
const char * exp,
const char * file,
int line);
185 void atf_assert_int_eq(atf_test_result * result,
const char * actual_exp, int64_t actual, int64_t expected,
const char * file,
int line);
186 void atf_assert_int_ne(atf_test_result * result,
const char * actual_exp, int64_t actual, int64_t expected,
const char * file,
int line);
188 void atf_assert_string_eq(atf_test_result * result,
const char * actual_exp,
const char * actual,
const char * expected,
const char * file,
int line);
190 void atf_assert_log(atf_test_result * result,
const char * exp,
const char * file,
int line,
const char * fmt, ...);
193 #define assert(EXP) \
194 if ( (EXP) != true ) return atf_assert(__result__, #EXP, __FILE__, __LINE__);
196 #define assert_true(EXP) \
197 if ( (EXP) != true ) return atf_assert_true(__result__, #EXP, __FILE__, __LINE__);
199 #define assert_false(EXP) \
200 if ( (EXP) == true ) return atf_assert_false(__result__, #EXP, __FILE__, __LINE__);
202 #define assert_null(EXP) \
203 if ( (EXP) != NULL ) return atf_assert_null(__result__, #EXP, __FILE__, __LINE__);
205 #define assert_not_null(EXP) \
206 if ( (EXP) == NULL ) return atf_assert_not_null(__result__, #EXP, __FILE__, __LINE__);
209 #define assert_int_eq(ACTUAL, EXPECTED) \
210 if ( (ACTUAL) != (EXPECTED) ) return atf_assert_int_eq(__result__, #ACTUAL, ACTUAL, EXPECTED, __FILE__, __LINE__);
212 #define assert_int_ne(ACTUAL, EXPECTED) \
213 if ( (ACTUAL) == (EXPECTED) ) return atf_assert_int_ne(__result__, #ACTUAL, ACTUAL, EXPECTED, __FILE__, __LINE__);
216 #define assert_string_eq(ACTUAL, EXPECTED) \
217 if ( strcmp(ACTUAL, EXPECTED) != 0 ) return atf_assert_string_eq(__result__, #ACTUAL, ACTUAL, EXPECTED, __FILE__, __LINE__);
220 #define assert_log(EXP, fmt, args ... ) \
221 if ( (EXP) == true ) return atf_assert_log(__result__, #EXP, __FILE__, __LINE__, fmt, ##args );
227 #define ATF_LOG_PREFIX " "
229 #define debug(fmt, args...) \
230 atf_log_line(stderr, "DEBUG", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ## args);
232 #define info(fmt, args...) \
233 atf_log(stderr, "INFO", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ## args);
235 #define warn(fmt, args...) \
236 atf_log(stderr, "WARN", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ## args);
238 #define error(fmt, args...) \
239 atf_log(stderr, "ERROR", ATF_LOG_PREFIX, __FILE__, __LINE__, fmt, ## args);
241 void atf_log(FILE *
f,
const char * level,
const char * prefix,
const char * file,
int line,
const char * fmt, ...);
243 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)
void atf_test_result_free(atf_test_result *test_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))
#define ATF_PLAN_SUITE_MAX
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)
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))
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 *)
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_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_assert(atf_test_result *test_result, const char *exp, const char *file, int line)
#define ATF_SUITE_TEST_MAX
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 *)
void atf_suite_result_free(atf_suite_result *suite_result)
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)
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)