| |
1 #include <glib.h> |
| |
2 |
| |
3 #include "xmlnode.h" |
| |
4 #include "ciphers/sha1hash.h" |
| |
5 #include "protocols/jabber/caps.h" |
| |
6 |
| |
7 static void |
| |
8 test_jabber_caps_parse_invalid_nodes(void) { |
| |
9 PurpleXmlNode *query; |
| |
10 |
| |
11 g_assert_null(jabber_caps_parse_client_info(NULL)); |
| |
12 |
| |
13 /* Something other than a disco#info query */ |
| |
14 query = purple_xmlnode_new("foo"); |
| |
15 g_assert_null(jabber_caps_parse_client_info(query)); |
| |
16 purple_xmlnode_free(query); |
| |
17 |
| |
18 query = purple_xmlnode_new("query"); |
| |
19 g_assert_null(jabber_caps_parse_client_info(query)); |
| |
20 |
| |
21 purple_xmlnode_set_namespace(query, "jabber:iq:last"); |
| |
22 g_assert_null(jabber_caps_parse_client_info(query)); |
| |
23 purple_xmlnode_free(query); |
| |
24 } |
| |
25 |
| |
26 static void |
| |
27 _test_jabber_caps_match(PurpleHash *hash, const gchar *in, const gchar *expected) { |
| |
28 PurpleXmlNode *query = purple_xmlnode_from_str(in, -1); |
| |
29 JabberCapsClientInfo *info = jabber_caps_parse_client_info(query); |
| |
30 gchar *got = NULL; |
| |
31 |
| |
32 got = jabber_caps_calculate_hash(info, hash); |
| |
33 g_object_unref(G_OBJECT(hash)); |
| |
34 |
| |
35 g_assert_cmpstr(expected, ==, got); |
| |
36 g_free(got); |
| |
37 } |
| |
38 |
| |
39 static void |
| |
40 test_jabber_caps_calculate_from_xmlnode(void) { |
| |
41 _test_jabber_caps_match( |
| |
42 purple_sha1_hash_new(), |
| |
43 "<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>", |
| |
44 "GNjxthSckUNvAIoCCJFttjl6VL8=" |
| |
45 ); |
| |
46 } |
| |
47 |
| |
48 gint |
| |
49 main(gint argc, gchar **argv) { |
| |
50 g_test_init(&argc, &argv, NULL); |
| |
51 |
| |
52 g_test_add_func("/jabber/caps/parse invalid nodes", |
| |
53 test_jabber_caps_parse_invalid_nodes); |
| |
54 |
| |
55 g_test_add_func("/jabber/caps/calulate from xmlnode", |
| |
56 test_jabber_caps_calculate_from_xmlnode); |
| |
57 |
| |
58 return g_test_run(); |
| |
59 } |