From b979d4c2bd1e8f445befd53ea8357b594f1ca3b2 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine@gmail.com" Date: Tue, 19 Oct 2010 14:29:02 +0000 Subject: Added prepend_attribute, prepend_child and prepend_copy functions git-svn-id: http://pugixml.googlecode.com/svn/trunk@769 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_dom_modify.cpp | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) (limited to 'tests') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index eefda58..b6155c1 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -78,6 +78,26 @@ TEST_XML(dom_node_set_value_allocated, "text") CHECK_NODE(doc, STR("no text at all")); } +TEST_XML(dom_node_prepend_attribute, "") +{ + CHECK(xml_node().prepend_attribute(STR("a")) == xml_attribute()); + CHECK(doc.prepend_attribute(STR("a")) == xml_attribute()); + + xml_attribute a1 = doc.child(STR("node")).prepend_attribute(STR("a1")); + CHECK(a1); + a1 = STR("v1"); + + xml_attribute a2 = doc.child(STR("node")).prepend_attribute(STR("a2")); + CHECK(a2 && a1 != a2); + a2 = STR("v2"); + + xml_attribute a3 = doc.child(STR("node")).child(STR("child")).prepend_attribute(STR("a3")); + CHECK(a3 && a1 != a3 && a2 != a3); + a3 = STR("v3"); + + CHECK_NODE(doc, STR("")); +} + TEST_XML(dom_node_append_attribute, "") { CHECK(xml_node().append_attribute(STR("a")) == xml_attribute()); @@ -158,6 +178,42 @@ TEST_XML(dom_node_insert_attribute_before, "")); } +TEST_XML(dom_node_prepend_copy_attribute, "") +{ + CHECK(xml_node().prepend_copy(xml_attribute()) == xml_attribute()); + CHECK(xml_node().prepend_copy(doc.child(STR("node")).attribute(STR("a1"))) == xml_attribute()); + CHECK(doc.prepend_copy(doc.child(STR("node")).attribute(STR("a1"))) == xml_attribute()); + CHECK(doc.child(STR("node")).prepend_copy(xml_attribute()) == xml_attribute()); + + xml_node node = doc.child(STR("node")); + xml_node child = node.child(STR("child")); + + xml_attribute a1 = node.attribute(STR("a1")); + xml_attribute a2 = child.attribute(STR("a2")); + + xml_attribute a3 = node.prepend_copy(a1); + CHECK(a3 && a3 != a2 && a3 != a1); + + xml_attribute a4 = node.prepend_copy(a2); + CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1); + + xml_attribute a5 = node.last_child().prepend_copy(a1); + CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1); + + CHECK_NODE(doc, STR("")); + + a3.set_name(STR("a3")); + a3 = STR("v3"); + + a4.set_name(STR("a4")); + a4 = STR("v4"); + + a5.set_name(STR("a5")); + a5 = STR("v5"); + + CHECK_NODE(doc, STR("")); +} + TEST_XML(dom_node_append_copy_attribute, "") { CHECK(xml_node().append_copy(xml_attribute()) == xml_attribute()); @@ -293,6 +349,32 @@ TEST_XML(dom_node_remove_attribute, "foo") +{ + CHECK(xml_node().prepend_copy(xml_node()) == xml_node()); + CHECK(doc.child(STR("node")).first_child().prepend_copy(doc.child(STR("node"))) == xml_node()); + CHECK(doc.prepend_copy(doc) == xml_node()); + CHECK(doc.prepend_copy(xml_node()) == xml_node()); + + xml_node n1 = doc.child(STR("node")).prepend_copy(doc.child(STR("node")).first_child()); + CHECK(n1); + CHECK_STRING(n1.value(), STR("foo")); + CHECK_NODE(doc, STR("foofoo")); + + xml_node n2 = doc.child(STR("node")).prepend_copy(doc.child(STR("node")).child(STR("child"))); + CHECK(n2 && n2 != n1); + CHECK_STRING(n2.name(), STR("child")); + CHECK_NODE(doc, STR("foofoo")); + + xml_node n3 = doc.child(STR("node")).child(STR("child")).prepend_copy(doc.child(STR("node")).first_child().next_sibling()); + CHECK(n3 && n3 != n1 && n3 != n2); + CHECK_STRING(n3.value(), STR("foo")); + CHECK_NODE(doc, STR("foofoofoo")); +} + TEST_XML(dom_node_append_copy, "foo") { CHECK(xml_node().append_copy(xml_node()) == xml_node()); -- cgit v1.2.3