From bbd75fda4618dcbef272c8e5432153992c392588 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 23 Oct 2014 05:46:44 +0000 Subject: tests: Improve test coverage git-svn-id: https://pugixml.googlecode.com/svn/trunk@1074 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_dom_modify.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/test_dom_modify.cpp') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 612b017..5f4e26c 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1354,3 +1354,38 @@ TEST_XML(dom_node_copy_out_of_memory, "text") +{ + xml_node node = doc.child(STR("node")); + + xml_attribute attr = node.attribute(STR("attr")); + attr.set_name(STR("longattr")); + attr.set_value(STR("longvalue")); + + node.set_name(STR("longnode")); + node.text().set(STR("longtext")); + + node.remove_attribute(attr); + doc.remove_child(node); + + CHECK_NODE(doc, STR("")); +} + +TEST_XML(dom_node_set_deallocate, "text") +{ + xml_node node = doc.child(STR("node")); + + xml_attribute attr = node.attribute(STR("attr")); + + attr.set_name(STR("longattr")); + attr.set_value(STR("longvalue")); + node.set_name(STR("longnode")); + + attr.set_name(STR("")); + attr.set_value(STR("")); + node.set_name(STR("")); + node.text().set(STR("")); + + CHECK_NODE(doc, STR("<:anonymous :anonymous=\"\">")); +} -- cgit v1.2.3 From 903db8682a5f14b52adec996584c70ea072619ea Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 23 Oct 2014 07:41:07 +0000 Subject: tests: Add more tests for better coverage More tests for out-of-memory and other edge conditions git-svn-id: https://pugixml.googlecode.com/svn/trunk@1075 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_dom_modify.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tests/test_dom_modify.cpp') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 5f4e26c..01b562a 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -27,6 +27,16 @@ TEST_XML(dom_attr_assign, "") CHECK_NODE(node, STR("")); } +TEST_XML(dom_attr_set_name, "") +{ + xml_attribute attr = doc.child(STR("node")).attribute(STR("attr")); + + CHECK(attr.set_name(STR("n"))); + CHECK(!xml_attribute().set_name(STR("n"))); + + CHECK_NODE(doc, STR("")); +} + TEST_XML(dom_attr_set_value, "") { xml_node node = doc.child(STR("node")); @@ -758,8 +768,9 @@ TEST(dom_node_declaration_name) doc.insert_child_after(node_declaration, doc.first_child()); doc.insert_child_before(node_declaration, doc.first_child()); + doc.prepend_child(node_declaration); - CHECK_NODE(doc, STR("")); + CHECK_NODE(doc, STR("")); } TEST(dom_node_declaration_attributes) @@ -867,17 +878,21 @@ TEST(dom_node_out_of_memory) // verify all node modification operations CHECK(!n.append_child()); + CHECK(!n.prepend_child()); CHECK(!n.insert_child_after(node_element, n.first_child())); CHECK(!n.insert_child_before(node_element, n.first_child())); CHECK(!n.append_attribute(STR(""))); + CHECK(!n.prepend_attribute(STR(""))); CHECK(!n.insert_attribute_after(STR(""), a)); CHECK(!n.insert_attribute_before(STR(""), a)); // verify node copy operations CHECK(!n.append_copy(n.first_child())); + CHECK(!n.prepend_copy(n.first_child())); CHECK(!n.insert_copy_after(n.first_child(), n.first_child())); CHECK(!n.insert_copy_before(n.first_child(), n.first_child())); CHECK(!n.append_copy(a)); + CHECK(!n.prepend_copy(a)); CHECK(!n.insert_copy_after(a, a)); CHECK(!n.insert_copy_before(a, a)); } -- cgit v1.2.3 From 0b7964917cbfd9d007c8a017eaced636f53ddeb3 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 25 Oct 2014 16:37:16 +0000 Subject: Fix node copying for some out of memory cases A page can fail to allocate during attribute creation; this case was not previously handled. git-svn-id: https://pugixml.googlecode.com/svn/trunk@1080 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_dom_modify.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'tests/test_dom_modify.cpp') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 01b562a..07fe6dc 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1361,13 +1361,22 @@ TEST_XML(dom_node_copyless_taint, "") CHECK_NODE(doc, STR("")); } -TEST_XML(dom_node_copy_out_of_memory, "text1text2") +TEST_XML(dom_node_copy_out_of_memory_node, "text1text2") { test_runner::_memory_fail_threshold = 32768 * 2 + 4096; - xml_document copy; - for (int i = 0; i < 100; ++i) - copy.append_copy(doc.first_child()); + xml_document copy; + for (int i = 0; i < 1000; ++i) + copy.append_copy(doc.first_child()); +} + +TEST_XML(dom_node_copy_out_of_memory_attr, "") +{ + test_runner::_memory_fail_threshold = 32768 * 2 + 4096; + + xml_document copy; + for (int i = 0; i < 1000; ++i) + copy.append_copy(doc.first_child()); } TEST_XML(dom_node_remove_deallocate, "text") -- cgit v1.2.3