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

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


---
 src/Makefile.am          |    4 ++--
 src/tests/strlist-test.c |   32 ++++++++++++++++++++++++++++++--
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 5c5e9e3..50baddf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -405,9 +405,9 @@ extended_test_CFLAGS = $(AM_CFLAGS)
 extended_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
 
 strlist_test_SOURCES = tests/strlist-test.c
-strlist_test_CFLAGS = $(AM_CFLAGS)
+strlist_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
 strlist_test_LDADD = $(AM_LDADD) $(WINSOCK_LIBS) libpulsecore- at PA_MAJORMINOR@.la libpulse.la libpulsecommon- at PA_MAJORMINOR@.la
-strlist_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+strlist_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
 
 close_test_SOURCES = tests/close-test.c
 close_test_CFLAGS = $(AM_CFLAGS)
diff --git a/src/tests/strlist-test.c b/src/tests/strlist-test.c
index 86f4f07..6a4f4bb 100644
--- a/src/tests/strlist-test.c
+++ b/src/tests/strlist-test.c
@@ -1,10 +1,16 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <stdio.h>
+#include <check.h>
 
 #include <pulse/xmalloc.h>
 
 #include <pulsecore/strlist.h>
+#include <pulsecore/core-util.h>
 
-int main(int argc, char* argv[]) {
+START_TEST (strlist_test) {
     char *t, *u;
     pa_strlist *l = NULL;
 
@@ -18,25 +24,47 @@ int main(int argc, char* argv[]) {
     pa_strlist_free(l);
 
     fprintf(stderr, "1: %s\n", t);
+    fail_unless(pa_streq(t, "a b c d e"));
 
     l = pa_strlist_parse(t);
     pa_xfree(t);
 
     t = pa_strlist_tostring(l);
     fprintf(stderr, "2: %s\n", t);
+    fail_unless(pa_streq(t, "a b c d e"));
     pa_xfree(t);
 
     l = pa_strlist_pop(l, &u);
     fprintf(stderr, "3: %s\n", u);
+    fail_unless(pa_streq(u, "a"));
     pa_xfree(u);
 
     l = pa_strlist_remove(l, "c");
 
     t = pa_strlist_tostring(l);
     fprintf(stderr, "4: %s\n", t);
+    fail_unless(pa_streq(t, "b d e"));
     pa_xfree(t);
 
     pa_strlist_free(l);
+}
+END_TEST
+
+int main(int argc, char *argv[]) {
+    int failed = 0;
+    Suite *s;
+    TCase *tc;
+    SRunner *sr;
+
+    s = suite_create("StrList");
+    tc = tcase_create("strlist");
+    tcase_add_test(tc, strlist_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 0;
+    return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-- 
1.7.7.6



More information about the pulseaudio-discuss mailing list