libpurple/protocols/jabber/tests/test_jabber_jutil.c

Sun, 15 Sep 2019 17:11:46 -0400

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Sun, 15 Sep 2019 17:11:46 -0400
changeset 39894
7eab91ea30a1
parent 37613
5dc70173ccb4
child 40179
83abc6732fb5
permissions
-rw-r--r--

Replace Purple type macros by GObject macros.

These were necessary to support both static and dynamic plugins, but
we're just leaving the to GPlugin now.

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"
37610
8e7c187310d5 Move the scram tests to gtester
Gary Kramlich <grim@reaperworld.com>
parents: 37609
diff changeset
5 #include "glibcompat.h"
8e7c187310d5 Move the scram tests to gtester
Gary Kramlich <grim@reaperworld.com>
parents: 37609
diff changeset
6 #include "tests.h"
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
7 #include "xmlnode.h"
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
8 #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
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",
37613
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
109 "noone@example.com",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
110 "noone@example.com/Test12345",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
111 "noone@example.com/Test@12345",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
112 "noone@example.com/Te/st@12@//345",
37605
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",
37613
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
115 "noone@example.com/まりるーむ",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
116 "noone@example/stuff.org",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
117 "noone@nödåtXäYZ.example",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
118 "noone@nödåtXäYZ.example/まりるーむ",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
119 "noone@わいど.org",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
120 "noone@まつ.おおかみ.net",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
121 "noone@310.0.42.230/s",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
122 "noone@[::1]", /* IPv6 */
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
123 "noone@[3001:470:1f05:d58::2]",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
124 "noone@[3001:470:1f05:d58::2]/foo",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
125 "no=one@310.0.42.230",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
126 "no,one@310.0.42.230",
37605
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",
37613
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
145 "noone@@example.com/Test12345",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
146 "no@one@example.com/Test12345",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
147 "@example.com/Test@12345",
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
148 "/Test@12345",
37613
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
149 "noone@",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
150 "noone/",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
151 "noone@gmail_stuff.org",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
152 "noone@gmail[stuff.org",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
153 "noone@gmail\\stuff.org",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
154 "noone@[::1]124",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
155 "noone@2[::1]124/as",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
156 "noone@まつ.おおかみ/\x01",
37605
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 */
37613
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
187 assert_jid_parts("noone", "example.com", "NoOne@example.com");
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
188 assert_jid_parts("noone", "example.com", "noone@ExaMPle.CoM");
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) */
37613
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
193 assert_jid_parts("ф", "example.com", "Ф@example.com");
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 */
37613
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
204 assert_jid_parts("Ꙥ", "example.com", "Ꙥ@example.com");
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
205 assert_jid_parts("ꙥ", "example.com", "ꙥ@example.com");
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 */
37613
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
209 assert_jid_parts("noone", "өexample.com", "noone@Өexample.com");
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 {
37613
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
221 "NoOnE@ExAMplE.com",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
222 "noone@example.com",
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
223 }, {
37613
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
224 "NoOnE@ExampLE.cOM/",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
225 "noone@example.com",
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 28923
diff changeset
226 }, {
37613
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
227 "NoONe@exAMPle.CoM/resource",
5dc70173ccb4 Change some names, protect the innocent, something something
Gary Kramlich <grim@reaperworld.com>
parents: 37610
diff changeset
228 "noone@example.com",
37605
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