[pulseaudio-discuss] [PATCH v2 4/6] tests: modify mainloop-test to use new 'check' framework

Deng Zhengrong dzrongg at gmail.com
Mon Jul 16 23:45:53 PDT 2012


---
 src/Makefile.am           |    8 ++++----
 src/tests/mainloop-test.c |   37 ++++++++++++++++++++++++++++---------
 2 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index c26d6e1..27f67fa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -310,9 +310,9 @@ check-daemon:
 	$(MAKE) check TESTS="$(TESTS_daemon)"
 
 mainloop_test_SOURCES = tests/mainloop-test.c
-mainloop_test_CFLAGS = $(AM_CFLAGS)
+mainloop_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
 mainloop_test_LDADD = $(AM_LDADD) libpulse.la libpulsecommon- at PA_MAJORMINOR@.la
-mainloop_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+mainloop_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
 
 thread_mainloop_test_SOURCES = tests/thread-mainloop-test.c
 thread_mainloop_test_CFLAGS = $(AM_CFLAGS)
@@ -435,9 +435,9 @@ cpulimit_test2_LDADD = $(AM_LDADD) libpulsecore- at PA_MAJORMINOR@.la libpulse.la l
 cpulimit_test2_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
 
 mainloop_test_glib_SOURCES = $(mainloop_test_SOURCES)
-mainloop_test_glib_CFLAGS = $(mainloop_test_CFLAGS) $(GLIB20_CFLAGS) -DGLIB_MAIN_LOOP
+mainloop_test_glib_CFLAGS = $(mainloop_test_CFLAGS) $(LIBCHECK_CFLAGS) $(GLIB20_CFLAGS) -DGLIB_MAIN_LOOP
 mainloop_test_glib_LDADD = $(mainloop_test_LDADD) $(GLIB20_LIBS) libpulse-mainloop-glib.la
-mainloop_test_glib_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+mainloop_test_glib_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
 
 memblockq_test_SOURCES = tests/memblockq-test.c
 memblockq_test_CFLAGS = $(AM_CFLAGS)
diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c
index ab23de4..3b062f8 100644
--- a/src/tests/mainloop-test.c
+++ b/src/tests/mainloop-test.c
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include <sys/time.h>
 #include <assert.h>
+#include <check.h>
 
 #include <pulse/rtclock.h>
 #include <pulse/timeval.h>
@@ -67,7 +68,7 @@ static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, v
 #endif
 }
 
-int main(int argc, char *argv[]) {
+START_TEST (mainloop_test) {
     pa_mainloop_api *a;
     pa_io_event *ioe;
     pa_time_event *te;
@@ -77,28 +78,28 @@ int main(int argc, char *argv[]) {
     pa_glib_mainloop *g;
 
     glib_main_loop = g_main_loop_new(NULL, FALSE);
-    assert(glib_main_loop);
+    fail_if(!glib_main_loop);
 
     g = pa_glib_mainloop_new(NULL);
-    assert(g);
+    fail_if(!g);
 
     a = pa_glib_mainloop_get_api(g);
-    assert(a);
+    fail_if(!a);
 #else /* GLIB_MAIN_LOOP */
     pa_mainloop *m;
 
     m = pa_mainloop_new();
-    assert(m);
+    fail_if(!m);
 
     a = pa_mainloop_get_api(m);
-    assert(a);
+    fail_if(!a);
 #endif /* GLIB_MAIN_LOOP */
 
     ioe = a->io_new(a, 0, PA_IO_EVENT_INPUT, iocb, NULL);
-    assert(ioe);
+    fail_if(!ioe);
 
     de = a->defer_new(a, dcb, NULL);
-    assert(de);
+    fail_if(!de);
 
     te = a->time_new(a, pa_timeval_rtstore(&tv, pa_rtclock_now() + 2 * PA_USEC_PER_SEC, TRUE), tcb, NULL);
 
@@ -118,6 +119,24 @@ int main(int argc, char *argv[]) {
 #else
     pa_mainloop_free(m);
 #endif
+}
+END_TEST
 
-    return 0;
+int main(int argc, char *argv[]) {
+    int failed = 0;
+    Suite *s;
+    TCase *tc;
+    SRunner *sr;
+
+    s = suite_create("MainLoop");
+    tc = tcase_create("mainloop");
+    tcase_add_test(tc, mainloop_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;
 }
-- 
1.7.7.6



More information about the pulseaudio-discuss mailing list