• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4 
5 #include <stdio.h>
6 #include <assert.h>
7 #include <check.h>
8 
9 #include <pulse/utf8.h>
10 #include <pulse/xmalloc.h>
11 #include <pulsecore/core-util.h>
12 
START_TEST(utf8_valid)13 START_TEST (utf8_valid) {
14     fail_unless(pa_utf8_valid("hallo") != NULL);
15     fail_unless(pa_utf8_valid("hallo\n") != NULL);
16     fail_unless(pa_utf8_valid("h�pfburg\n") == NULL);
17     fail_unless(pa_utf8_valid("hallo\n") != NULL);
18     fail_unless(pa_utf8_valid("hüpfburg\n") != NULL);
19 }
20 END_TEST
21 
START_TEST(utf8_filter)22 START_TEST (utf8_filter) {
23     char *c;
24 
25     {
26         char res1[] = { 0x68, 0x5f, 0x70, 0x66, 0x62, 0x75, 0x72, 0x67, '\0' };
27         c = pa_utf8_filter("h�pfburg");
28         pa_log_debug("%s %s", res1, c);
29         fail_unless(pa_streq(c, res1));
30         pa_xfree(c);
31     }
32 
33     {
34         char res2[] = { 0x68, 0xc3, 0xbc, 0x70, 0x66, 0x62, 0x75, 0x72, 0x67, '\0' };
35         c = pa_utf8_filter("hüpfburg");
36         fail_unless(pa_streq(c, res2));
37         pa_log_debug("%s %s", res2, c);
38         pa_xfree(c);
39     }
40 
41     {
42         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' };
43         c = pa_utf8_filter("�xkn�rzm�rzelt�rsz߳�dsjkfh");
44         pa_log_debug("%s %s", res3, c);
45         fail_unless(pa_streq(c, res3));
46         pa_xfree(c);
47     }
48 }
49 END_TEST
50 
main(int argc,char * argv[])51 int main(int argc, char *argv[]) {
52     int failed = 0;
53     Suite *s;
54     TCase *tc;
55     SRunner *sr;
56 
57     if (!getenv("MAKE_CHECK"))
58         pa_log_set_level(PA_LOG_DEBUG);
59 
60     s = suite_create("UTF8");
61     tc = tcase_create("utf8");
62     tcase_add_test(tc, utf8_valid);
63     tcase_add_test(tc, utf8_filter);
64     suite_add_tcase(s, tc);
65 
66     sr = srunner_create(s);
67     srunner_run_all(sr, CK_NORMAL);
68     failed = srunner_ntests_failed(sr);
69     srunner_free(sr);
70 
71     return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
72 }
73