mirror of
https://github.com/zeux/pugixml.git
synced 2025-01-14 01:47:55 +08:00
tests: Added node_doctype and parse_doctype tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@757 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
605ab1b145
commit
630be2edb3
@ -514,13 +514,16 @@ TEST_XML(dom_node_copy_crossdoc, "<node/>")
|
||||
CHECK_NODE(newdoc, STR("<node />"));
|
||||
}
|
||||
|
||||
TEST_XML_FLAGS(dom_node_copy_types, "<?xml version='1.0'?><root><?pi value?><!--comment--><node id='1'>pcdata<![CDATA[cdata]]></node></root>", parse_default | parse_pi | parse_comments | parse_declaration)
|
||||
TEST_XML_FLAGS(dom_node_copy_types, "<?xml version='1.0'?><!DOCTYPE id><root><?pi value?><!--comment--><node id='1'>pcdata<![CDATA[cdata]]></node></root>", parse_full)
|
||||
{
|
||||
doc.append_copy(doc.child(STR("root")));
|
||||
CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root>"));
|
||||
CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><!DOCTYPE id><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root>"));
|
||||
|
||||
doc.insert_copy_before(doc.first_child(), doc.first_child());
|
||||
CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><?xml version=\"1.0\"?><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root>"));
|
||||
CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><?xml version=\"1.0\"?><!DOCTYPE id><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root>"));
|
||||
|
||||
doc.insert_copy_after(doc.first_child().next_sibling().next_sibling(), doc.first_child());
|
||||
CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><!DOCTYPE id><?xml version=\"1.0\"?><!DOCTYPE id><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root>"));
|
||||
}
|
||||
|
||||
TEST_XML(dom_attr_assign_large_number, "<node attr1='' attr2='' />")
|
||||
@ -549,6 +552,16 @@ TEST(dom_node_declaration_name)
|
||||
CHECK_NODE(doc, STR("<?xml?><?xml?><?xml?>"));
|
||||
}
|
||||
|
||||
TEST(dom_node_declaration_attributes)
|
||||
{
|
||||
xml_document doc;
|
||||
xml_node node = doc.append_child(node_declaration);
|
||||
node.append_attribute(STR("version")) = STR("1.0");
|
||||
node.append_attribute(STR("encoding")) = STR("utf-8");
|
||||
|
||||
CHECK_NODE(doc, STR("<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
|
||||
}
|
||||
|
||||
TEST(dom_node_declaration_top_level)
|
||||
{
|
||||
xml_document doc;
|
||||
@ -677,3 +690,49 @@ TEST(dom_node_memory_limit)
|
||||
CHECK(doc.remove_child(doc.first_child()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(dom_node_doctype_top_level)
|
||||
{
|
||||
xml_document doc;
|
||||
doc.append_child().set_name(STR("node"));
|
||||
|
||||
xml_node node = doc.first_child();
|
||||
node.append_child(node_pcdata).set_value(STR("text"));
|
||||
|
||||
CHECK(node.insert_child_before(node_doctype, node.first_child()) == xml_node());
|
||||
CHECK(node.insert_child_after(node_doctype, node.first_child()) == xml_node());
|
||||
CHECK(node.append_child(node_doctype) == xml_node());
|
||||
|
||||
CHECK_NODE(doc, STR("<node>text</node>"));
|
||||
|
||||
CHECK(doc.insert_child_before(node_doctype, node));
|
||||
CHECK(doc.insert_child_after(node_doctype, node));
|
||||
CHECK(doc.append_child(node_doctype));
|
||||
|
||||
CHECK_NODE(doc, STR("<!DOCTYPE><node>text</node><!DOCTYPE><!DOCTYPE>"));
|
||||
}
|
||||
|
||||
TEST(dom_node_doctype_copy)
|
||||
{
|
||||
xml_document doc;
|
||||
doc.append_child(node_doctype);
|
||||
|
||||
doc.append_child().set_name(STR("node"));
|
||||
|
||||
doc.last_child().append_copy(doc.first_child());
|
||||
|
||||
CHECK_NODE(doc, STR("<!DOCTYPE><node />"));
|
||||
}
|
||||
|
||||
TEST(dom_node_doctype_value)
|
||||
{
|
||||
xml_document doc;
|
||||
xml_node node = doc.append_child(node_doctype);
|
||||
|
||||
CHECK(node.type() == node_doctype);
|
||||
CHECK_STRING(node.value(), STR(""));
|
||||
CHECK_NODE(node, STR("<!DOCTYPE>"));
|
||||
|
||||
CHECK(node.set_value(STR("id [ foo ]")));
|
||||
CHECK_NODE(node, STR("<!DOCTYPE id [ foo ]>"));
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ TEST_XML(dom_node_root, "<node><child/></node>")
|
||||
CHECK(doc.child(STR("node")).root() == doc);
|
||||
}
|
||||
|
||||
TEST_XML_FLAGS(dom_node_type, "<?xml?><?pi?><!--comment--><node>pcdata<![CDATA[cdata]]></node>", parse_default | parse_pi | parse_comments | parse_declaration)
|
||||
TEST_XML_FLAGS(dom_node_type, "<?xml?><!DOCTYPE><?pi?><!--comment--><node>pcdata<![CDATA[cdata]]></node>", parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype)
|
||||
{
|
||||
CHECK(xml_node().type() == node_null);
|
||||
CHECK(doc.type() == node_document);
|
||||
@ -355,6 +355,7 @@ TEST_XML_FLAGS(dom_node_type, "<?xml?><?pi?><!--comment--><node>pcdata<![CDATA[c
|
||||
xml_node_iterator it = doc.begin();
|
||||
|
||||
CHECK((it++)->type() == node_declaration);
|
||||
CHECK((it++)->type() == node_doctype);
|
||||
CHECK((it++)->type() == node_pi);
|
||||
CHECK((it++)->type() == node_comment);
|
||||
CHECK((it++)->type() == node_element);
|
||||
@ -365,7 +366,7 @@ TEST_XML_FLAGS(dom_node_type, "<?xml?><?pi?><!--comment--><node>pcdata<![CDATA[c
|
||||
CHECK((cit++)->type() == node_cdata);
|
||||
}
|
||||
|
||||
TEST_XML_FLAGS(dom_node_name_value, "<?xml?><?pi?><!--comment--><node>pcdata<![CDATA[cdata]]></node>", parse_default | parse_pi | parse_comments | parse_declaration)
|
||||
TEST_XML_FLAGS(dom_node_name_value, "<?xml?><!DOCTYPE id><?pi?><!--comment--><node>pcdata<![CDATA[cdata]]></node>", parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype)
|
||||
{
|
||||
CHECK_NAME_VALUE(xml_node(), STR(""), STR(""));
|
||||
CHECK_NAME_VALUE(doc, STR(""), STR(""));
|
||||
@ -373,6 +374,7 @@ TEST_XML_FLAGS(dom_node_name_value, "<?xml?><?pi?><!--comment--><node>pcdata<![C
|
||||
xml_node_iterator it = doc.begin();
|
||||
|
||||
CHECK_NAME_VALUE(*it++, STR("xml"), STR(""));
|
||||
CHECK_NAME_VALUE(*it++, STR(""), STR("id"));
|
||||
CHECK_NAME_VALUE(*it++, STR("pi"), STR(""));
|
||||
CHECK_NAME_VALUE(*it++, STR(""), STR("comment"));
|
||||
CHECK_NAME_VALUE(*it++, STR("node"), STR(""));
|
||||
@ -740,7 +742,7 @@ TEST_XML(dom_node_traverse_stop_end, "<node><child>text</child></node>")
|
||||
CHECK(walker.log == STR("|-1 <=|0 !node=|1 !child=|2 !=text|-1 >="));
|
||||
}
|
||||
|
||||
TEST_XML_FLAGS(dom_offset_debug, "<?xml?><?pi?><!--comment--><node>pcdata<![CDATA[cdata]]></node>", parse_default | parse_pi | parse_comments | parse_declaration)
|
||||
TEST_XML_FLAGS(dom_offset_debug, "<?xml?><!DOCTYPE><?pi?><!--comment--><node>pcdata<![CDATA[cdata]]></node>", parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype)
|
||||
{
|
||||
CHECK(xml_node().offset_debug() == -1);
|
||||
CHECK(doc.offset_debug() == 0);
|
||||
@ -748,14 +750,15 @@ TEST_XML_FLAGS(dom_offset_debug, "<?xml?><?pi?><!--comment--><node>pcdata<![CDAT
|
||||
xml_node_iterator it = doc.begin();
|
||||
|
||||
CHECK((it++)->offset_debug() == 2);
|
||||
CHECK((it++)->offset_debug() == 9);
|
||||
CHECK((it++)->offset_debug() == 17);
|
||||
CHECK((it++)->offset_debug() == 28);
|
||||
CHECK((it++)->offset_debug() == 16);
|
||||
CHECK((it++)->offset_debug() == 19);
|
||||
CHECK((it++)->offset_debug() == 27);
|
||||
CHECK((it++)->offset_debug() == 38);
|
||||
|
||||
xml_node_iterator cit = doc.child(STR("node")).begin();
|
||||
|
||||
CHECK((cit++)->offset_debug() == 33);
|
||||
CHECK((cit++)->offset_debug() == 48);
|
||||
CHECK((cit++)->offset_debug() == 43);
|
||||
CHECK((cit++)->offset_debug() == 58);
|
||||
}
|
||||
|
||||
TEST_XML(dom_internal_object, "<node attr='value'>value</node>")
|
||||
|
@ -40,8 +40,9 @@ static bool test_doctype_wf(const char_t* decl)
|
||||
if (!load_concat(doc, decl, STR("<nodeb/>")) || !test_node(doc, STR("<nodeb />"), STR(""), format_raw)) return false;
|
||||
if (!load_concat(doc, STR("<nodea/>"), decl, STR("<nodeb/>")) || !test_node(doc, STR("<nodea /><nodeb />"), STR(""), format_raw)) return false;
|
||||
|
||||
// wrap in node to check that doctype is parsed fully (does not leave any "pcdata")
|
||||
if (!load_concat(doc, STR("<node>"), decl, STR("</node>")) || !test_node(doc, STR("<node />"), STR(""), format_raw)) return false;
|
||||
// check load-store contents preservation
|
||||
CHECK(doc.load(decl, parse_doctype));
|
||||
CHECK_NODE(doc, decl);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -276,9 +277,12 @@ TEST(parse_doctype_xmlconf_oasis_1)
|
||||
TEST_DOCTYPE_WF("<!DOCTYPE doc [ <!ELEMENT doc EMPTY> <!NOTATION not1 SYSTEM \"a%a&b�<!ELEMENT<!--<?</>?>/\''\"> <!NOTATION not2 SYSTEM 'a b\"\"\"'> <!NOTATION not3 SYSTEM \"\"> <!NOTATION not4 SYSTEM ''> ]>");
|
||||
TEST_DOCTYPE_WF("<!DOCTYPE doc [ <!ELEMENT doc EMPTY> <!NOTATION not1 PUBLIC \"<\"> ]>");
|
||||
TEST_DOCTYPE_WF("<!DOCTYPE doc [ <!ELEMENT doc EMPTY> <!NOTATION not1 PUBLIC \"a b cdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"> <!NOTATION not2 PUBLIC '0123456789-()+,./:=?;!*#@$_%'> <!NOTATION not3 PUBLIC \"0123456789-()+,.'/:=?;!*#@$_%\"> ]>");
|
||||
TEST_DOCTYPE_WF("<!--a <!DOCTYPE <?- ]]>-<[ CDATA [ \"- -'- -<doc>--> <!---->"); // not actually a doctype :)
|
||||
TEST_DOCTYPE_WF("<?xmla <!DOCTYPE <[ CDATA [</doc> &a%b&#c?>"); // not actually a doctype :)
|
||||
TEST_DOCTYPE_WF("<!DOCTYPE doc SYSTEM \"p31pass1.dtd\" [<!ELEMENT doc EMPTY>]>");
|
||||
|
||||
// not actually a doctype :)
|
||||
xml_document doc;
|
||||
CHECK(doc.load(STR("<!--a <!DOCTYPE <?- ]]>-<[ CDATA [ \"- -'- -<doc>--> <!---->"), parse_full) && doc.first_child().type() == node_comment && doc.last_child().type() == node_comment && doc.first_child().next_sibling() == doc.last_child());
|
||||
CHECK(doc.load(STR("<?xmla <!DOCTYPE <[ CDATA [</doc> &a%b&#c?>"), parse_full) && doc.first_child().type() == node_pi && doc.first_child() == doc.last_child());
|
||||
}
|
||||
|
||||
TEST(parse_doctype_xmlconf_xmltest_1)
|
||||
@ -294,3 +298,18 @@ TEST(parse_doctype_xmlconf_xmltest_1)
|
||||
TEST_DOCTYPE_WF("<!DOCTYPE doc [ <!ENTITY e \"<foo a='&'></foo>\"> ]>");
|
||||
TEST_DOCTYPE_WF("<!DOCTYPE doc [ <!ELEMENT doc (#PCDATA)> <!ENTITY e \"<![CDATA[Tim & Michael]]>\"> ]>");
|
||||
}
|
||||
|
||||
TEST_XML_FLAGS(parse_doctype_value, "<!DOCTYPE doc [ <!ELEMENT doc (#PCDATA)> <!ENTITY e \"<![CDATA[Tim & Michael]]>\"> ]>", parse_minimal | parse_doctype)
|
||||
{
|
||||
xml_node n = doc.first_child();
|
||||
|
||||
CHECK(n.type() == node_doctype);
|
||||
CHECK_STRING(n.value(), STR("doc [ <!ELEMENT doc (#PCDATA)> <!ENTITY e \"<![CDATA[Tim & Michael]]>\"> ]"));
|
||||
}
|
||||
|
||||
TEST(parse_doctype_error_toplevel)
|
||||
{
|
||||
xml_document doc;
|
||||
CHECK(doc.load(STR("<node><!DOCTYPE></node>")).status == status_bad_doctype);
|
||||
CHECK(doc.load(STR("<node><!DOCTYPE></node>"), parse_doctype).status == status_bad_doctype);
|
||||
}
|
||||
|
@ -63,6 +63,12 @@ TEST_XML_FLAGS(write_declaration, "<?xml version='2.0'?>", parse_default | parse
|
||||
CHECK_NODE_EX(doc, STR("<?xml version=\"2.0\"?>\n"), STR(""), 0);
|
||||
}
|
||||
|
||||
TEST_XML_FLAGS(write_doctype, "<!DOCTYPE id [ foo ]>", parse_default | parse_doctype)
|
||||
{
|
||||
CHECK_NODE(doc, STR("<!DOCTYPE id [ foo ]>"));
|
||||
CHECK_NODE_EX(doc, STR("<!DOCTYPE id [ foo ]>\n"), STR(""), 0);
|
||||
}
|
||||
|
||||
TEST_XML(write_escape, "<node attr=''>text</node>")
|
||||
{
|
||||
doc.child(STR("node")).attribute(STR("attr")) = STR("<>'\"&\x04\r\n\t");
|
||||
|
Loading…
x
Reference in New Issue
Block a user