[pulseaudio-discuss] [PATCH v2 5/6] tests: modify utf8-test to use new 'check' test framework
Deng Zhengrong
dzrongg at gmail.com
Mon Jul 16 23:45:54 PDT 2012
---
src/Makefile.am | 4 +-
src/tests/utf8-test.c | 68 +++++++++++++++++++++++++++++++++++++++---------
2 files changed, 57 insertions(+), 15 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 27f67fa..5c5e9e3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -320,9 +320,9 @@ thread_mainloop_test_LDADD = $(AM_LDADD) libpulsecore- at 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)
diff --git a/src/tests/utf8-test.c b/src/tests/utf8-test.c
index 6dc5b50..035fe64 100644
--- a/src/tests/utf8-test.c
+++ b/src/tests/utf8-test.c
@@ -1,24 +1,66 @@
+#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");
+ 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_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");
+ 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;
+
+ 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;
}
--
1.7.7.6
More information about the pulseaudio-discuss
mailing list