annotate libpurple/tests/test_jabber_jutil.c @ 31940:df716c39f698

Less code duplication.
author andrew.victor@mxit.com
date Mon, 21 Mar 2011 21:07:47 +0000
parents aea409195613
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15889
6577b292e7b4 Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <stu@nosnilmot.com>
parents: 15374
diff changeset
1 #include <string.h>
6577b292e7b4 Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <stu@nosnilmot.com>
parents: 15374
diff changeset
2
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 #include "tests.h"
15892
5bd5af818afe Update #includes to match changes in jabber
Stu Tomlinson <stu@nosnilmot.com>
parents: 15889
diff changeset
4 #include "../account.h"
5bd5af818afe Update #includes to match changes in jabber
Stu Tomlinson <stu@nosnilmot.com>
parents: 15889
diff changeset
5 #include "../conversation.h"
5bd5af818afe Update #includes to match changes in jabber
Stu Tomlinson <stu@nosnilmot.com>
parents: 15889
diff changeset
6 #include "../xmlnode.h"
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 #include "../protocols/jabber/jutil.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 START_TEST(test_get_resource)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 assert_string_equal_free("baz", jabber_get_resource("foo@bar/baz"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 assert_string_equal_free("baz", jabber_get_resource("bar/baz"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 assert_string_equal_free("baz/bat", jabber_get_resource("foo@bar/baz/bat"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 assert_string_equal_free("baz/bat", jabber_get_resource("bar/baz/bat"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 END_TEST
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 START_TEST(test_get_resource_no_resource)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 fail_unless(NULL == jabber_get_resource("foo@bar"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 fail_unless(NULL == jabber_get_resource("bar"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 END_TEST
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 START_TEST(test_get_bare_jid)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 assert_string_equal_free("foo@bar", jabber_get_bare_jid("foo@bar"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 assert_string_equal_free("foo@bar", jabber_get_bare_jid("foo@bar/baz"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 assert_string_equal_free("bar", jabber_get_bare_jid("bar"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 assert_string_equal_free("bar", jabber_get_bare_jid("bar/baz"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 END_TEST
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 START_TEST(test_nodeprep_validate)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 {
15889
6577b292e7b4 Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <stu@nosnilmot.com>
parents: 15374
diff changeset
37 char *longnode;
6577b292e7b4 Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <stu@nosnilmot.com>
parents: 15374
diff changeset
38
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 fail_unless(jabber_nodeprep_validate(NULL));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 fail_unless(jabber_nodeprep_validate("foo"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 fail_unless(jabber_nodeprep_validate("%d"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 fail_unless(jabber_nodeprep_validate("y\\z"));
28972
aea409195613 '=' and ',' are valid nodeprep characters
Paul Aurich <paul@darkrain42.org>
parents: 28778
diff changeset
43 fail_unless(jabber_nodeprep_validate("a="));
aea409195613 '=' and ',' are valid nodeprep characters
Paul Aurich <paul@darkrain42.org>
parents: 28778
diff changeset
44 fail_unless(jabber_nodeprep_validate("a,"));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45
15889
6577b292e7b4 Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <stu@nosnilmot.com>
parents: 15374
diff changeset
46 longnode = g_strnfill(1023, 'a');
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 fail_unless(jabber_nodeprep_validate(longnode));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 g_free(longnode);
27674
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
49
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
50 longnode = g_strnfill(1024, 'a');
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
51 fail_if(jabber_nodeprep_validate(longnode));
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
52 g_free(longnode);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 END_TEST
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 START_TEST(test_nodeprep_validate_illegal_chars)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 fail_if(jabber_nodeprep_validate("don't"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 fail_if(jabber_nodeprep_validate("m@ke"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 fail_if(jabber_nodeprep_validate("\"me\""));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 fail_if(jabber_nodeprep_validate("&ngry"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 fail_if(jabber_nodeprep_validate("c:"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 fail_if(jabber_nodeprep_validate("a/b"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 fail_if(jabber_nodeprep_validate("4>2"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 fail_if(jabber_nodeprep_validate("4<7"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 END_TEST
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 START_TEST(test_nodeprep_validate_too_long)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 char *longnode = g_strnfill(1024, 'a');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 fail_if(jabber_nodeprep_validate(longnode));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 g_free(longnode);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 END_TEST
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76
27527
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
77 #define assert_valid_jid(str) { \
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
78 JabberID *jid = jabber_id_new(str); \
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
79 fail_if(jid == NULL, "JID '%s' is valid but jabber_id_new() rejected it", str); \
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
80 jabber_id_free(jid); \
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
81 }
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
82
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
83 #define assert_invalid_jid(str) { \
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
84 JabberID *jid = jabber_id_new(str); \
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
85 fail_if(jid != NULL, "JID '%s' is invalid but jabber_id_new() allowed it", str); \
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
86 jabber_id_free(jid); \
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
87 }
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
88
27636
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
89 #define assert_jid_parts(expect_node, expect_domain, str) { \
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
90 JabberID *jid = jabber_id_new(str); \
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
91 fail_if(jid == NULL, "JID '%s' is valid but jabber_id_new() rejected it", str); \
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
92 fail_if(jid->node == NULL, "JID '%s' is valid but jabber_id_new() didn't return a node", str); \
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
93 fail_if(jid->domain == NULL, "JID '%s' is valid but jabber_id_new() didn't return a domain", str); \
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
94 fail_if(jid->resource != NULL, "JID '%s' doesn't contain a resource", str); \
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
95 assert_string_equal(expect_node, jid->node); \
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
96 assert_string_equal(expect_domain, jid->domain); \
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
97 jabber_id_free(jid); \
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
98 }
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
99
27527
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
100 START_TEST(test_jabber_id_new)
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
101 {
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
102 assert_valid_jid("gmail.com");
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
103 assert_valid_jid("gmail.com/Test");
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
104 assert_valid_jid("gmail.com/Test@");
27529
c6fea4ae68b3 Two more JID tests.
Paul Aurich <paul@darkrain42.org>
parents: 27528
diff changeset
105 assert_valid_jid("gmail.com/@");
27527
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
106 assert_valid_jid("gmail.com/Test@alkjaweflkj");
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
107 assert_valid_jid("mark.doliner@gmail.com");
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
108 assert_valid_jid("mark.doliner@gmail.com/Test12345");
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
109 assert_valid_jid("mark.doliner@gmail.com/Test@12345");
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
110 assert_valid_jid("mark.doliner@gmail.com/Te/st@12@//345");
27533
3599729ce9ce More tests, some with an international flavor. I have no idea what that
Mark Doliner <mark@kingant.net>
parents: 27529
diff changeset
111 assert_valid_jid("わいど@conference.jabber.org");
3599729ce9ce More tests, some with an international flavor. I have no idea what that
Mark Doliner <mark@kingant.net>
parents: 27529
diff changeset
112 assert_valid_jid("まりるーむ@conference.jabber.org");
3599729ce9ce More tests, some with an international flavor. I have no idea what that
Mark Doliner <mark@kingant.net>
parents: 27529
diff changeset
113 assert_valid_jid("mark.doliner@gmail.com/まりるーむ");
27535
91fefa830798 Whoops, some of these were asserting valid but should have been
Mark Doliner <mark@kingant.net>
parents: 27533
diff changeset
114 assert_valid_jid("mark.doliner@gmail/stuff.org");
27539
167d7c3a4f7b XMPP allows for internationalized domain names.
Paul Aurich <paul@darkrain42.org>
parents: 27535
diff changeset
115 assert_valid_jid("stuart@nödåtXäYZ.se");
167d7c3a4f7b XMPP allows for internationalized domain names.
Paul Aurich <paul@darkrain42.org>
parents: 27535
diff changeset
116 assert_valid_jid("stuart@nödåtXäYZ.se/まりるーむ");
167d7c3a4f7b XMPP allows for internationalized domain names.
Paul Aurich <paul@darkrain42.org>
parents: 27535
diff changeset
117 assert_valid_jid("mark.doliner@わいど.org");
167d7c3a4f7b XMPP allows for internationalized domain names.
Paul Aurich <paul@darkrain42.org>
parents: 27535
diff changeset
118 assert_valid_jid("nick@まつ.おおかみ.net");
27540
da3d0159333d XMPP domains can also be IPv4 or IPv6 addresses
Paul Aurich <paul@darkrain42.org>
parents: 27539
diff changeset
119 assert_valid_jid("paul@10.0.42.230/s");
da3d0159333d XMPP domains can also be IPv4 or IPv6 addresses
Paul Aurich <paul@darkrain42.org>
parents: 27539
diff changeset
120 assert_valid_jid("paul@[::1]"); /* IPv6 */
da3d0159333d XMPP domains can also be IPv4 or IPv6 addresses
Paul Aurich <paul@darkrain42.org>
parents: 27539
diff changeset
121 assert_valid_jid("paul@[2001:470:1f05:d58::2]");
27546
e90fa379fcec Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <paul@darkrain42.org>
parents: 27540
diff changeset
122 assert_valid_jid("paul@[2001:470:1f05:d58::2]/foo");
28972
aea409195613 '=' and ',' are valid nodeprep characters
Paul Aurich <paul@darkrain42.org>
parents: 28778
diff changeset
123 assert_valid_jid("pa=ul@10.0.42.230");
aea409195613 '=' and ',' are valid nodeprep characters
Paul Aurich <paul@darkrain42.org>
parents: 28778
diff changeset
124 assert_valid_jid("pa,ul@10.0.42.230");
27527
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
125
27529
c6fea4ae68b3 Two more JID tests.
Paul Aurich <paul@darkrain42.org>
parents: 27528
diff changeset
126 assert_invalid_jid("@gmail.com");
27527
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
127 assert_invalid_jid("@@gmail.com");
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
128 assert_invalid_jid("mark.doliner@@gmail.com/Test12345");
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
129 assert_invalid_jid("mark@doliner@gmail.com/Test12345");
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
130 assert_invalid_jid("@gmail.com/Test@12345");
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
131 assert_invalid_jid("/Test@12345");
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
132 assert_invalid_jid("mark.doliner@");
27528
2131abd387f9 I thought of another invalid JID. I'm changing jabber_id_new() so that all
Mark Doliner <mark@kingant.net>
parents: 27527
diff changeset
133 assert_invalid_jid("mark.doliner/");
27535
91fefa830798 Whoops, some of these were asserting valid but should have been
Mark Doliner <mark@kingant.net>
parents: 27533
diff changeset
134 assert_invalid_jid("mark.doliner@gmail_stuff.org");
91fefa830798 Whoops, some of these were asserting valid but should have been
Mark Doliner <mark@kingant.net>
parents: 27533
diff changeset
135 assert_invalid_jid("mark.doliner@gmail[stuff.org");
91fefa830798 Whoops, some of these were asserting valid but should have been
Mark Doliner <mark@kingant.net>
parents: 27533
diff changeset
136 assert_invalid_jid("mark.doliner@gmail\\stuff.org");
27546
e90fa379fcec Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <paul@darkrain42.org>
parents: 27540
diff changeset
137 assert_invalid_jid("paul@[::1]124");
e90fa379fcec Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <paul@darkrain42.org>
parents: 27540
diff changeset
138 assert_invalid_jid("paul@2[::1]124/as");
28615
4cb882afbd6f Fix a crash when attempting to validate a JID with an invalid resource.
Paul Aurich <paul@darkrain42.org>
parents: 28482
diff changeset
139 assert_invalid_jid("paul@まつ.おおかみ/\x01");
27636
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
140
28778
aba0ab6b4abd Add another (IMHO unintuitive) JID test. Refs #10532.
Paul Aurich <paul@darkrain42.org>
parents: 28643
diff changeset
141 /*
aba0ab6b4abd Add another (IMHO unintuitive) JID test. Refs #10532.
Paul Aurich <paul@darkrain42.org>
parents: 28643
diff changeset
142 * RFC 3454 Section 6 reads, in part,
aba0ab6b4abd Add another (IMHO unintuitive) JID test. Refs #10532.
Paul Aurich <paul@darkrain42.org>
parents: 28643
diff changeset
143 * "If a string contains any RandALCat character, the
aba0ab6b4abd Add another (IMHO unintuitive) JID test. Refs #10532.
Paul Aurich <paul@darkrain42.org>
parents: 28643
diff changeset
144 * string MUST NOT contain any LCat character."
aba0ab6b4abd Add another (IMHO unintuitive) JID test. Refs #10532.
Paul Aurich <paul@darkrain42.org>
parents: 28643
diff changeset
145 * The character is U+066D (ARABIC FIVE POINTED STAR).
aba0ab6b4abd Add another (IMHO unintuitive) JID test. Refs #10532.
Paul Aurich <paul@darkrain42.org>
parents: 28643
diff changeset
146 */
aba0ab6b4abd Add another (IMHO unintuitive) JID test. Refs #10532.
Paul Aurich <paul@darkrain42.org>
parents: 28643
diff changeset
147 assert_invalid_jid("foo@example.com/٭simplexe٭");
aba0ab6b4abd Add another (IMHO unintuitive) JID test. Refs #10532.
Paul Aurich <paul@darkrain42.org>
parents: 28643
diff changeset
148
27636
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
149 /* Ensure that jabber_id_new is properly lowercasing node and domains */
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
150 assert_jid_parts("paul", "darkrain42.org", "PaUL@darkrain42.org");
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
151 assert_jid_parts("paul", "darkrain42.org", "paul@DaRkRaIn42.org");
27674
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
152
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
153 /* These case-mapping tests culled from examining RFC3454 B.2 */
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
154
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
155 /* Cyrillic capital EF (U+0424) maps to lowercase EF (U+0444) */
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
156 assert_jid_parts("ф", "darkrain42.org", "Ф@darkrain42.org");
28643
c9ec54c0add1 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <paul@darkrain42.org>
parents: 28639
diff changeset
157
c9ec54c0add1 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <paul@darkrain42.org>
parents: 28639
diff changeset
158 #ifdef USE_IDN
27674
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
159 /*
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
160 * These character (U+A664 and U+A665) are not mapped to anything in
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
161 * RFC3454 B.2. This first test *fails* when not using IDN because glib's
28639
60a790b93a50 Clarify the "improperly"; glib is doing what I'd expect strdown to do.
Paul Aurich <paul@darkrain42.org>
parents: 28615
diff changeset
162 * case-folding/utf8_strdown improperly (for XMPP) lowercases the character.
28643
c9ec54c0add1 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <paul@darkrain42.org>
parents: 28639
diff changeset
163 *
c9ec54c0add1 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <paul@darkrain42.org>
parents: 28639
diff changeset
164 * This is known, but not (very?) likely to actually cause a problem, so
c9ec54c0add1 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <paul@darkrain42.org>
parents: 28639
diff changeset
165 * this test is commented out when using glib's functions.
27674
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
166 */
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
167 assert_jid_parts("Ꙥ", "darkrain42.org", "Ꙥ@darkrain42.org");
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
168 assert_jid_parts("ꙥ", "darkrain42.org", "ꙥ@darkrain42.org");
28643
c9ec54c0add1 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <paul@darkrain42.org>
parents: 28639
diff changeset
169 #endif
c9ec54c0add1 Just comment out the failing tests when using glib; it's not likely anyone
Paul Aurich <paul@darkrain42.org>
parents: 28639
diff changeset
170
27674
e5fdfff98aa9 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <paul@darkrain42.org>
parents: 27636
diff changeset
171 /* U+04E9 to U+04E9 */
27636
090dc513552f Ensure UTF-8 strdown is mostly working correctly.
Paul Aurich <paul@darkrain42.org>
parents: 27546
diff changeset
172 assert_jid_parts("paul", "өarkrain42.org", "paul@Өarkrain42.org");
27527
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
173 }
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
174 END_TEST
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
175
28482
22c65c1090a8 jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <paul@darkrain42.org>
parents: 27674
diff changeset
176 START_TEST(test_jabber_normalize)
22c65c1090a8 jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <paul@darkrain42.org>
parents: 27674
diff changeset
177 {
22c65c1090a8 jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <paul@darkrain42.org>
parents: 27674
diff changeset
178 assert_string_equal("paul@darkrain42.org", jabber_normalize(NULL, "PaUL@DaRkRain42.org"));
22c65c1090a8 jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <paul@darkrain42.org>
parents: 27674
diff changeset
179 assert_string_equal("paul@darkrain42.org", jabber_normalize(NULL, "PaUL@DaRkRain42.org/"));
22c65c1090a8 jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <paul@darkrain42.org>
parents: 27674
diff changeset
180 assert_string_equal("paul@darkrain42.org", jabber_normalize(NULL, "PaUL@DaRkRain42.org/resource"));
22c65c1090a8 jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <paul@darkrain42.org>
parents: 27674
diff changeset
181 }
22c65c1090a8 jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <paul@darkrain42.org>
parents: 27674
diff changeset
182 END_TEST
22c65c1090a8 jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <paul@darkrain42.org>
parents: 27674
diff changeset
183
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 Suite *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 jabber_jutil_suite(void)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 Suite *s = suite_create("Jabber Utility Functions");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 TCase *tc = tcase_create("Get Resource");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 tcase_add_test(tc, test_get_resource);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 tcase_add_test(tc, test_get_resource_no_resource);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 suite_add_tcase(s, tc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 tc = tcase_create("Get Bare JID");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 tcase_add_test(tc, test_get_bare_jid);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 suite_add_tcase(s, tc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197
27527
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
198 tc = tcase_create("JID validate");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 tcase_add_test(tc, test_nodeprep_validate);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200 tcase_add_test(tc, test_nodeprep_validate_illegal_chars);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 tcase_add_test(tc, test_nodeprep_validate_too_long);
27527
962ce369fc35 Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <mark@kingant.net>
parents: 15892
diff changeset
202 tcase_add_test(tc, test_jabber_id_new);
28482
22c65c1090a8 jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <paul@darkrain42.org>
parents: 27674
diff changeset
203 tcase_add_test(tc, test_jabber_normalize);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 suite_add_tcase(s, tc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 return s;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207 }