Mercurial > pidgin
comparison libpurple/tests/test_xmlnode.c @ 32038:8d3b5853b017
xmlnode: Add xmlnode_strip_prefixes
This is largely based on a patch from Thijs (sphynx/xnyhps) Alkemade, with
some modifications by me to try to maintain namespaces of elements
as best as we can.
I also rewrote xmlnode_get_default_namespace not to use recursion.
References #14529
| author | Paul Aurich <paul@darkrain42.org> |
|---|---|
| date | Sun, 04 Sep 2011 21:06:26 +0000 |
| parents | 114a98da1a5f |
| children |
comparison
equal
deleted
inserted
replaced
| 32037:114a98da1a5f | 32038:8d3b5853b017 |
|---|---|
| 79 xmlnode_free(xml); | 79 xmlnode_free(xml); |
| 80 xmlnode_free(reparsed); | 80 xmlnode_free(reparsed); |
| 81 } | 81 } |
| 82 END_TEST | 82 END_TEST |
| 83 | 83 |
| 84 | |
| 85 START_TEST(test_strip_prefixes) | |
| 86 { | |
| 87 const char *xml_doc = "<message xmlns='jabber:client' from='user@gmail.com/resource' to='another_user@darkrain42.org' type='chat' id='purple'>" | |
| 88 "<cha:active xmlns:cha='http://jabber.org/protocol/chatstates'/>" | |
| 89 "<body>xvlc xvlc</body>" | |
| 90 "<im:html xmlns:im='http://jabber.org/protocol/xhtml-im'>" | |
| 91 "<xht:body xmlns:xht='http://www.w3.org/1999/xhtml'>" | |
| 92 "<xht:p>xvlc <xht:span style='font-weight: bold;'>xvlc</xht:span></xht:p>" | |
| 93 "</xht:body>" | |
| 94 "</im:html>" | |
| 95 "</message>"; | |
| 96 const char *out = "<message xmlns='jabber:client' from='user@gmail.com/resource' to='another_user@darkrain42.org' type='chat' id='purple'>" | |
| 97 "<active xmlns:cha='http://jabber.org/protocol/chatstates' xmlns='http://jabber.org/protocol/chatstates'/>" | |
| 98 "<body>xvlc xvlc</body>" | |
| 99 "<html xmlns:im='http://jabber.org/protocol/xhtml-im' xmlns='http://jabber.org/protocol/xhtml-im'>" | |
| 100 "<body xmlns:xht='http://www.w3.org/1999/xhtml' xmlns='http://www.w3.org/1999/xhtml'>" | |
| 101 "<p>xvlc <span style='font-weight: bold;'>xvlc</span></p>" | |
| 102 "</body>" | |
| 103 "</html>" | |
| 104 "</message>"; | |
| 105 char *str; | |
| 106 xmlnode *xml; | |
| 107 | |
| 108 xml = xmlnode_from_str(xml_doc, -1); | |
| 109 fail_if(xml == NULL, "Failed to parse XML"); | |
| 110 | |
| 111 xmlnode_strip_prefixes(xml); | |
| 112 str = xmlnode_to_str(xml, NULL); | |
| 113 assert_string_equal_free(out, str); | |
| 114 | |
| 115 xmlnode_free(xml); | |
| 116 } | |
| 117 END_TEST | |
| 118 | |
| 84 Suite * | 119 Suite * |
| 85 xmlnode_suite(void) | 120 xmlnode_suite(void) |
| 86 { | 121 { |
| 87 Suite *s = suite_create("Utility Functions"); | 122 Suite *s = suite_create("Utility Functions"); |
| 88 | 123 |
| 89 TCase *tc = tcase_create("xmlnode"); | 124 TCase *tc = tcase_create("xmlnode"); |
| 90 tcase_add_test(tc, test_xmlnode_billion_laughs_attack); | 125 tcase_add_test(tc, test_xmlnode_billion_laughs_attack); |
| 91 tcase_add_test(tc, test_xmlnode_prefixes); | 126 tcase_add_test(tc, test_xmlnode_prefixes); |
| 127 tcase_add_test(tc, test_strip_prefixes); | |
| 92 | 128 |
| 93 suite_add_tcase(s, tc); | 129 suite_add_tcase(s, tc); |
| 94 | 130 |
| 95 return s; | 131 return s; |
| 96 } | 132 } |
