sink, source: Really set the fixed latency in set_fixed_latency_within_thread(),...
[platform/upstream/pulseaudio.git] / src / tests / rtpoll-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 <check.h>
25 #include <signal.h>
26
27 #include <pulsecore/poll.h>
28 #include <pulsecore/log.h>
29 #include <pulsecore/rtpoll.h>
30
31 static int before(pa_rtpoll_item *i) {
32     pa_log("before");
33     return 0;
34 }
35
36 static void after(pa_rtpoll_item *i) {
37     pa_log("after");
38 }
39
40 static int worker(pa_rtpoll_item *w) {
41     pa_log("worker");
42     return 0;
43 }
44
45 START_TEST (rtpoll_test) {
46     pa_rtpoll *p;
47     pa_rtpoll_item *i, *w;
48     struct pollfd *pollfd;
49
50     p = pa_rtpoll_new();
51
52     i = pa_rtpoll_item_new(p, PA_RTPOLL_EARLY, 1);
53     pa_rtpoll_item_set_before_callback(i, before);
54     pa_rtpoll_item_set_after_callback(i, after);
55
56     pollfd = pa_rtpoll_item_get_pollfd(i, NULL);
57     pollfd->fd = 0;
58     pollfd->events = POLLIN;
59
60     w = pa_rtpoll_item_new(p, PA_RTPOLL_NORMAL, 0);
61     pa_rtpoll_item_set_before_callback(w, worker);
62
63     pa_rtpoll_set_timer_relative(p, 10000000); /* 10 s */
64
65     pa_rtpoll_run(p, 1);
66
67     pa_rtpoll_item_free(i);
68
69     i = pa_rtpoll_item_new(p, PA_RTPOLL_EARLY, 1);
70     pa_rtpoll_item_set_before_callback(i, before);
71     pa_rtpoll_item_set_after_callback(i, after);
72
73     pollfd = pa_rtpoll_item_get_pollfd(i, NULL);
74     pollfd->fd = 0;
75     pollfd->events = POLLIN;
76
77     pa_rtpoll_run(p, 1);
78
79     pa_rtpoll_item_free(i);
80
81     pa_rtpoll_item_free(w);
82
83     pa_rtpoll_free(p);
84 }
85 END_TEST
86
87 int main(int argc, char *argv[]) {
88     int failed = 0;
89     Suite *s;
90     TCase *tc;
91     SRunner *sr;
92
93     s = suite_create("RT Poll");
94     tc = tcase_create("rtpoll");
95     tcase_add_test(tc, rtpoll_test);
96     /* the default timeout is too small,
97      * set it to a reasonable large one.
98      */
99     tcase_set_timeout(tc, 60 * 60);
100     suite_add_tcase(s, tc);
101
102     sr = srunner_create(s);
103     srunner_run_all(sr, CK_NORMAL);
104     failed = srunner_ntests_failed(sr);
105     srunner_free(sr);
106
107     return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
108 }