From 6ffd2ffc418eab0699124d2739f487782460a263 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 31 Jan 2017 00:10:20 -0800 Subject: tests: Add more DOM coverage tests Add tests for various corner cases of DOM inspection and modification routines. --- tests/test_dom_modify.cpp | 28 ++++++++++++++++++++-------- tests/test_dom_traverse.cpp | 17 +++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index f2d7ea8..7b26c5f 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -389,7 +389,7 @@ TEST_XML(dom_node_append_copy_attribute, " CHECK_NODE(doc, STR("")); } -TEST_XML(dom_node_insert_copy_after_attribute, "") +TEST_XML(dom_node_insert_copy_after_attribute, "text") { CHECK(xml_node().insert_copy_after(xml_attribute(), xml_attribute()) == xml_attribute()); @@ -402,6 +402,7 @@ TEST_XML(dom_node_insert_copy_after_attribute, "")); + CHECK_NODE(doc, STR("text")); a3.set_name(STR("a3")); a3 = STR("v3"); @@ -425,10 +426,10 @@ TEST_XML(dom_node_insert_copy_after_attribute, "")); + CHECK_NODE(doc, STR("text")); } -TEST_XML(dom_node_insert_copy_before_attribute, "") +TEST_XML(dom_node_insert_copy_before_attribute, "text") { CHECK(xml_node().insert_copy_before(xml_attribute(), xml_attribute()) == xml_attribute()); @@ -441,6 +442,7 @@ TEST_XML(dom_node_insert_copy_before_attribute, "< CHECK(node.insert_copy_before(a1, xml_attribute()) == xml_attribute()); CHECK(node.insert_copy_before(xml_attribute(), a1) == xml_attribute()); CHECK(node.insert_copy_before(a2, a2) == xml_attribute()); + CHECK(node.last_child().insert_copy_before(a2, a2) == xml_attribute()); xml_attribute a3 = node.insert_copy_before(a1, a1); CHECK(a3 && a3 != a2 && a3 != a1); @@ -453,7 +455,7 @@ TEST_XML(dom_node_insert_copy_before_attribute, "< CHECK(child.insert_copy_before(a4, a4) == xml_attribute()); - CHECK_NODE(doc, STR("")); + CHECK_NODE(doc, STR("text")); a3.set_name(STR("a3")); a3 = STR("v3"); @@ -464,7 +466,7 @@ TEST_XML(dom_node_insert_copy_before_attribute, "< a5.set_name(STR("a5")); a5 = STR("v5"); - CHECK_NODE(doc, STR("")); + CHECK_NODE(doc, STR("text")); } TEST_XML(dom_node_remove_attribute, "") @@ -550,6 +552,7 @@ TEST_XML(dom_node_insert_child_after, "foo") xml_node node = doc.child(STR("node")); xml_node child = node.child(STR("child")); + CHECK(node.insert_child_after(node_element, xml_node()) == xml_node()); CHECK(node.insert_child_after(node_element, node) == xml_node()); CHECK(child.insert_child_after(node_element, node) == xml_node()); @@ -584,6 +587,7 @@ TEST_XML(dom_node_insert_child_before, "foo") xml_node node = doc.child(STR("node")); xml_node child = node.child(STR("child")); + CHECK(node.insert_child_before(node_element, xml_node()) == xml_node()); CHECK(node.insert_child_before(node_element, node) == xml_node()); CHECK(child.insert_child_before(node_element, node) == xml_node()); @@ -770,13 +774,16 @@ TEST_XML(dom_node_append_copy, "foo") TEST_XML(dom_node_insert_copy_after, "foo") { + xml_node child = doc.child(STR("node")).child(STR("child")); + CHECK(xml_node().insert_copy_after(xml_node(), xml_node()) == xml_node()); CHECK(doc.child(STR("node")).first_child().insert_copy_after(doc.child(STR("node")), doc.child(STR("node"))) == xml_node()); CHECK(doc.insert_copy_after(doc, doc) == xml_node()); CHECK(doc.insert_copy_after(xml_node(), doc.child(STR("node"))) == xml_node()); CHECK(doc.insert_copy_after(doc.child(STR("node")), xml_node()) == xml_node()); + CHECK(doc.insert_copy_after(doc.child(STR("node")), child) == xml_node()); - xml_node n1 = doc.child(STR("node")).insert_copy_after(doc.child(STR("node")).child(STR("child")), doc.child(STR("node")).first_child()); + xml_node n1 = doc.child(STR("node")).insert_copy_after(child, doc.child(STR("node")).first_child()); CHECK(n1); CHECK_STRING(n1.name(), STR("child")); CHECK_NODE(doc, STR("foo")); @@ -794,13 +801,16 @@ TEST_XML(dom_node_insert_copy_after, "foo") TEST_XML(dom_node_insert_copy_before, "foo") { + xml_node child = doc.child(STR("node")).child(STR("child")); + CHECK(xml_node().insert_copy_before(xml_node(), xml_node()) == xml_node()); CHECK(doc.child(STR("node")).first_child().insert_copy_before(doc.child(STR("node")), doc.child(STR("node"))) == xml_node()); CHECK(doc.insert_copy_before(doc, doc) == xml_node()); CHECK(doc.insert_copy_before(xml_node(), doc.child(STR("node"))) == xml_node()); CHECK(doc.insert_copy_before(doc.child(STR("node")), xml_node()) == xml_node()); + CHECK(doc.insert_copy_before(doc.child(STR("node")), child) == xml_node()); - xml_node n1 = doc.child(STR("node")).insert_copy_before(doc.child(STR("node")).child(STR("child")), doc.child(STR("node")).first_child()); + xml_node n1 = doc.child(STR("node")).insert_copy_before(child, doc.child(STR("node")).first_child()); CHECK(n1); CHECK_STRING(n1.name(), STR("child")); CHECK_NODE(doc, STR("foo")); @@ -1314,6 +1324,7 @@ TEST_XML(dom_node_insert_move_after, "foobar") CHECK(doc.insert_move_after(doc, doc) == xml_node()); CHECK(doc.insert_move_after(xml_node(), doc.child(STR("node"))) == xml_node()); CHECK(doc.insert_move_after(doc.child(STR("node")), xml_node()) == xml_node()); + CHECK(doc.insert_move_after(doc.child(STR("node")), child) == xml_node()); xml_node n1 = doc.child(STR("node")).insert_move_after(child, doc.child(STR("node")).first_child()); CHECK(n1 && n1 == child); @@ -1340,6 +1351,7 @@ TEST_XML(dom_node_insert_move_before, "foobar") CHECK(doc.insert_move_before(doc, doc) == xml_node()); CHECK(doc.insert_move_before(xml_node(), doc.child(STR("node"))) == xml_node()); CHECK(doc.insert_move_before(doc.child(STR("node")), xml_node()) == xml_node()); + CHECK(doc.insert_move_before(doc.child(STR("node")), child) == xml_node()); xml_node n1 = doc.child(STR("node")).insert_move_before(child, doc.child(STR("node")).first_child()); CHECK(n1 && n1 == child); diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index f977e15..773f0f0 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -736,6 +736,9 @@ TEST_XML(dom_node_path, "text") CHECK(doc.child(STR("node")).child(STR("child1")).first_child().path() == STR("/node/child1/")); CHECK(doc.child(STR("node")).child(STR("child1")).path('\\') == STR("\\node\\child1")); + + doc.append_child(node_element); + CHECK(doc.last_child().path() == STR("/")); } #endif @@ -1274,3 +1277,17 @@ TEST_XML(dom_as_int_plus, "") CHECK(node.attribute(STR("attr2")).as_ullong() == 10); #endif } + +TEST(dom_node_anonymous) +{ + xml_document doc; + doc.append_child(node_element); + doc.append_child(node_element); + doc.append_child(node_pcdata); + + CHECK(doc.child(STR("node")) == xml_node()); + CHECK(doc.first_child().next_sibling(STR("node")) == xml_node()); + CHECK(doc.last_child().previous_sibling(STR("node")) == xml_node()); + CHECK_STRING(doc.child_value(), STR("")); + CHECK_STRING(doc.last_child().child_value(), STR("")); +} -- cgit v1.2.3