2007-10-28 19:13:50 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-07-29 00:59:42 +08:00
|
|
|
#include <check.h>
|
|
|
|
|
|
2006-08-12 23:35:44 +00:00
|
|
|
#include <pulsecore/hook-list.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
|
|
|
|
|
2008-06-11 19:45:57 +00:00
|
|
|
static pa_hook_result_t func1(const char *hook_data, const char *call_data, const char *slot_data) {
|
2006-08-13 16:13:36 +00:00
|
|
|
pa_log("(func1) hook=%s call=%s slot=%s", hook_data, call_data, slot_data);
|
2012-07-29 00:59:42 +08:00
|
|
|
/* succeed when it runs to here */
|
|
|
|
|
fail_unless(1);
|
2006-08-12 23:35:44 +00:00
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-11 19:45:57 +00:00
|
|
|
static pa_hook_result_t func2(const char *hook_data, const char *call_data, const char *slot_data) {
|
2006-08-13 16:13:36 +00:00
|
|
|
pa_log("(func2) hook=%s call=%s slot=%s", hook_data, call_data, slot_data);
|
2012-07-29 00:59:42 +08:00
|
|
|
/* succeed when it runs to here */
|
|
|
|
|
fail_unless(1);
|
2006-08-12 23:35:44 +00:00
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-29 00:59:42 +08:00
|
|
|
START_TEST (hooklist_test) {
|
2006-08-13 01:43:34 +00:00
|
|
|
pa_hook hook;
|
|
|
|
|
pa_hook_slot *slot;
|
2006-08-12 23:35:44 +00:00
|
|
|
|
2006-08-13 16:13:36 +00:00
|
|
|
pa_hook_init(&hook, (void*) "hook");
|
2006-08-12 23:35:44 +00:00
|
|
|
|
2008-06-11 19:45:57 +00:00
|
|
|
pa_hook_connect(&hook, PA_HOOK_LATE, (pa_hook_cb_t) func1, (void*) "slot1");
|
|
|
|
|
slot = pa_hook_connect(&hook, PA_HOOK_NORMAL, (pa_hook_cb_t) func2, (void*) "slot2");
|
|
|
|
|
pa_hook_connect(&hook, PA_HOOK_NORMAL, (pa_hook_cb_t) func1, (void*) "slot3");
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-08-13 16:13:36 +00:00
|
|
|
pa_hook_fire(&hook, (void*) "call1");
|
2006-08-12 23:35:44 +00:00
|
|
|
|
2006-08-13 01:43:34 +00:00
|
|
|
pa_hook_slot_free(slot);
|
2006-08-13 16:13:36 +00:00
|
|
|
|
|
|
|
|
pa_hook_fire(&hook, (void*) "call2");
|
|
|
|
|
|
2008-08-03 16:21:08 +02:00
|
|
|
pa_hook_done(&hook);
|
2012-07-29 00:59:42 +08:00
|
|
|
}
|
|
|
|
|
END_TEST
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2012-07-29 00:59:42 +08:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
int failed = 0;
|
|
|
|
|
Suite *s;
|
|
|
|
|
TCase *tc;
|
|
|
|
|
SRunner *sr;
|
|
|
|
|
|
|
|
|
|
s = suite_create("Hook List");
|
|
|
|
|
tc = tcase_create("hooklist");
|
|
|
|
|
tcase_add_test(tc, hooklist_test);
|
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
|
|
sr = srunner_create(s);
|
|
|
|
|
srunner_run_all(sr, CK_NORMAL);
|
|
|
|
|
failed = srunner_ntests_failed(sr);
|
|
|
|
|
srunner_free(sr);
|
|
|
|
|
|
|
|
|
|
return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
2006-08-12 23:35:44 +00:00
|
|
|
}
|