tests: modify proplist-test to use 'check' framework

This commit is contained in:
Deng Zhengrong 2012-07-28 22:56:43 +08:00 committed by Arun Raghavan
parent 67df8223b0
commit d10009fc97
2 changed files with 40 additions and 18 deletions

View file

@ -481,8 +481,8 @@ smoother_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
proplist_test_SOURCES = tests/proplist-test.c proplist_test_SOURCES = tests/proplist-test.c
proplist_test_LDADD = $(AM_LDADD) libpulsecore-@PA_MAJORMINOR@.la libpulse.la libpulsecommon-@PA_MAJORMINOR@.la proplist_test_LDADD = $(AM_LDADD) libpulsecore-@PA_MAJORMINOR@.la libpulse.la libpulsecommon-@PA_MAJORMINOR@.la
proplist_test_CFLAGS = $(AM_CFLAGS) proplist_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
proplist_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) proplist_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
cpu_test_SOURCES = tests/cpu-test.c cpu_test_SOURCES = tests/cpu-test.c
cpu_test_LDADD = $(AM_LDADD) libpulsecore-@PA_MAJORMINOR@.la libpulse.la libpulsecommon-@PA_MAJORMINOR@.la cpu_test_LDADD = $(AM_LDADD) libpulsecore-@PA_MAJORMINOR@.la libpulse.la libpulsecommon-@PA_MAJORMINOR@.la

View file

@ -23,36 +23,35 @@
#include <stdio.h> #include <stdio.h>
#include <check.h>
#include <pulse/proplist.h> #include <pulse/proplist.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
int main(int argc, char*argv[]) { START_TEST (proplist_test) {
pa_modargs *ma; pa_modargs *ma;
pa_proplist *a, *b, *c, *d; pa_proplist *a, *b, *c, *d;
char *s, *t, *u, *v; char *s, *t, *u, *v;
const char *text; const char *text;
const char *x[] = { "foo", NULL }; const char *x[] = { "foo", NULL };
if (!getenv("MAKE_CHECK"))
pa_log_set_level(PA_LOG_DEBUG);
a = pa_proplist_new(); a = pa_proplist_new();
pa_assert_se(pa_proplist_sets(a, PA_PROP_MEDIA_TITLE, "Brandenburgische Konzerte") == 0); fail_unless(pa_proplist_sets(a, PA_PROP_MEDIA_TITLE, "Brandenburgische Konzerte") == 0);
pa_assert_se(pa_proplist_sets(a, PA_PROP_MEDIA_ARTIST, "Johann Sebastian Bach") == 0); fail_unless(pa_proplist_sets(a, PA_PROP_MEDIA_ARTIST, "Johann Sebastian Bach") == 0);
b = pa_proplist_new(); b = pa_proplist_new();
pa_assert_se(pa_proplist_sets(b, PA_PROP_MEDIA_TITLE, "Goldbergvariationen") == 0); fail_unless(pa_proplist_sets(b, PA_PROP_MEDIA_TITLE, "Goldbergvariationen") == 0);
pa_assert_se(pa_proplist_set(b, PA_PROP_MEDIA_ICON, "\0\1\2\3\4\5\6\7", 8) == 0); fail_unless(pa_proplist_set(b, PA_PROP_MEDIA_ICON, "\0\1\2\3\4\5\6\7", 8) == 0);
pa_proplist_update(a, PA_UPDATE_MERGE, b); pa_proplist_update(a, PA_UPDATE_MERGE, b);
pa_assert_se(!pa_proplist_gets(a, PA_PROP_MEDIA_ICON)); fail_unless(!pa_proplist_gets(a, PA_PROP_MEDIA_ICON));
pa_log_debug("%s", pa_strnull(pa_proplist_gets(a, PA_PROP_MEDIA_TITLE))); pa_log_debug("%s", pa_strnull(pa_proplist_gets(a, PA_PROP_MEDIA_TITLE)));
pa_assert_se(pa_proplist_unset(b, PA_PROP_MEDIA_TITLE) == 0); fail_unless(pa_proplist_unset(b, PA_PROP_MEDIA_TITLE) == 0);
s = pa_proplist_to_string(a); s = pa_proplist_to_string(a);
t = pa_proplist_to_string(b); t = pa_proplist_to_string(b);
@ -60,7 +59,7 @@ int main(int argc, char*argv[]) {
c = pa_proplist_from_string(s); c = pa_proplist_from_string(s);
u = pa_proplist_to_string(c); u = pa_proplist_to_string(c);
pa_assert_se(pa_streq(s, u)); fail_unless(pa_streq(s, u));
pa_xfree(s); pa_xfree(s);
pa_xfree(t); pa_xfree(t);
@ -84,16 +83,39 @@ int main(int argc, char*argv[]) {
pa_log_debug("%s", v); pa_log_debug("%s", v);
pa_xfree(v); pa_xfree(v);
pa_assert_se(ma = pa_modargs_new("foo='foobar=waldo foo2=\"lj\\\"dhflh\" foo3=\"kjlskj\\'\"'", x)); ma = pa_modargs_new("foo='foobar=waldo foo2=\"lj\\\"dhflh\" foo3=\"kjlskj\\'\"'", x);
pa_assert_se(a = pa_proplist_new()); fail_unless(ma != NULL);
a = pa_proplist_new();
fail_unless(a != NULL);
pa_assert_se(pa_modargs_get_proplist(ma, "foo", a, PA_UPDATE_REPLACE) >= 0); fail_unless(pa_modargs_get_proplist(ma, "foo", a, PA_UPDATE_REPLACE) >= 0);
pa_log_debug("%s", v = pa_proplist_to_string(a)); pa_log_debug("%s", v = pa_proplist_to_string(a));
pa_xfree(v); pa_xfree(v);
pa_proplist_free(a); pa_proplist_free(a);
pa_modargs_free(ma); pa_modargs_free(ma);
}
return 0; END_TEST
int main(int argc, char *argv[]) {
int failed = 0;
Suite *s;
TCase *tc;
SRunner *sr;
if (!getenv("MAKE_CHECK"))
pa_log_set_level(PA_LOG_DEBUG);
s = suite_create("Property List");
tc = tcase_create("propertylist");
tcase_add_test(tc, proplist_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;
} }