check_list_add_end(s->tclst, tc);
}
-void _tcase_add_test(TCase * tc, TFun fn, const char *name, int _signal,
- int allowed_exit_value, int start, int end)
+void _tcase_add_test(TCase * tc, const TTest * ttest,
+ int _signal, int allowed_exit_value,
+ int start, int end)
{
TF *tf;
- if(tc == NULL || fn == NULL || name == NULL)
+ if(tc == NULL || ttest == NULL)
return;
tf = (TF *)emalloc(sizeof(TF)); /* freed in tcase_free */
- tf->fn = fn;
+ tf->ttest = ttest;
tf->loop_start = start;
tf->loop_end = end;
tf->signal = _signal; /* 0 means no signal expected */
tf->allowed_exit_value =
(WEXITSTATUS_MASK & allowed_exit_value); /* 0 is default successful exit */
- tf->name = name;
check_list_add_end(tc->tflst, tf);
}
*/
typedef struct Suite Suite;
+/**
+ * Type for a test, which wraps a test function
+ */
+typedef struct TTest {
+ const char *name;
+ TFun fn;
+ const char *file;
+ int line;
+} TTest;
+
/**
* Creates a test suite with the given name.
*
*
* @since 0.9.2
* */
-#define tcase_add_test_raise_signal(tc,tf,signal) \
- _tcase_add_test((tc),(tf),"" # tf "",(signal), 0, 0, 1)
+#define tcase_add_test_raise_signal(tc,ttest,signal) \
+ _tcase_add_test((tc),(ttest),(signal), 0, 0, 1)
/**
* Add a test function with an expected exit value to a test case
*
* @since 0.9.7
*/
-#define tcase_add_exit_test(tc, tf, expected_exit_value) \
- _tcase_add_test((tc),(tf),"" # tf "",0,(expected_exit_value),0,1)
+#define tcase_add_exit_test(tc, ttest, expected_exit_value) \
+ _tcase_add_test((tc),(ttest),0,(expected_exit_value),0,1)
/**
* Add a looping test function to a test case
*
* @since 0.9.4
*/
-#define tcase_add_loop_test(tc,tf,s,e) \
- _tcase_add_test((tc),(tf),"" # tf "",0,0,(s),(e))
+#define tcase_add_loop_test(tc,ttest,s,e) \
+ _tcase_add_test((tc),(ttest),0,0,(s),(e))
/**
* Add a looping test function with signal handling to a test case
*
* @since 0.9.5
*/
-#define tcase_add_loop_test_raise_signal(tc,tf,signal,s,e) \
- _tcase_add_test((tc),(tf),"" # tf "",(signal),0,(s),(e))
+#define tcase_add_loop_test_raise_signal(tc,ttest,signal,s,e) \
+ _tcase_add_test((tc),(ttest),(signal),0,(s),(e))
/**
* Add a looping test function with an expected exit value to a test case
*
* @since 0.9.7
*/
-#define tcase_add_loop_exit_test(tc,tf,expected_exit_value,s,e) \
- _tcase_add_test((tc),(tf),"" # tf "",0,(expected_exit_value),(s),(e))
+#define tcase_add_loop_exit_test(tc,ttest,expected_exit_value,s,e) \
+ _tcase_add_test((tc),(ttest),0,(expected_exit_value),(s),(e))
/* Add a test function to a test case
(function version -- use this when the macro won't work
*/
-CK_DLL_EXP void CK_EXPORT _tcase_add_test(TCase * tc, TFun tf,
- const char *fname, int _signal,
- int allowed_exit_value, int start,
- int end);
+CK_DLL_EXP void CK_EXPORT _tcase_add_test(TCase * tc, const TTest * ttest,
+ int _signal, int allowed_exit_value,
+ int start, int end);
/**
* Add unchecked fixture setup/teardown functions to a test case
* @since 0.6.0
*/
#define START_TEST(__testname)\
-static void __testname (int _i CK_ATTRIBUTE_UNUSED)\
-{\
- tcase_fn_start (""# __testname, __FILE__, __LINE__);
+static void __testname ## _fn (int _i CK_ATTRIBUTE_UNUSED);\
+static const TTest __testname ## _ttest = {""# __testname, __testname ## _fn, __FILE__, __LINE__};\
+static const TTest * __testname = & __testname ## _ttest;\
+static void __testname ## _fn (int _i CK_ATTRIBUTE_UNUSED)
/**
* End a unit test
*
* @since 0.6.0
*/
-#define END_TEST }
+#define END_TEST
/*
* Fail the test case unless expr is false
clock_gettime(check_get_clockid(), &ts_start);
if(0 == setjmp(error_jmp_buffer))
{
- tfun->fn(i);
+ tcase_fn_start(tfun->ttest->name, tfun->ttest->file, tfun->ttest->line);
+ tfun->ttest->fn(i);
}
clock_gettime(check_get_clockid(), &ts_end);
tcase_run_checked_teardown(tc);
- return receive_result_info_nofork(tc->name, tfun->name, i,
+ return receive_result_info_nofork(tc->name, tfun->ttest->name, i,
DIFF_IN_USEC(ts_start, ts_end));
}
tr = tcase_run_checked_setup(sr, tc);
free(tr);
clock_gettime(check_get_clockid(), &ts_start);
- tfun->fn(i);
+ tcase_fn_start(tfun->ttest->name, tfun->ttest->file, tfun->ttest->line);
+ tfun->ttest->fn(i);
clock_gettime(check_get_clockid(), &ts_end);
tcase_run_checked_teardown(tc);
send_duration_info(DIFF_IN_USEC(ts_start, ts_end));
killpg(pid, SIGKILL); /* Kill remaining processes. */
- return receive_result_info_fork(tc->name, tfun->name, i, status,
+ return receive_result_info_fork(tc->name, tfun->ttest->name, i, status,
tfun->signal, tfun->allowed_exit_value);
}