tests: modify thread-mainloop-test to use 'check' framework

This commit is contained in:
Deng Zhengrong 2012-07-28 18:07:28 +08:00 committed by Arun Raghavan
parent ca104d3467
commit 4d5c85cfa2
2 changed files with 35 additions and 8 deletions

View file

@ -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)

View file

@ -25,6 +25,8 @@
#include <unistd.h>
#include <stdio.h>
#include <check.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h>
#include <pulse/util.h>
@ -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;
}