Mercurial > pidgin
changeset 30254:6362579b3d2e
jabber: Start adding some caps tests
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Fri, 09 Jul 2010 22:14:03 +0000 |
parents | 22afdd5a9290 |
children | 502b9d2f2d7a |
files | libpurple/protocols/jabber/caps.c libpurple/protocols/jabber/caps.h libpurple/tests/Makefile.am libpurple/tests/check_libpurple.c libpurple/tests/test_jabber_caps.c libpurple/tests/tests.h |
diffstat | 6 files changed, 54 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/caps.c Thu Jul 08 21:27:36 2010 +0000 +++ b/libpurple/protocols/jabber/caps.c Fri Jul 09 22:14:03 2010 +0000 @@ -41,14 +41,6 @@ static GHashTable *nodetable = NULL; /* char *node -> JabberCapsNodeExts */ static guint save_timer = 0; -/** - * Processes a query-node and returns a JabberCapsClientInfo object with all relevant info. - * - * @param query A query object. - * @return A JabberCapsClientInfo object. - */ -static JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query); - /* Free a GList of allocated char* */ static void free_string_glist(GList *list) @@ -764,13 +756,14 @@ return result; } -static JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query) +JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query) { xmlnode *child; JabberCapsClientInfo *info; - if (!query || strcmp(query->xmlns, NS_DISCO_INFO)) - return 0; + if (!query || !g_str_equal(query->name, "query") || + !purple_strequal(query->xmlns, NS_DISCO_INFO)) + return NULL; info = g_new0(JabberCapsClientInfo, 1);
--- a/libpurple/protocols/jabber/caps.h Thu Jul 08 21:27:36 2010 +0000 +++ b/libpurple/protocols/jabber/caps.h Fri Jul 09 22:14:03 2010 +0000 @@ -115,4 +115,15 @@ */ void jabber_caps_broadcast_change(void); +/** + * Parse the <query/> element from an IQ stanza into a JabberCapsClientInfo + * struct. + * + * Exposed for tests + * + * @param query The 'query' element from an IQ reply stanza. + * @returns A JabberCapsClientInfo struct, or NULL on error + */ +JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query); + #endif /* PURPLE_JABBER_CAPS_H_ */
--- a/libpurple/tests/Makefile.am Thu Jul 08 21:27:36 2010 +0000 +++ b/libpurple/tests/Makefile.am Fri Jul 09 22:14:03 2010 +0000 @@ -10,6 +10,7 @@ check_libpurple.c \ tests.h \ test_cipher.c \ + test_jabber_caps.c \ test_jabber_jutil.c \ test_jabber_scram.c \ test_qq.c \
--- a/libpurple/tests/check_libpurple.c Thu Jul 08 21:27:36 2010 +0000 +++ b/libpurple/tests/check_libpurple.c Fri Jul 09 22:14:03 2010 +0000 @@ -84,6 +84,7 @@ sr = srunner_create (master_suite()); srunner_add_suite(sr, cipher_suite()); + srunner_add_suite(sr, jabber_caps_suite()); srunner_add_suite(sr, jabber_jutil_suite()); srunner_add_suite(sr, jabber_scram_suite()); srunner_add_suite(sr, qq_suite());
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/tests/test_jabber_caps.c Fri Jul 09 22:14:03 2010 +0000 @@ -0,0 +1,36 @@ +#include <string.h> + +#include "tests.h" +#include "../xmlnode.h" +#include "../protocols/jabber/caps.h" + +START_TEST(test_parse_invalid) +{ + xmlnode *query; + + fail_unless(NULL == jabber_caps_parse_client_info(NULL)); + + /* Something other than a disco#info query */ + query = xmlnode_new("foo"); + fail_unless(NULL == jabber_caps_parse_client_info(query)); + xmlnode_free(query); + + query = xmlnode_new("query"); + fail_unless(NULL == jabber_caps_parse_client_info(query)); + xmlnode_set_namespace(query, "jabber:iq:last"); + fail_unless(NULL == jabber_caps_parse_client_info(query)); + xmlnode_free(query); +} +END_TEST + +Suite * +jabber_caps_suite(void) +{ + Suite *s = suite_create("Jabber Caps Functions"); + + TCase *tc = tcase_create("Parsing invalid ndoes"); + tcase_add_test(tc, test_parse_invalid); + suite_add_tcase(s, tc); + + return s; +}
--- a/libpurple/tests/tests.h Thu Jul 08 21:27:36 2010 +0000 +++ b/libpurple/tests/tests.h Fri Jul 09 22:14:03 2010 +0000 @@ -9,6 +9,7 @@ /* remember to add the suite to the runner in check_libpurple.c */ Suite * master_suite(void); Suite * cipher_suite(void); +Suite * jabber_caps_suite(void); Suite * jabber_jutil_suite(void); Suite * jabber_scram_suite(void); Suite * qq_suite(void);