]> code.delx.au - pulseaudio/commitdiff
tests: modify utf8-test to use new 'check' test framework
authorDeng Zhengrong <dzrongg@gmail.com>
Tue, 17 Jul 2012 06:45:54 +0000 (14:45 +0800)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Sat, 4 Aug 2012 06:23:34 +0000 (08:23 +0200)
src/Makefile.am
src/tests/utf8-test.c

index 970db4e9770faabc9683b0ee7cf3595a47d90b0a..0132274855c92fa12bb51516c5dea3fa474f74b0 100644 (file)
@@ -320,9 +320,9 @@ thread_mainloop_test_LDADD = $(AM_LDADD) libpulsecore-@PA_MAJORMINOR@.la libpuls
 thread_mainloop_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
 
 utf8_test_SOURCES = tests/utf8-test.c
-utf8_test_CFLAGS = $(AM_CFLAGS)
+utf8_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
 utf8_test_LDADD = $(AM_LDADD) libpulse.la
-utf8_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+utf8_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
 
 format_test_SOURCES = tests/format-test.c
 format_test_CFLAGS = $(AM_CFLAGS)
index 6dc5b50dc2a17052af58b1e4296fb75a6549f080..22a58c08f001673bc97deb12d294cb6476022bd6 100644 (file)
@@ -1,24 +1,72 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <stdio.h>
 #include <assert.h>
+#include <check.h>
 
 #include <pulse/utf8.h>
 #include <pulse/xmalloc.h>
+#include <pulsecore/core-util.h>
 
-int main(int argc, char *argv[]) {
+START_TEST (utf8_valid) {
+    fail_unless(pa_utf8_valid("hallo") != NULL);
+    fail_unless(pa_utf8_valid("hallo\n") != NULL);
+    fail_unless(pa_utf8_valid("hüpfburg\n") == NULL);
+    fail_unless(pa_utf8_valid("hallo\n") != NULL);
+    fail_unless(pa_utf8_valid("hüpfburg\n") != NULL);
+}
+END_TEST
+
+START_TEST (utf8_filter) {
     char *c;
 
-    assert(pa_utf8_valid("hallo"));
-    assert(pa_utf8_valid("hallo\n"));
-    assert(!pa_utf8_valid("hüpfburg\n"));
-    assert(pa_utf8_valid("hallo\n"));
-    assert(pa_utf8_valid("hüpfburg\n"));
+    {
+        char res1[] = { 0x68, 0x5f, 0x70, 0x66, 0x62, 0x75, 0x72, 0x67, '\0' };
+        c = pa_utf8_filter("hüpfburg");
+        pa_log_debug("%s %s\n", res1, c);
+        fail_unless(pa_streq(c, res1));
+        pa_xfree(c);
+    }
+
+    {
+        char res2[] = { 0x68, 0xc3, 0xbc, 0x70, 0x66, 0x62, 0x75, 0x72, 0x67, '\0' };
+        c = pa_utf8_filter("hüpfburg");
+        fail_unless(pa_streq(c, res2));
+        pa_log_debug("%s %s\n", res2, c);
+        pa_xfree(c);
+    }
+
+    {
+        char res3[] = { 0x5f, 0x78, 0x6b, 0x6e, 0x5f, 0x72, 0x7a, 0x6d, 0x5f, 0x72, 0x7a, 0x65, 0x6c, 0x74, 0x5f, 0x72, 0x73, 0x7a, 0xdf, 0xb3, 0x5f, 0x64, 0x73, 0x6a, 0x6b, 0x66, 0x68, '\0' };
+        c = pa_utf8_filter("üxknärzmörzeltörszß³§dsjkfh");
+        pa_log_debug("%s %s\n", res3, c);
+        fail_unless(pa_streq(c, res3));
+        pa_xfree(c);
+    }
+}
+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("UTF8");
+    tc = tcase_create("utf8");
+    tcase_add_test(tc, utf8_valid);
+    tcase_add_test(tc, utf8_filter);
+    suite_add_tcase(s, tc);
 
-    fprintf(stderr, "LATIN1: %s\n", c = pa_utf8_filter("hüpfburg"));
-    pa_xfree(c);
-    fprintf(stderr, "UTF8: %sx\n", c = pa_utf8_filter("hüpfburg"));
-    pa_xfree(c);
-    fprintf(stderr, "LATIN1: %sx\n", c = pa_utf8_filter("üxknärzmörzeltörszß³§dsjkfh"));
-    pa_xfree(c);
+    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;
 }