summaryrefslogtreecommitdiff
path: root/tests/test_dom_modify.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-10-26 17:09:34 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-10-26 17:09:34 +0000
commit09b5dfdcb0707c39874997efbf207ff554334c34 (patch)
tree6f1ec740a22d766a419574e95122aa7322342179 /tests/test_dom_modify.cpp
parent948cb037aec073255d71a19ae1f9f5a351deff72 (diff)
Added xml_document::reset, added append/prepend/insert child overloads for elements (with explicit name)
git-svn-id: http://pugixml.googlecode.com/svn/trunk@779 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_dom_modify.cpp')
-rw-r--r--tests/test_dom_modify.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp
index b6155c1..70a01cc 100644
--- a/tests/test_dom_modify.cpp
+++ b/tests/test_dom_modify.cpp
@@ -469,6 +469,78 @@ TEST_XML(dom_node_insert_child_before, "<node>foo<child/></node>")
CHECK_NODE(doc, STR("<node><?n4?>foo<n1 />n3<n2 /><child /></node>"));
}
+TEST_XML(dom_node_prepend_child_name, "<node>foo<child/></node>")
+{
+ CHECK(xml_node().prepend_child(STR("")) == xml_node());
+ CHECK(doc.child(STR("node")).first_child().prepend_child(STR("")) == xml_node());
+
+ xml_node n1 = doc.child(STR("node")).prepend_child(STR("n1"));
+ CHECK(n1);
+
+ xml_node n2 = doc.child(STR("node")).prepend_child(STR("n2"));
+ CHECK(n2 && n1 != n2);
+
+ CHECK_NODE(doc, STR("<node><n2 /><n1 />foo<child /></node>"));
+}
+
+TEST_XML(dom_node_append_child_name, "<node>foo<child/></node>")
+{
+ CHECK(xml_node().append_child(STR("")) == xml_node());
+ CHECK(doc.child(STR("node")).first_child().append_child(STR("")) == xml_node());
+
+ xml_node n1 = doc.child(STR("node")).append_child(STR("n1"));
+ CHECK(n1);
+
+ xml_node n2 = doc.child(STR("node")).append_child(STR("n2"));
+ CHECK(n2 && n1 != n2);
+
+ CHECK_NODE(doc, STR("<node>foo<child /><n1 /><n2 /></node>"));
+}
+
+TEST_XML(dom_node_insert_child_after_name, "<node>foo<child/></node>")
+{
+ CHECK(xml_node().insert_child_after(STR(""), xml_node()) == xml_node());
+ CHECK(doc.child(STR("node")).first_child().insert_child_after(STR(""), xml_node()) == xml_node());
+
+ xml_node node = doc.child(STR("node"));
+ xml_node child = node.child(STR("child"));
+
+ CHECK(node.insert_child_after(STR(""), node) == xml_node());
+ CHECK(child.insert_child_after(STR(""), node) == xml_node());
+
+ xml_node n1 = node.insert_child_after(STR("n1"), child);
+ CHECK(n1 && n1 != node && n1 != child);
+
+ xml_node n2 = node.insert_child_after(STR("n2"), child);
+ CHECK(n2 && n2 != node && n2 != child && n2 != n1);
+
+ CHECK(child.insert_child_after(STR(""), n2) == xml_node());
+
+ CHECK_NODE(doc, STR("<node>foo<child /><n2 /><n1 /></node>"));
+}
+
+TEST_XML(dom_node_insert_child_before_name, "<node>foo<child/></node>")
+{
+ CHECK(xml_node().insert_child_before(STR(""), xml_node()) == xml_node());
+ CHECK(doc.child(STR("node")).first_child().insert_child_before(STR(""), xml_node()) == xml_node());
+
+ xml_node node = doc.child(STR("node"));
+ xml_node child = node.child(STR("child"));
+
+ CHECK(node.insert_child_before(STR(""), node) == xml_node());
+ CHECK(child.insert_child_before(STR(""), node) == xml_node());
+
+ xml_node n1 = node.insert_child_before(STR("n1"), child);
+ CHECK(n1 && n1 != node && n1 != child);
+
+ xml_node n2 = node.insert_child_before(STR("n2"), child);
+ CHECK(n2 && n2 != node && n2 != child && n2 != n1);
+
+ CHECK(child.insert_child_before(STR(""), n2) == xml_node());
+
+ CHECK_NODE(doc, STR("<node>foo<n1 /><n2 /><child /></node>"));
+}
+
TEST_XML(dom_node_remove_child, "<node><n1/><n2/><n3/><child><n4/></child></node>")
{
CHECK(!xml_node().remove_child(STR("a")));