libpurple/protocols/jabber/tests/test_jabber_caps.c

Mon, 12 Jun 2017 17:48:37 -0300

author
dx <dx@dxzone.com.ar>
date
Mon, 12 Jun 2017 17:48:37 -0300
changeset 38358
30ba44276e74
parent 38327
c842a56b9967
child 40358
e6fe6fc1f516
permissions
-rw-r--r--

Merge release-2.x.y into default

37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
1 #include <glib.h>
30507
10c522a4c93a jabber: Start adding some caps tests
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
2
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
3 #include "xmlnode.h"
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
4 #include "protocols/jabber/caps.h"
30507
10c522a4c93a jabber: Start adding some caps tests
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
5
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
6 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
7 test_jabber_caps_parse_invalid_nodes(void) {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34567
diff changeset
8 PurpleXmlNode *query;
30507
10c522a4c93a jabber: Start adding some caps tests
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
9
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
10 g_assert_null(jabber_caps_parse_client_info(NULL));
30507
10c522a4c93a jabber: Start adding some caps tests
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
11
10c522a4c93a jabber: Start adding some caps tests
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
12 /* Something other than a disco#info query */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34567
diff changeset
13 query = purple_xmlnode_new("foo");
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
14 g_assert_null(jabber_caps_parse_client_info(query));
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34567
diff changeset
15 purple_xmlnode_free(query);
30507
10c522a4c93a jabber: Start adding some caps tests
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
16
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34567
diff changeset
17 query = purple_xmlnode_new("query");
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
18 g_assert_null(jabber_caps_parse_client_info(query));
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
19
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34567
diff changeset
20 purple_xmlnode_set_namespace(query, "jabber:iq:last");
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
21 g_assert_null(jabber_caps_parse_client_info(query));
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34567
diff changeset
22 purple_xmlnode_free(query);
30507
10c522a4c93a jabber: Start adding some caps tests
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
23 }
10c522a4c93a jabber: Start adding some caps tests
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
24
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
25 static void
38327
c842a56b9967 jabber: Port to use GChecksum instead of PurpleHash
Mike Ruprecht <cmaiku@gmail.com>
parents: 37605
diff changeset
26 _test_jabber_caps_match(GChecksumType hash_type, const gchar *in, const gchar *expected) {
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
27 PurpleXmlNode *query = purple_xmlnode_from_str(in, -1);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
28 JabberCapsClientInfo *info = jabber_caps_parse_client_info(query);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
29 gchar *got = NULL;
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
30
38327
c842a56b9967 jabber: Port to use GChecksum instead of PurpleHash
Mike Ruprecht <cmaiku@gmail.com>
parents: 37605
diff changeset
31 got = jabber_caps_calculate_hash(info, hash_type);
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
32
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
33 g_assert_cmpstr(expected, ==, got);
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
34 g_free(got);
30508
80ecb950263a jabber: Don't crash on caps that include an empty <value/> in the Software Information extended info. Fixes #12292
Paul Aurich <darkrain42@pidgin.im>
parents: 30507
diff changeset
35 }
80ecb950263a jabber: Don't crash on caps that include an empty <value/> in the Software Information extended info. Fixes #12292
Paul Aurich <darkrain42@pidgin.im>
parents: 30507
diff changeset
36
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
37 static void
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
38 test_jabber_caps_calculate_from_xmlnode(void) {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
39 _test_jabber_caps_match(
38327
c842a56b9967 jabber: Port to use GChecksum instead of PurpleHash
Mike Ruprecht <cmaiku@gmail.com>
parents: 37605
diff changeset
40 G_CHECKSUM_SHA1,
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
41 "<query xmlns='http://jabber.org/protocol/disco#info' node='http://tkabber.jabber.ru/#GNjxthSckUNvAIoCCJFttjl6VL8='><identity category='client' type='pc' name='Tkabber'/><x xmlns='jabber:x:data' type='result'><field var='FORM_TYPE' type='hidden'><value>urn:xmpp:dataforms:softwareinfo</value></field><field var='software'><value>Tkabber</value></field><field var='software_version'><value> ( 8.5.5 )</value></field><field var='os'><value>ATmega640-16AU</value></field><field var='os_version'><value/></field></x><feature var='games:board'/><feature var='google:mail:notify'/><feature var='http://jabber.org/protocol/activity'/><feature var='http://jabber.org/protocol/bytestreams'/><feature var='http://jabber.org/protocol/chatstates'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/disco#info'/><feature var='http://jabber.org/protocol/disco#items'/><feature var='http://jabber.org/protocol/feature-neg'/><feature var='http://jabber.org/protocol/geoloc'/><feature var='http://jabber.org/protocol/ibb'/><feature var='http://jabber.org/protocol/iqibb'/><feature var='http://jabber.org/protocol/mood'/><feature var='http://jabber.org/protocol/muc'/><feature var='http://jabber.org/protocol/mute#ancestor'/><feature var='http://jabber.org/protocol/mute#editor'/><feature var='http://jabber.org/protocol/rosterx'/><feature var='http://jabber.org/protocol/si'/><feature var='http://jabber.org/protocol/si/profile/file-transfer'/><feature var='http://jabber.org/protocol/tune'/><feature var='jabber:iq:avatar'/><feature var='jabber:iq:browse'/><feature var='jabber:iq:dtcp'/><feature var='jabber:iq:filexfer'/><feature var='jabber:iq:ibb'/><feature var='jabber:iq:inband'/><feature var='jabber:iq:jidlink'/><feature var='jabber:iq:last'/><feature var='jabber:iq:oob'/><feature var='jabber:iq:privacy'/><feature var='jabber:iq:time'/><feature var='jabber:iq:version'/><feature var='jabber:x:data'/><feature var='jabber:x:event'/><feature var='jabber:x:oob'/><feature var='urn:xmpp:ping'/><feature var='urn:xmpp:receipts'/><feature var='urn:xmpp:time'/></query>",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
42 "GNjxthSckUNvAIoCCJFttjl6VL8="
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
43 );
30508
80ecb950263a jabber: Don't crash on caps that include an empty <value/> in the Software Information extended info. Fixes #12292
Paul Aurich <darkrain42@pidgin.im>
parents: 30507
diff changeset
44 }
80ecb950263a jabber: Don't crash on caps that include an empty <value/> in the Software Information extended info. Fixes #12292
Paul Aurich <darkrain42@pidgin.im>
parents: 30507
diff changeset
45
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
46 gint
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
47 main(gint argc, gchar **argv) {
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
48 g_test_init(&argc, &argv, NULL);
30507
10c522a4c93a jabber: Start adding some caps tests
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
49
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
50 g_test_add_func("/jabber/caps/parse invalid nodes",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
51 test_jabber_caps_parse_invalid_nodes);
30507
10c522a4c93a jabber: Start adding some caps tests
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
52
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
53 g_test_add_func("/jabber/caps/calulate from xmlnode",
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
54 test_jabber_caps_calculate_from_xmlnode);
30508
80ecb950263a jabber: Don't crash on caps that include an empty <value/> in the Software Information extended info. Fixes #12292
Paul Aurich <darkrain42@pidgin.im>
parents: 30507
diff changeset
55
37605
599b01f2f5a7 This should do it for the jabber tests
Gary Kramlich <grim@reaperworld.com>
parents: 34935
diff changeset
56 return g_test_run();
30507
10c522a4c93a jabber: Start adding some caps tests
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
57 }

mercurial