From a562014cc24ff060266de8c3cc951263e4efa750 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sat, 12 Jun 2010 09:04:52 +0000 Subject: Declaration nodes improvements (they now automatically get name "xml", they can't be inserted as a non-document child, document saving prints declaration only if there is none present in the document) git-svn-id: http://pugixml.googlecode.com/svn/trunk@517 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_dom_modify.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'tests/test_dom_modify.cpp') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 31647d4..e1e47f7 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -532,3 +532,51 @@ TEST_XML(dom_attr_assign_large_number, "") CHECK(test_node(node, STR(""), STR(""), pugi::format_raw) || test_node(node, STR(""), STR(""), pugi::format_raw)); } + +TEST(dom_node_declaration_name) +{ + xml_document doc; + doc.append_child(node_declaration); + + // name 'xml' is auto-assigned + CHECK(doc.first_child().type() == node_declaration); + CHECK_STRING(doc.first_child().name(), STR("xml")); + + doc.insert_child_after(node_declaration, doc.first_child()); + doc.insert_child_before(node_declaration, doc.first_child()); + + CHECK_NODE(doc, STR("")); +} + +TEST(dom_node_declaration_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_declaration, node.first_child()) == xml_node()); + CHECK(node.insert_child_after(node_declaration, node.first_child()) == xml_node()); + CHECK(node.append_child(node_declaration) == xml_node()); + + CHECK_NODE(doc, STR("text")); + + CHECK(doc.insert_child_before(node_declaration, node)); + CHECK(doc.insert_child_after(node_declaration, node)); + CHECK(doc.append_child(node_declaration)); + + CHECK_NODE(doc, STR("text")); +} + +TEST(dom_node_declaration_copy) +{ + xml_document doc; + doc.append_child(node_declaration); + + doc.append_child().set_name(STR("node")); + + doc.last_child().append_copy(doc.first_child()); + + CHECK_NODE(doc, STR("")); +} -- cgit v1.2.3