summaryrefslogtreecommitdiffstats
path: root/src/tests/mainloop-test.c
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2006-02-16 19:19:58 +0000
committerPierre Ossman <ossman@cendio.se>2006-02-16 19:19:58 +0000
commite205b25d65ccb380fa158711e24d55b6de5d9bc1 (patch)
tree470b4ced153c9ff18b8e35deb05c7a95efc838fc /src/tests/mainloop-test.c
parent5b881e62282f26b353635120935d114e0c7c3f3c (diff)
Reorganised the source tree. We now have src/ with a couple of subdirs:
* daemon/ - Contains the files specific to the polypaudio daemon. * modules/ - All loadable modules. * polyp/ - Files that are part of the public, application interface or are only used in libpolyp. * polypcore/ - All other shared files. * tests/ - Test programs. * utils/ - Utility programs. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@487 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/tests/mainloop-test.c')
-rw-r--r--src/tests/mainloop-test.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c
new file mode 100644
index 00000000..f62c9693
--- /dev/null
+++ b/src/tests/mainloop-test.c
@@ -0,0 +1,146 @@
+/* $Id$ */
+
+/***
+ This file is part of polypaudio.
+
+ polypaudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ polypaudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with polypaudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <assert.h>
+
+#include <polypcore/util.h>
+#include <polypcore/gccmacro.h>
+
+#ifdef GLIB_MAIN_LOOP
+
+#include <glib.h>
+#include <polyp/glib-mainloop.h>
+
+static GMainLoop* glib_main_loop = NULL;
+
+#if GLIB_MAJOR_VERSION >= 2
+#define GLIB20
+#else
+#undef GLIB20
+#endif
+
+
+#else /* GLIB_MAIN_LOOP */
+#include <polyp/mainloop.h>
+#endif /* GLIB_MAIN_LOOP */
+
+static pa_defer_event *de;
+
+static void iocb(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
+ unsigned char c;
+ read(fd, &c, sizeof(c));
+ fprintf(stderr, "IO EVENT: %c\n", c < 32 ? '.' : c);
+ a->defer_enable(de, 1);
+}
+
+static void dcb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) {
+ fprintf(stderr, "DEFER EVENT\n");
+ a->defer_enable(e, 0);
+}
+
+static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) {
+ fprintf(stderr, "TIME EVENT\n");
+
+#if defined(GLIB_MAIN_LOOP) && defined(GLIB20)
+ g_main_loop_quit(glib_main_loop);
+#elif defined(GLIB_MAIN_LOOP)
+ g_main_quit(glib_main_loop);
+#else
+ a->quit(a, 0);
+#endif
+}
+
+int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
+ pa_mainloop_api *a;
+ pa_io_event *ioe;
+ pa_time_event *te;
+ struct timeval tv;
+
+#ifdef GLIB_MAIN_LOOP
+ pa_glib_mainloop *g;
+
+#ifdef GLIB20
+ glib_main_loop = g_main_loop_new(NULL, FALSE);
+ assert(glib_main_loop);
+
+ g = pa_glib_mainloop_new(NULL);
+#else /* GLIB20 */
+ glib_main_loop = g_main_new(FALSE);
+ assert(glib_main_loop);
+
+ g = pa_glib_mainloop_new();
+#endif /* GLIB20 */
+ assert(g);
+
+ a = pa_glib_mainloop_get_api(g);
+ assert(a);
+#else /* GLIB_MAIN_LOOP */
+ pa_mainloop *m;
+
+ m = pa_mainloop_new();
+ assert(m);
+
+ a = pa_mainloop_get_api(m);
+ assert(a);
+#endif /* GLIB_MAIN_LOOP */
+
+ ioe = a->io_new(a, 0, PA_IO_EVENT_INPUT, iocb, NULL);
+ assert(ioe);
+
+ de = a->defer_new(a, dcb, NULL);
+ assert(de);
+
+ pa_gettimeofday(&tv);
+ tv.tv_sec += 10;
+ te = a->time_new(a, &tv, tcb, NULL);
+
+#if defined(GLIB_MAIN_LOOP) && defined(GLIB20)
+ g_main_loop_run(glib_main_loop);
+#elif defined(GLIB_MAIN_LOOP)
+ g_main_run(glib_main_loop);
+#else
+ pa_mainloop_run(m, NULL);
+#endif
+
+ a->time_free(te);
+ a->defer_free(de);
+ a->io_free(ioe);
+
+#ifdef GLIB_MAIN_LOOP
+ pa_glib_mainloop_free(g);
+#ifdef GLIB20
+ g_main_loop_unref(glib_main_loop);
+#else
+ g_main_destroy(glib_main_loop);
+#endif
+#else
+ pa_mainloop_free(m);
+#endif
+
+ return 0;
+}