Changed the ReportHook declaration syntax

This commit is contained in:
Snaipe 2015-02-02 16:34:29 +01:00
parent 4dd9f77c41
commit 5ca6f80e25
3 changed files with 14 additions and 22 deletions

View file

@ -35,19 +35,19 @@ typedef enum {
POST_EVERYTHING,
} e_report_status;
typedef void (*f_report_hook)(void *);
typedef void (*f_report_hook)();
# define HOOK_IDENTIFIER_(Suffix) HOOK_IDENTIFIER__(__LINE__, Suffix)
# define HOOK_IDENTIFIER__(Line, Suffix) HOOK_IDENTIFIER___(Line, Suffix)
# define HOOK_IDENTIFIER___(Line, Suffix) hook_l ## Line ## _ ## Suffix
# define HOOK_PROTOTYPE_ \
void HOOK_IDENTIFIER_(impl)(UNUSED void *data)
void HOOK_IDENTIFIER_(impl)
# define ReportHook(Kind) \
HOOK_PROTOTYPE_; \
HOOK_PROTOTYPE_(); \
SECTION_("criterion_hooks_" #Kind) \
const f_report_hook HOOK_IDENTIFIER_(func) = HOOK_IDENTIFIER_(impl); \
const f_report_hook HOOK_IDENTIFIER_(func) = HOOK_IDENTIFIER_(impl); \
HOOK_PROTOTYPE_
#endif /* !CRITERION_HOOKS_H_ */

View file

@ -13,23 +13,19 @@ Test(misc, simple) {
expect(1);
}
ReportHook(PRE_INIT) {
struct criterion_test *test = data;
ReportHook(PRE_INIT)(struct criterion_test *test) {
printf("testing %s in category %s\n", test->name, test->category);
}
ReportHook(POST_TEST) {
struct criterion_test_stats *stats = data;
ReportHook(POST_TEST)(struct criterion_test_stats *stats) {
printf("Asserts: [%d passed, %d failed, %d total]\n",
stats->passed, stats->failed, stats->passed + stats->failed);
}
ReportHook(PRE_EVERYTHING) {
ReportHook(PRE_EVERYTHING)() {
puts("criterion_init");
}
ReportHook(POST_EVERYTHING) {
ReportHook(POST_EVERYTHING)() {
puts("criterion_fini");
}

View file

@ -45,22 +45,18 @@ IMPL_CALL_REPORT_HOOKS(POST_TEST);
IMPL_CALL_REPORT_HOOKS(POST_FINI);
IMPL_CALL_REPORT_HOOKS(POST_EVERYTHING);
ReportHook(PRE_INIT) {
struct criterion_test *test = data;
ReportHook(PRE_INIT)(struct criterion_test *test) {
fprintf(stderr, "%s::%s: RUNNING\n", test->category, test->name);
}
ReportHook(POST_TEST) {
struct criterion_test_stats *stats = data;
ReportHook(POST_TEST)(struct criterion_test_stats *stats) {
int success = stats->failed == 0;
fprintf(stderr, "%s::%s: %s\n", stats->test->category, stats->test->name, success ? "SUCCESS" : "FAILURE");
}
ReportHook(PRE_TEST) {}
ReportHook(POST_FINI) {}
ReportHook(PRE_TEST)() {}
ReportHook(POST_FINI)() {}
ReportHook(PRE_EVERYTHING) {}
ReportHook(POST_EVERYTHING) {}
ReportHook(PRE_EVERYTHING)() {}
ReportHook(POST_EVERYTHING)() {}