From 4d5c85cfa2ff8f730d99d66a6df7ff4561e31601 Mon Sep 17 00:00:00 2001 From: Deng Zhengrong Date: Sat, 28 Jul 2012 18:07:28 +0800 Subject: [PATCH] tests: modify thread-mainloop-test to use 'check' framework --- src/Makefile.am | 4 ++-- src/tests/thread-mainloop-test.c | 39 +++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 7b0d057b1..d01c80d73 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -315,9 +315,9 @@ mainloop_test_LDADD = $(AM_LDADD) libpulse.la libpulsecommon-@PA_MAJORMINOR@.la mainloop_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS) thread_mainloop_test_SOURCES = tests/thread-mainloop-test.c -thread_mainloop_test_CFLAGS = $(AM_CFLAGS) +thread_mainloop_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS) thread_mainloop_test_LDADD = $(AM_LDADD) libpulsecore-@PA_MAJORMINOR@.la libpulse.la libpulsecommon-@PA_MAJORMINOR@.la -thread_mainloop_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) +thread_mainloop_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS) utf8_test_SOURCES = tests/utf8-test.c utf8_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS) diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 599f1959b..d2f6152bf 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -25,6 +25,8 @@ #include #include +#include + #include #include #include @@ -40,19 +42,21 @@ static void tcb(pa_mainloop_api *a, pa_time_event *e, const struct timeval *tv, fprintf(stderr, "TIME EVENT END\n"); } -int main(int argc, char *argv[]) { +START_TEST (thread_mainloop_test) { pa_mainloop_api *a; pa_threaded_mainloop *m; struct timeval tv; - pa_assert_se(m = pa_threaded_mainloop_new()); - pa_assert_se(a = pa_threaded_mainloop_get_api(m)); + m = pa_threaded_mainloop_new(); + fail_unless(m != NULL); + a = pa_threaded_mainloop_get_api(m); + fail_unless(m != NULL); - pa_assert_se(pa_threaded_mainloop_start(m) >= 0); + fail_unless(pa_threaded_mainloop_start(m) >= 0); pa_threaded_mainloop_lock(m); - pa_assert_se(!pa_threaded_mainloop_in_thread(m)); + fail_unless(!pa_threaded_mainloop_in_thread(m)); a->time_new(a, pa_timeval_rtstore(&tv, pa_rtclock_now() + 5 * PA_USEC_PER_SEC, TRUE), tcb, m); @@ -70,5 +74,28 @@ int main(int argc, char *argv[]) { pa_threaded_mainloop_stop(m); pa_threaded_mainloop_free(m); - return 0; +} +END_TEST + +int main(int argc, char *argv[]) { + int failed = 0; + Suite *s; + TCase *tc; + SRunner *sr; + + s = suite_create("Thread MainLoop"); + tc = tcase_create("threadmainloop"); + tcase_add_test(tc, thread_mainloop_test); + /* the default timeout is too small, + * set it to a reasonable large one. + */ + tcase_set_timeout(tc, 60 * 60); + 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; }