/pidgin/main: 773815a9a48f: Convert the xmlnode tests to gtester
Gary Kramlich <[email protected]>
| Newsgroups | gmane.comp.gnome.gaim.cvs |
|---|---|
| Message-ID | <[email protected]> |
Changeset: 773815a9a48f5dffcd0d05db0b9f3ed1116dc5a2 Author: Gary Kramlich <[email protected]> Date: 2016-03-13 17:59 -0500 Branch: default URL: https://hg.pidgin.im/pidgin/main/rev/773815a9a48f Description: Convert the xmlnode tests to gtester diffstat: libpurple/tests/.hgignore | 1 + libpurple/tests/Makefile.am | 6 ++- libpurple/tests/test_xmlnode.c | 78 +++++++++++++++++++---------------------- 3 files changed, 42 insertions(+), 43 deletions(-) diffs (182 lines): diff --git a/libpurple/tests/.hgignore b/libpurple/tests/.hgignore --- a/libpurple/tests/.hgignore +++ b/libpurple/tests/.hgignore @@ -5,6 +5,7 @@ syntax: regexp ^test_hmac$ ^test_trie$ ^test_util$ +^test_xmlnode$ syntax: glob *.log diff --git a/libpurple/tests/Makefile.am b/libpurple/tests/Makefile.am --- a/libpurple/tests/Makefile.am +++ b/libpurple/tests/Makefile.am @@ -14,7 +14,8 @@ test_programs=\ test_sha1 \ test_sha256 \ test_trie \ - test_util + test_util \ + test_xmlnode test_des_SOURCES=test_des.c @@ -44,6 +45,9 @@ test_trie_LDADD=$(COMMON_LIBS) test_util_SOURCES=test_util.c test_util_LDADD=$(COMMON_LIBS) +test_xmlnode_SOURCES=test_xmlnode.c +test_xmlnode_LDADD=$(COMMON_LIBS) + AM_CPPFLAGS = \ -I$(top_srcdir)/libpurple \ -I$(top_builddir)/libpurple \ diff --git a/libpurple/tests/test_xmlnode.c b/libpurple/tests/test_xmlnode.c --- a/libpurple/tests/test_xmlnode.c +++ b/libpurple/tests/test_xmlnode.c @@ -1,6 +1,5 @@ -#include <string.h> +#include <glib.h> -#include "tests.h" #include "../xmlnode.h" /* @@ -8,52 +7,50 @@ * need to have more than just 4 ha's. But as long as this shorter * document fails to parse, the longer one should also fail to parse. */ -START_TEST(test_xmlnode_billion_laughs_attack) -{ +static void +test_xmlnode_billion_laughs_attack(void) { const char *malicious_xml_doc = "<!DOCTYPE root [ <!ENTITY ha \"Ha !\"><!ENTITY ha2 \"&ha; &ha;\"><!ENTITY ha3 \"&ha2; &ha2;\"> ]><root>&ha3;</root>"; /* Uncomment this line if you want to see the error message given by the parser for the above XML document */ /* purple_debug_set_enabled(TRUE); */ - fail_if(purple_xmlnode_from_str(malicious_xml_doc, -1), - "purple_xmlnode_from_str() returned an XML tree, but we didn't want it to"); + g_assert_null(purple_xmlnode_from_str(malicious_xml_doc, -1)); } -END_TEST #define check_doc_structure(x) { \ PurpleXmlNode *ping, *child1, *child2; \ - fail_if(x == NULL, "Failed to parse document"); \ + g_assert_nonnull(x); \ ping = purple_xmlnode_get_child(x, "ping"); \ - fail_if(ping == NULL, "Failed to find 'ping' child"); \ + g_assert_nonnull(ping); \ child1 = purple_xmlnode_get_child(ping, "child1"); \ - fail_if(child1 == NULL, "Failed to find 'child1'"); \ + g_assert_nonnull(child1); \ child2 = purple_xmlnode_get_child(child1, "child2"); \ - fail_if(child2 == NULL, "Failed to find 'child2'"); \ + g_assert_nonnull(child2); \ purple_xmlnode_new_child(child2, "a"); \ \ - assert_string_equal("jabber:client", purple_xmlnode_get_namespace(x)); \ + g_assert_cmpstr("jabber:client", ==, purple_xmlnode_get_namespace(x)); \ /* NOTE: purple_xmlnode_get_namespace() returns the namespace of the element, not the * current default namespace. See http://www.w3.org/TR/xml-names/#defaulting and * http://www.w3.org/TR/xml-names/#dt-defaultNS. */ \ - assert_string_equal("urn:xmpp:ping", purple_xmlnode_get_namespace(ping)); \ - assert_string_equal("jabber:client", purple_xmlnode_get_namespace(child1)); \ - assert_string_equal("urn:xmpp:ping", purple_xmlnode_get_namespace(child2)); \ + g_assert_cmpstr("urn:xmpp:ping", ==, purple_xmlnode_get_namespace(ping)); \ + g_assert_cmpstr("jabber:client", ==, purple_xmlnode_get_namespace(child1)); \ + g_assert_cmpstr("urn:xmpp:ping", ==, purple_xmlnode_get_namespace(child2)); \ /* * This fails (well, actually crashes [the ns is NULL]) unless * purple_xmlnode_new_child() actually sets the element namespace. - assert_string_equal("jabber:client", purple_xmlnode_get_namespace(purple_xmlnode_get_child(child2, "a"))); + g_assert_cmpstr("jabber:client", ==, purple_xmlnode_get_namespace(purple_xmlnode_get_child(child2, "a"))); */ \ \ - assert_string_equal("jabber:client", purple_xmlnode_get_default_namespace(x)); \ - assert_string_equal("jabber:client", purple_xmlnode_get_default_namespace(ping)); \ - assert_string_equal("jabber:client", purple_xmlnode_get_default_namespace(child1)); \ - assert_string_equal("jabber:client", purple_xmlnode_get_default_namespace(child2)); \ + g_assert_cmpstr("jabber:client", ==, purple_xmlnode_get_default_namespace(x)); \ + g_assert_cmpstr("jabber:client", ==, purple_xmlnode_get_default_namespace(ping)); \ + g_assert_cmpstr("jabber:client", ==, purple_xmlnode_get_default_namespace(child1)); \ + g_assert_cmpstr("jabber:client", ==, purple_xmlnode_get_default_namespace(child2)); \ } -START_TEST(test_xmlnode_prefixes) -{ +static void +test_xmlnode_prefixes(void) { const char *xml_doc = "<iq type='get' xmlns='jabber:client' xmlns:ping='urn:xmpp:ping'>" "<ping:ping>" @@ -70,20 +67,18 @@ START_TEST(test_xmlnode_prefixes) /* Check that purple_xmlnode_from_str(purple_xmlnode_to_str(xml, NULL), -1) is idempotent. */ str = purple_xmlnode_to_str(xml, NULL); - fail_if(str == NULL, "Failed to serialize XMLnode"); + g_assert_nonnull(str); reparsed = purple_xmlnode_from_str(str, -1); - fail_if(reparsed == NULL, "Failed to reparse xml document"); + g_assert_nonnull(reparsed); check_doc_structure(reparsed); g_free(str); purple_xmlnode_free(xml); purple_xmlnode_free(reparsed); } -END_TEST - -START_TEST(test_strip_prefixes) -{ +static void +test_strip_prefixes(void) { const char *xml_doc = "<message xmlns='jabber:client' from='[email protected]/resource' to='[email protected]' type='chat' id='purple'>" "<cha:active xmlns:cha='http://jabber.org/protocol/chatstates'/>" "<body>xvlc xvlc</body>" @@ -106,27 +101,26 @@ START_TEST(test_strip_prefixes) PurpleXmlNode *xml; xml = purple_xmlnode_from_str(xml_doc, -1); - fail_if(xml == NULL, "Failed to parse XML"); + g_assert_nonnull(xml); purple_xmlnode_strip_prefixes(xml); str = purple_xmlnode_to_str(xml, NULL); - assert_string_equal_free(out, str); + g_assert_cmpstr(out, ==, str); + g_free(str); purple_xmlnode_free(xml); } -END_TEST -Suite * -purple_xmlnode_suite(void) -{ - Suite *s = suite_create("Utility Functions"); +gint +main(gint argc, gchar **argv) { + g_test_init(&argc, &argv, NULL); - TCase *tc = tcase_create("xmlnode"); - tcase_add_test(tc, test_xmlnode_billion_laughs_attack); - tcase_add_test(tc, test_xmlnode_prefixes); - tcase_add_test(tc, test_strip_prefixes); + g_test_add_func("/xmlnode/billion_laughs_attack", + test_xmlnode_billion_laughs_attack); + g_test_add_func("/xmlnode/prefixes", + test_xmlnode_prefixes); + g_test_add_func("/xmlnode/strip_prefixes", + test_strip_prefixes); - suite_add_tcase(s, tc); - - return s; + return g_test_run(); } _______________________________________________ Commits mailing list [email protected] https://pidgin.im/cgi-bin/mailman/listinfo/commits