libpurple/protocols/jabber/tests/test_jabber_jutil.c

Sun, 20 Mar 2016 15:59:16 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Sun, 20 Mar 2016 15:59:16 -0500
changeset 37609
a265dfe49fcb
parent 37605
599b01f2f5a7
child 37610
8e7c187310d5
permissions
-rw-r--r--

Add a header file with some utils for testing

37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
1 #include <glib.h>
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
2
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
3 #include "account.h"
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
4 #include "conversation.h"
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
5 #include "xmlnode.h"
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
6 #include "protocols/jabber/jutil.h"
15950
0f01bb61c5d3 Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15435
diff changeset
7
37609
a265dfe49fcb Add a header file with some utils for testing
Gary Kramlich <grim@reaperworld.com>
parents: 37605
diff changeset
8 #include "tests.h"
15155
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
10 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
11 test_jabber_util_get_resource_exists(void) {
37609
a265dfe49fcb Add a header file with some utils for testing
Gary Kramlich <grim@reaperworld.com>
parents: 37605
diff changeset
12 PurpleTestStringData data[] = {
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
13 { "foo@bar/baz", "baz" },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
14 { "bar/baz", "baz" },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
15 { "foo@bar/baz/bat", "baz/bat" },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
16 { "bar/baz/bat", "baz/bat" },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
17 { NULL, NULL },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
18 };
15155
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19
37609
a265dfe49fcb Add a header file with some utils for testing
Gary Kramlich <grim@reaperworld.com>
parents: 37605
diff changeset
20 purple_test_string_compare_free(jabber_get_resource, data);
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
21 }
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
22
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
23 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
24 test_jabber_util_get_resource_none(void) {
37609
a265dfe49fcb Add a header file with some utils for testing
Gary Kramlich <grim@reaperworld.com>
parents: 37605
diff changeset
25 PurpleTestStringData data[] = {
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
26 { "foo@bar", NULL },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
27 { "bar", NULL },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
28 { NULL, NULL },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
29 };
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
30
37609
a265dfe49fcb Add a header file with some utils for testing
Gary Kramlich <grim@reaperworld.com>
parents: 37605
diff changeset
31 purple_test_string_compare_free(jabber_get_resource, data);
15155
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 }
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
34 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
35 test_jabber_util_get_bare_jid(void) {
37609
a265dfe49fcb Add a header file with some utils for testing
Gary Kramlich <grim@reaperworld.com>
parents: 37605
diff changeset
36 PurpleTestStringData data[] = {
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
37 { "foo@bar", "foo@bar" },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
38 { "foo@bar/baz", "foo@bar" },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
39 { "bar", "bar" },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
40 { "bar/baz", "bar" },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
41 { NULL, NULL },
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
42 };
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
43
37609
a265dfe49fcb Add a header file with some utils for testing
Gary Kramlich <grim@reaperworld.com>
parents: 37605
diff changeset
44 purple_test_string_compare_free(jabber_get_bare_jid, data);
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
45 }
15950
0f01bb61c5d3 Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15435
diff changeset
46
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
47 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
48 test_jabber_util_nodeprep_validate(void) {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
49 const gchar *data[] = {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
50 "foo",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
51 "%d",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
52 "y\\z",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
53 "a=",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
54 "a,",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
55 NULL,
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
56 };
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
57 gchar *longnode;
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
58 gint i;
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
59
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
60 for(i = 0; data[i]; i++) {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
61 g_assert_true(jabber_nodeprep_validate(data[i]));
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
62 }
15155
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63
15950
0f01bb61c5d3 Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15435
diff changeset
64 longnode = g_strnfill(1023, 'a');
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
65 g_assert_true(jabber_nodeprep_validate(longnode));
15155
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66 g_free(longnode);
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
67
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
68 longnode = g_strnfill(1024, 'a');
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
69 g_assert_false(jabber_nodeprep_validate(longnode));
15155
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 g_free(longnode);
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 }
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
73 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
74 test_jabber_util_nodeprep_validate_illegal_chars(void) {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
75 const gchar *data[] = {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
76 "don't",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
77 "m@ke",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
78 "\"me\"",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
79 "&ngry",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
80 "c:",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
81 "a/b",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
82 "4>2",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
83 "4<7",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
84 NULL,
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
85 };
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
86 gint i;
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
87
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
88 for(i = 0; data[i]; i++)
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
89 g_assert_false(jabber_nodeprep_validate(data[i]));
27710
e4b25e3c28a2 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents: 15953
diff changeset
90 }
e4b25e3c28a2 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents: 15953
diff changeset
91
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
92 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
93 test_jabber_util_nodeprep_validate_too_long(void) {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
94 gchar *longnode = g_strnfill(1024, 'a');
27710
e4b25e3c28a2 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents: 15953
diff changeset
95
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
96 g_assert_false(jabber_nodeprep_validate(longnode));
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
97
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
98 g_free(longnode);
27818
d2d5d265001b Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
99 }
d2d5d265001b Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
100
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
101 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
102 test_jabber_util_jabber_id_new_valid(void) {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
103 const gchar *jids[] = {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
104 "gmail.com",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
105 "gmail.com/Test",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
106 "gmail.com/Test@",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
107 "gmail.com/@",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
108 "gmail.com/Test@alkjaweflkj",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
109 "mark.doliner@gmail.com",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
110 "mark.doliner@gmail.com/Test12345",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
111 "mark.doliner@gmail.com/Test@12345",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
112 "mark.doliner@gmail.com/Te/st@12@//345",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
113 "わいど@conference.jabber.org",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
114 "まりるーむ@conference.jabber.org",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
115 "mark.doliner@gmail.com/まりるーむ",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
116 "mark.doliner@gmail/stuff.org",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
117 "stuart@nödåtXäYZ.se",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
118 "stuart@nödåtXäYZ.se/まりるーむ",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
119 "mark.doliner@わいど.org",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
120 "nick@まつ.おおかみ.net",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
121 "paul@10.0.42.230/s",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
122 "paul@[::1]", /* IPv6 */
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
123 "paul@[2001:470:1f05:d58::2]",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
124 "paul@[2001:470:1f05:d58::2]/foo",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
125 "pa=ul@10.0.42.230",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
126 "pa,ul@10.0.42.230",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
127 NULL
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
128 };
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
129 gint i;
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
130
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
131 for(i = 0; jids[i]; i++) {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
132 JabberID *jid = jabber_id_new(jids[i]);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
133
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
134 g_assert_nonnull(jid);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
135
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
136 jabber_id_free(jid);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
137 }
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
138 }
27710
e4b25e3c28a2 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents: 15953
diff changeset
139
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
140 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
141 test_jabber_util_jabber_id_new_invalid(void) {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
142 const gchar *jids[] = {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
143 "@gmail.com",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
144 "@@gmail.com",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
145 "mark.doliner@@gmail.com/Test12345",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
146 "mark@doliner@gmail.com/Test12345",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
147 "@gmail.com/Test@12345",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
148 "/Test@12345",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
149 "mark.doliner@",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
150 "mark.doliner/",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
151 "mark.doliner@gmail_stuff.org",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
152 "mark.doliner@gmail[stuff.org",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
153 "mark.doliner@gmail\\stuff.org",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
154 "paul@[::1]124",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
155 "paul@2[::1]124/as",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
156 "paul@まつ.おおかみ/\x01",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
157 /*
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
158 * RFC 3454 Section 6 reads, in part,
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
159 * "If a string contains any RandALCat character, the
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
160 * string MUST NOT contain any LCat character."
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
161 * The character is U+066D (ARABIC FIVE POINTED STAR).
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
162 */
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
163 "foo@example.com/٭simplexe٭",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
164 NULL,
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
165 };
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
166 gint i;
27818
d2d5d265001b Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
167
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
168 for(i = 0; jids[i]; i++)
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
169 g_assert_null(jabber_id_new(jids[i]));
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
170 }
28713
b68bad2389d3 Add another (IMHO unintuitive) JID test. Refs #10532.
Paul Aurich <darkrain42@pidgin.im>
parents: 28558
diff changeset
171
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
172 #define assert_jid_parts(expect_node, expect_domain, str) G_STMT_START { \
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
173 JabberID *jid = jabber_id_new(str); \
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
174 g_assert_nonnull(jid); \
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
175 g_assert_nonnull(jid->node); \
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
176 g_assert_nonnull(jid->domain); \
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
177 g_assert_null(jid->resource); \
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
178 g_assert_cmpstr(expect_node, ==, jid->node); \
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
179 g_assert_cmpstr(expect_domain, ==, jid->domain); \
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
180 jabber_id_free(jid); \
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
181 } G_STMT_END
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
182
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
183
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
184 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
185 test_jabber_util_jid_parts(void) {
27818
d2d5d265001b Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
186 /* Ensure that jabber_id_new is properly lowercasing node and domains */
d2d5d265001b Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
187 assert_jid_parts("paul", "darkrain42.org", "PaUL@darkrain42.org");
d2d5d265001b Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
188 assert_jid_parts("paul", "darkrain42.org", "paul@DaRkRaIn42.org");
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
189
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
190 /* These case-mapping tests culled from examining RFC3454 B.2 */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
191
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
192 /* Cyrillic capital EF (U+0424) maps to lowercase EF (U+0444) */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
193 assert_jid_parts("ф", "darkrain42.org", "Ф@darkrain42.org");
28558
dd11e7078db9 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <darkrain42@pidgin.im>
parents: 28554
diff changeset
194
dd11e7078db9 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <darkrain42@pidgin.im>
parents: 28554
diff changeset
195 #ifdef USE_IDN
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
196 /*
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
197 * These character (U+A664 and U+A665) are not mapped to anything in
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
198 * RFC3454 B.2. This first test *fails* when not using IDN because glib's
28554
a4a6df1d2e53 Clarify the "improperly"; glib is doing what I'd expect strdown to do.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
199 * case-folding/utf8_strdown improperly (for XMPP) lowercases the character.
28558
dd11e7078db9 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <darkrain42@pidgin.im>
parents: 28554
diff changeset
200 *
dd11e7078db9 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <darkrain42@pidgin.im>
parents: 28554
diff changeset
201 * This is known, but not (very?) likely to actually cause a problem, so
dd11e7078db9 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <darkrain42@pidgin.im>
parents: 28554
diff changeset
202 * this test is commented out when using glib's functions.
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
203 */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
204 assert_jid_parts("Ꙥ", "darkrain42.org", "Ꙥ@darkrain42.org");
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
205 assert_jid_parts("ꙥ", "darkrain42.org", "ꙥ@darkrain42.org");
28558
dd11e7078db9 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <darkrain42@pidgin.im>
parents: 28554
diff changeset
206 #endif
dd11e7078db9 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <darkrain42@pidgin.im>
parents: 28554
diff changeset
207
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27818
diff changeset
208 /* U+04E9 to U+04E9 */
27818
d2d5d265001b Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
209 assert_jid_parts("paul", "өarkrain42.org", "paul@Өarkrain42.org");
27710
e4b25e3c28a2 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents: 15953
diff changeset
210 }
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
211
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
212 static const gchar *
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
213 partial_jabber_normalize(const gchar *str) {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
214 return jabber_normalize(NULL, str);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
215 }
27710
e4b25e3c28a2 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents: 15953
diff changeset
216
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
217 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
218 test_jabber_util_jabber_normalize(void) {
37609
a265dfe49fcb Add a header file with some utils for testing
Gary Kramlich <grim@reaperworld.com>
parents: 37605
diff changeset
219 PurpleTestStringData data[] = {
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
220 {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
221 "PaUL@DaRkRain42.org",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
222 "paul@darkrain42.org",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
223 }, {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
224 "PaUL@DaRkRain42.org/",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
225 "paul@darkrain42.org",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
226 }, {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
227 "PaUL@DaRkRain42.org/resource",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
228 "paul@darkrain42.org",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
229 }, {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
230 NULL,
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
231 NULL,
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
232 }
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
233 };
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
234
37609
a265dfe49fcb Add a header file with some utils for testing
Gary Kramlich <grim@reaperworld.com>
parents: 37605
diff changeset
235 purple_test_string_compare(partial_jabber_normalize, data);
28414
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 27849
diff changeset
236 }
15155
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
237
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
238 gint
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
239 main(gint argc, gchar **argv) {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
240 g_test_init(&argc, &argv, NULL);
15155
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
242 g_test_add_func("/jabber/util/get_resource/exists",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
243 test_jabber_util_get_resource_exists);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
244 g_test_add_func("/jabber/util/get_resource/none",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
245 test_jabber_util_get_resource_none);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
246
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
247 g_test_add_func("/jabber/util/get_bare_jid",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
248 test_jabber_util_get_bare_jid);
15155
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
250 g_test_add_func("/jabber/util/nodeprep/validate/valid",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
251 test_jabber_util_nodeprep_validate);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
252 g_test_add_func("/jabber/util/nodeprep/validate/illegal_chars",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
253 test_jabber_util_nodeprep_validate_illegal_chars);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
254 g_test_add_func("/jabber/util/nodeprep/validate/too_long",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
255 test_jabber_util_nodeprep_validate_too_long);
15155
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
257 g_test_add_func("/jabber/util/id_new/valid",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
258 test_jabber_util_jabber_id_new_valid);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
259 g_test_add_func("/jabber/util/id_new/invalid",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
260 test_jabber_util_jabber_id_new_invalid);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
261 g_test_add_func("/jabber/util/id_new/jid_parts",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
262 test_jabber_util_jid_parts);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
263
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
264 g_test_add_func("/jabber/util/normalize",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
265 test_jabber_util_jabber_normalize);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
266
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
267 return g_test_run();
15155
ef9cb9123212 [gaim-migrate @ 17879]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268 }

mercurial