• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4 
5 #include <check.h>
6 
7 #include <pulsecore/hook-list.h>
8 #include <pulsecore/log.h>
9 
func1(const char * hook_data,const char * call_data,const char * slot_data)10 static pa_hook_result_t func1(const char *hook_data, const char *call_data, const char *slot_data) {
11     pa_log("(func1) hook=%s call=%s slot=%s", hook_data, call_data, slot_data);
12     /* succeed when it runs to here */
13     fail_unless(1);
14     return PA_HOOK_OK;
15 }
16 
func2(const char * hook_data,const char * call_data,const char * slot_data)17 static pa_hook_result_t func2(const char *hook_data, const char *call_data, const char *slot_data) {
18     pa_log("(func2) hook=%s call=%s slot=%s", hook_data, call_data, slot_data);
19     /* succeed when it runs to here */
20     fail_unless(1);
21     return PA_HOOK_OK;
22 }
23 
START_TEST(hooklist_test)24 START_TEST (hooklist_test) {
25     pa_hook hook;
26     pa_hook_slot *slot;
27 
28     pa_hook_init(&hook, (void*) "hook");
29 
30     pa_hook_connect(&hook, PA_HOOK_LATE, (pa_hook_cb_t) func1, (void*) "slot1");
31     slot = pa_hook_connect(&hook, PA_HOOK_NORMAL, (pa_hook_cb_t) func2, (void*) "slot2");
32     pa_hook_connect(&hook, PA_HOOK_NORMAL, (pa_hook_cb_t) func1, (void*) "slot3");
33 
34     pa_hook_fire(&hook, (void*) "call1");
35 
36     pa_hook_slot_free(slot);
37 
38     pa_hook_fire(&hook, (void*) "call2");
39 
40     pa_hook_done(&hook);
41 }
42 END_TEST
43 
main(int argc,char * argv[])44 int main(int argc, char *argv[]) {
45     int failed = 0;
46     Suite *s;
47     TCase *tc;
48     SRunner *sr;
49 
50     s = suite_create("Hook List");
51     tc = tcase_create("hooklist");
52     tcase_add_test(tc, hooklist_test);
53     suite_add_tcase(s, tc);
54 
55     sr = srunner_create(s);
56     srunner_run_all(sr, CK_NORMAL);
57     failed = srunner_ntests_failed(sr);
58     srunner_free(sr);
59 
60     return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
61 }
62