15093
|
1 #include "tests.h"
|
|
2 #include "../protocols/jabber/jutil.h"
|
|
3
|
|
4 START_TEST(test_get_resource)
|
|
5 {
|
|
6 assert_string_equal_free("baz", jabber_get_resource("foo@bar/baz"));
|
|
7 assert_string_equal_free("baz", jabber_get_resource("bar/baz"));
|
|
8 assert_string_equal_free("baz/bat", jabber_get_resource("foo@bar/baz/bat"));
|
|
9 assert_string_equal_free("baz/bat", jabber_get_resource("bar/baz/bat"));
|
|
10 }
|
|
11 END_TEST
|
|
12
|
|
13 START_TEST(test_get_resource_no_resource)
|
|
14 {
|
|
15
|
|
16 fail_unless(NULL == jabber_get_resource("foo@bar"));
|
|
17 fail_unless(NULL == jabber_get_resource("bar"));
|
|
18 }
|
|
19 END_TEST
|
|
20
|
|
21 START_TEST(test_get_bare_jid)
|
|
22 {
|
|
23 assert_string_equal_free("foo@bar", jabber_get_bare_jid("foo@bar"));
|
|
24 assert_string_equal_free("foo@bar", jabber_get_bare_jid("foo@bar/baz"));
|
|
25 assert_string_equal_free("bar", jabber_get_bare_jid("bar"));
|
|
26 assert_string_equal_free("bar", jabber_get_bare_jid("bar/baz"));
|
|
27 }
|
|
28 END_TEST
|
|
29
|
|
30 START_TEST(test_nodeprep_validate)
|
|
31 {
|
|
32 fail_unless(jabber_nodeprep_validate(NULL));
|
|
33 fail_unless(jabber_nodeprep_validate("foo"));
|
|
34 fail_unless(jabber_nodeprep_validate("%d"));
|
|
35 fail_unless(jabber_nodeprep_validate("y\\z"));
|
|
36
|
|
37 char *longnode = g_strnfill(1023, 'a');
|
|
38 fail_unless(jabber_nodeprep_validate(longnode));
|
|
39 g_free(longnode);
|
|
40 }
|
|
41 END_TEST
|
|
42
|
|
43 START_TEST(test_nodeprep_validate_illegal_chars)
|
|
44 {
|
|
45 fail_if(jabber_nodeprep_validate("don't"));
|
|
46 fail_if(jabber_nodeprep_validate("m@ke"));
|
|
47 fail_if(jabber_nodeprep_validate("\"me\""));
|
|
48 fail_if(jabber_nodeprep_validate("&ngry"));
|
|
49 fail_if(jabber_nodeprep_validate("c:"));
|
|
50 fail_if(jabber_nodeprep_validate("a/b"));
|
|
51 fail_if(jabber_nodeprep_validate("4>2"));
|
|
52 fail_if(jabber_nodeprep_validate("4<7"));
|
|
53 }
|
|
54 END_TEST
|
|
55
|
|
56 START_TEST(test_nodeprep_validate_too_long)
|
|
57 {
|
|
58 char *longnode = g_strnfill(1024, 'a');
|
|
59 fail_if(jabber_nodeprep_validate(longnode));
|
|
60 g_free(longnode);
|
|
61 }
|
|
62 END_TEST
|
|
63
|
|
64 Suite *
|
|
65 jabber_jutil_suite(void)
|
|
66 {
|
|
67 Suite *s = suite_create("Jabber Utility Functions");
|
|
68
|
|
69 TCase *tc = tcase_create("Get Resource");
|
|
70 tcase_add_test(tc, test_get_resource);
|
|
71 tcase_add_test(tc, test_get_resource_no_resource);
|
|
72 suite_add_tcase(s, tc);
|
|
73
|
|
74 tc = tcase_create("Get Bare JID");
|
|
75 tcase_add_test(tc, test_get_bare_jid);
|
|
76 suite_add_tcase(s, tc);
|
|
77
|
|
78 tc = tcase_create("Nodeprep validate");
|
|
79 tcase_add_test(tc, test_nodeprep_validate);
|
|
80 tcase_add_test(tc, test_nodeprep_validate_illegal_chars);
|
|
81 tcase_add_test(tc, test_nodeprep_validate_too_long);
|
|
82 suite_add_tcase(s, tc);
|
|
83
|
|
84 return s;
|
|
85 }
|