diff -r 651092763669 -r 599b01f2f5a7 libpurple/protocols/jabber/tests/test_jabber_caps.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/protocols/jabber/tests/test_jabber_caps.c Sun Mar 13 17:08:29 2016 -0500 @@ -0,0 +1,59 @@ +#include + +#include "xmlnode.h" +#include "ciphers/sha1hash.h" +#include "protocols/jabber/caps.h" + +static void +test_jabber_caps_parse_invalid_nodes(void) { + PurpleXmlNode *query; + + g_assert_null(jabber_caps_parse_client_info(NULL)); + + /* Something other than a disco#info query */ + query = purple_xmlnode_new("foo"); + g_assert_null(jabber_caps_parse_client_info(query)); + purple_xmlnode_free(query); + + query = purple_xmlnode_new("query"); + g_assert_null(jabber_caps_parse_client_info(query)); + + purple_xmlnode_set_namespace(query, "jabber:iq:last"); + g_assert_null(jabber_caps_parse_client_info(query)); + purple_xmlnode_free(query); +} + +static void +_test_jabber_caps_match(PurpleHash *hash, const gchar *in, const gchar *expected) { + PurpleXmlNode *query = purple_xmlnode_from_str(in, -1); + JabberCapsClientInfo *info = jabber_caps_parse_client_info(query); + gchar *got = NULL; + + got = jabber_caps_calculate_hash(info, hash); + g_object_unref(G_OBJECT(hash)); + + g_assert_cmpstr(expected, ==, got); + g_free(got); +} + +static void +test_jabber_caps_calculate_from_xmlnode(void) { + _test_jabber_caps_match( + purple_sha1_hash_new(), + "urn:xmpp:dataforms:softwareinfoTkabber ( 8.5.5 )ATmega640-16AU", + "GNjxthSckUNvAIoCCJFttjl6VL8=" + ); +} + +gint +main(gint argc, gchar **argv) { + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/jabber/caps/parse invalid nodes", + test_jabber_caps_parse_invalid_nodes); + + g_test_add_func("/jabber/caps/calulate from xmlnode", + test_jabber_caps_calculate_from_xmlnode); + + return g_test_run(); +}