]> code.delx.au - pulseaudio/blob - src/tests/asyncmsgq-test.c
sink, source: Add hooks for mute changes
[pulseaudio] / src / tests / asyncmsgq-test.c
1 /***
2 This file is part of PulseAudio.
3
4 PulseAudio is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License,
7 or (at your option) any later version.
8
9 PulseAudio is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with PulseAudio; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 USA.
18 ***/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27
28 #include <check.h>
29
30 #include <pulsecore/asyncmsgq.h>
31 #include <pulsecore/thread.h>
32 #include <pulsecore/log.h>
33 #include <pulsecore/macro.h>
34
35 enum {
36 OPERATION_A,
37 OPERATION_B,
38 OPERATION_C,
39 QUIT
40 };
41
42 static void the_thread(void *_q) {
43 pa_asyncmsgq *q = _q;
44 int quit = 0;
45
46 do {
47 int code = 0;
48
49 pa_assert_se(pa_asyncmsgq_get(q, NULL, &code, NULL, NULL, NULL, 1) == 0);
50
51 switch (code) {
52
53 case OPERATION_A:
54 pa_log_info("Operation A");
55 break;
56
57 case OPERATION_B:
58 pa_log_info("Operation B");
59 break;
60
61 case OPERATION_C:
62 pa_log_info("Operation C");
63 break;
64
65 case QUIT:
66 pa_log_info("quit");
67 quit = 1;
68 break;
69 }
70
71 pa_asyncmsgq_done(q, 0);
72
73 } while (!quit);
74 }
75
76 START_TEST (asyncmsgq_test) {
77 pa_asyncmsgq *q;
78 pa_thread *t;
79
80 q = pa_asyncmsgq_new(0);
81 fail_unless(q != NULL);
82
83 t = pa_thread_new("test", the_thread, q);
84 fail_unless(t != NULL);
85
86 pa_log_info("Operation A post");
87 pa_asyncmsgq_post(q, NULL, OPERATION_A, NULL, 0, NULL, NULL);
88
89 pa_thread_yield();
90
91 pa_log_info("Operation B post");
92 pa_asyncmsgq_post(q, NULL, OPERATION_B, NULL, 0, NULL, NULL);
93
94 pa_thread_yield();
95
96 pa_log_info("Operation C send");
97 pa_asyncmsgq_send(q, NULL, OPERATION_C, NULL, 0, NULL);
98
99 pa_thread_yield();
100
101 pa_log_info("Quit post");
102 pa_asyncmsgq_post(q, NULL, QUIT, NULL, 0, NULL, NULL);
103
104 pa_thread_free(t);
105
106 pa_asyncmsgq_unref(q);
107 }
108 END_TEST
109
110 int main(int argc, char *argv[]) {
111 int failed = 0;
112 Suite *s;
113 TCase *tc;
114 SRunner *sr;
115
116 s = suite_create("Async Message Queue");
117 tc = tcase_create("asyncmsgq");
118 tcase_add_test(tc, asyncmsgq_test);
119 suite_add_tcase(s, tc);
120
121 sr = srunner_create(s);
122 srunner_run_all(sr, CK_NORMAL);
123 failed = srunner_ntests_failed(sr);
124 srunner_free(sr);
125
126 return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
127 }