From 7d24b9b5655d584b6dc8b89df7cbd58d2e940a81 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Mon, 19 Jul 2010 09:57:32 +0000 Subject: Set svn:eol-style to native for all text files git-svn-id: http://pugixml.googlecode.com/svn/trunk@607 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_dom_modify.cpp | 1318 ++++++++++++++++++++++----------------------- 1 file changed, 659 insertions(+), 659 deletions(-) (limited to 'tests/test_dom_modify.cpp') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 1e38d95..38cc89e 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1,659 +1,659 @@ -#include "common.hpp" - -#include - -TEST_XML(dom_attr_assign, "") -{ - xml_node node = doc.child(STR("node")); - - node.append_attribute(STR("attr1")) = STR("v1"); - xml_attribute() = STR("v1"); - - node.append_attribute(STR("attr2")) = -2147483647; - node.append_attribute(STR("attr3")) = -2147483647 - 1; - xml_attribute() = -2147483647 - 1; - - node.append_attribute(STR("attr4")) = 4294967295u; - node.append_attribute(STR("attr5")) = 4294967294u; - xml_attribute() = 2147483647; - - node.append_attribute(STR("attr6")) = 0.5; - xml_attribute() = 0.5; - - node.append_attribute(STR("attr7")) = true; - xml_attribute() = true; - - CHECK_NODE(node, STR("")); -} - -TEST_XML(dom_attr_set_value, "") -{ - xml_node node = doc.child(STR("node")); - - CHECK(node.append_attribute(STR("attr1")).set_value(STR("v1"))); - CHECK(!xml_attribute().set_value(STR("v1"))); - - CHECK(node.append_attribute(STR("attr2")).set_value(-2147483647)); - CHECK(node.append_attribute(STR("attr3")).set_value(-2147483647 - 1)); - CHECK(!xml_attribute().set_value(-2147483647)); - - CHECK(node.append_attribute(STR("attr4")).set_value(4294967295u)); - CHECK(node.append_attribute(STR("attr5")).set_value(4294967294u)); - CHECK(!xml_attribute().set_value(4294967295u)); - - CHECK(node.append_attribute(STR("attr6")).set_value(0.5)); - CHECK(!xml_attribute().set_value(0.5)); - - CHECK(node.append_attribute(STR("attr7")).set_value(true)); - CHECK(!xml_attribute().set_value(true)); - - CHECK_NODE(node, STR("")); -} - -TEST_XML(dom_node_set_name, "text") -{ - CHECK(doc.child(STR("node")).set_name(STR("n"))); - CHECK(!doc.child(STR("node")).first_child().set_name(STR("n"))); - CHECK(!xml_node().set_name(STR("n"))); - - CHECK_NODE(doc, STR("text")); -} - -TEST_XML(dom_node_set_value, "text") -{ - CHECK(doc.child(STR("node")).first_child().set_value(STR("no text"))); - CHECK(!doc.child(STR("node")).set_value(STR("no text"))); - CHECK(!xml_node().set_value(STR("no text"))); - - CHECK_NODE(doc, STR("no text")); -} - -TEST_XML(dom_node_set_value_allocated, "text") -{ - CHECK(doc.child(STR("node")).first_child().set_value(STR("no text"))); - CHECK(!doc.child(STR("node")).set_value(STR("no text"))); - CHECK(!xml_node().set_value(STR("no text"))); - CHECK(doc.child(STR("node")).first_child().set_value(STR("no text at all"))); - - CHECK_NODE(doc, STR("no text at all")); -} - -TEST_XML(dom_node_append_attribute, "") -{ - CHECK(xml_node().append_attribute(STR("a")) == xml_attribute()); - CHECK(doc.append_attribute(STR("a")) == xml_attribute()); - - xml_attribute a1 = doc.child(STR("node")).append_attribute(STR("a1")); - CHECK(a1); - a1 = STR("v1"); - - xml_attribute a2 = doc.child(STR("node")).append_attribute(STR("a2")); - CHECK(a2 && a1 != a2); - a2 = STR("v2"); - - xml_attribute a3 = doc.child(STR("node")).child(STR("child")).append_attribute(STR("a3")); - CHECK(a3 && a1 != a3 && a2 != a3); - a3 = STR("v3"); - - CHECK_NODE(doc, STR("")); -} - -TEST_XML(dom_node_insert_attribute_after, "") -{ - CHECK(xml_node().insert_attribute_after(STR("a"), 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")); - - CHECK(node.insert_attribute_after(STR("a"), xml_attribute()) == xml_attribute()); - CHECK(node.insert_attribute_after(STR("a"), a2) == xml_attribute()); - - xml_attribute a3 = node.insert_attribute_after(STR("a3"), a1); - CHECK(a3 && a3 != a2 && a3 != a1); - a3 = STR("v3"); - - xml_attribute a4 = node.insert_attribute_after(STR("a4"), a1); - CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1); - a4 = STR("v4"); - - xml_attribute a5 = node.insert_attribute_after(STR("a5"), a3); - CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1); - a5 = STR("v5"); - - CHECK(child.insert_attribute_after(STR("a"), a4) == xml_attribute()); - - CHECK_NODE(doc, STR("")); -} - -TEST_XML(dom_node_insert_attribute_before, "") -{ - CHECK(xml_node().insert_attribute_before(STR("a"), 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")); - - CHECK(node.insert_attribute_before(STR("a"), xml_attribute()) == xml_attribute()); - CHECK(node.insert_attribute_before(STR("a"), a2) == xml_attribute()); - - xml_attribute a3 = node.insert_attribute_before(STR("a3"), a1); - CHECK(a3 && a3 != a2 && a3 != a1); - a3 = STR("v3"); - - xml_attribute a4 = node.insert_attribute_before(STR("a4"), a1); - CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1); - a4 = STR("v4"); - - xml_attribute a5 = node.insert_attribute_before(STR("a5"), a3); - CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1); - a5 = STR("v5"); - - CHECK(child.insert_attribute_before(STR("a"), a4) == xml_attribute()); - - CHECK_NODE(doc, STR("")); -} - -TEST_XML(dom_node_append_copy_attribute, "") -{ - CHECK(xml_node().append_copy(xml_attribute()) == xml_attribute()); - CHECK(xml_node().append_copy(doc.child(STR("node")).attribute(STR("a1"))) == xml_attribute()); - CHECK(doc.append_copy(doc.child(STR("node")).attribute(STR("a1"))) == 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.append_copy(a1); - CHECK(a3 && a3 != a2 && a3 != a1); - - xml_attribute a4 = node.append_copy(a2); - CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1); - - xml_attribute a5 = node.last_child().append_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_insert_copy_after_attribute, "") -{ - CHECK(xml_node().insert_copy_after(xml_attribute(), 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")); - - CHECK(node.insert_copy_after(a1, xml_attribute()) == xml_attribute()); - CHECK(node.insert_copy_after(xml_attribute(), a1) == xml_attribute()); - CHECK(node.insert_copy_after(a2, a2) == xml_attribute()); - - xml_attribute a3 = node.insert_copy_after(a1, a1); - CHECK(a3 && a3 != a2 && a3 != a1); - - xml_attribute a4 = node.insert_copy_after(a2, a1); - CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1); - - xml_attribute a5 = node.insert_copy_after(a4, a1); - CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1); - - CHECK(child.insert_copy_after(a4, a4) == xml_attribute()); - - 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_insert_copy_before_attribute, "") -{ - CHECK(xml_node().insert_copy_before(xml_attribute(), 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")); - - 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()); - - xml_attribute a3 = node.insert_copy_before(a1, a1); - CHECK(a3 && a3 != a2 && a3 != a1); - - xml_attribute a4 = node.insert_copy_before(a2, a1); - CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1); - - xml_attribute a5 = node.insert_copy_before(a4, a1); - CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1); - - CHECK(child.insert_copy_before(a4, a4) == xml_attribute()); - - 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_remove_attribute, "") -{ - CHECK(!xml_node().remove_attribute(STR("a"))); - CHECK(!xml_node().remove_attribute(xml_attribute())); - - xml_node node = doc.child(STR("node")); - xml_node child = node.child(STR("child")); - - CHECK(!node.remove_attribute(STR("a"))); - CHECK(!node.remove_attribute(xml_attribute())); - CHECK(!node.remove_attribute(child.attribute(STR("a4")))); - - CHECK_NODE(doc, STR("")); - - CHECK(node.remove_attribute(STR("a1"))); - CHECK(node.remove_attribute(node.attribute(STR("a3")))); - CHECK(child.remove_attribute(STR("a4"))); - - CHECK_NODE(doc, STR("")); -} - -TEST_XML(dom_node_append_child, "foo") -{ - CHECK(xml_node().append_child() == xml_node()); - CHECK(doc.child(STR("node")).first_child().append_child() == xml_node()); - CHECK(doc.append_child(node_document) == xml_node()); - CHECK(doc.append_child(node_null) == xml_node()); - - xml_node n1 = doc.child(STR("node")).append_child(); - CHECK(n1); - CHECK(n1.set_name(STR("n1"))); - - xml_node n2 = doc.child(STR("node")).append_child(); - CHECK(n2 && n1 != n2); - CHECK(n2.set_name(STR("n2"))); - - xml_node n3 = doc.child(STR("node")).child(STR("child")).append_child(node_pcdata); - CHECK(n3 && n1 != n3 && n2 != n3); - CHECK(n3.set_value(STR("n3"))); - - xml_node n4 = doc.append_child(node_comment); - CHECK(n4 && n1 != n4 && n2 != n4 && n3 != n4); - CHECK(n4.set_value(STR("n4"))); - - CHECK_NODE(doc, STR("foon3")); -} - -TEST_XML(dom_node_insert_child_after, "foo") -{ - CHECK(xml_node().insert_child_after(node_element, xml_node()) == xml_node()); - CHECK(doc.child(STR("node")).first_child().insert_child_after(node_element, xml_node()) == xml_node()); - CHECK(doc.insert_child_after(node_document, xml_node()) == xml_node()); - CHECK(doc.insert_child_after(node_null, xml_node()) == xml_node()); - - xml_node node = doc.child(STR("node")); - xml_node child = node.child(STR("child")); - - CHECK(node.insert_child_after(node_element, node) == xml_node()); - CHECK(child.insert_child_after(node_element, node) == xml_node()); - - xml_node n1 = node.insert_child_after(node_element, child); - CHECK(n1 && n1 != node && n1 != child); - CHECK(n1.set_name(STR("n1"))); - - xml_node n2 = node.insert_child_after(node_element, child); - CHECK(n2 && n2 != node && n2 != child && n2 != n1); - CHECK(n2.set_name(STR("n2"))); - - xml_node n3 = node.insert_child_after(node_pcdata, n2); - CHECK(n3 && n3 != node && n3 != child && n3 != n1 && n3 != n2); - CHECK(n3.set_value(STR("n3"))); - - xml_node n4 = node.insert_child_after(node_pi, node.first_child()); - CHECK(n4 && n4 != node && n4 != child && n4 != n1 && n4 != n2 && n4 != n3); - CHECK(n4.set_name(STR("n4"))); - - CHECK(child.insert_child_after(node_element, n3) == xml_node()); - - CHECK_NODE(doc, STR("foon3")); -} - -TEST_XML(dom_node_insert_child_before, "foo") -{ - CHECK(xml_node().insert_child_before(node_element, xml_node()) == xml_node()); - CHECK(doc.child(STR("node")).first_child().insert_child_before(node_element, xml_node()) == xml_node()); - CHECK(doc.insert_child_before(node_document, xml_node()) == xml_node()); - CHECK(doc.insert_child_before(node_null, xml_node()) == xml_node()); - - xml_node node = doc.child(STR("node")); - xml_node child = node.child(STR("child")); - - CHECK(node.insert_child_before(node_element, node) == xml_node()); - CHECK(child.insert_child_before(node_element, node) == xml_node()); - - xml_node n1 = node.insert_child_before(node_element, child); - CHECK(n1 && n1 != node && n1 != child); - CHECK(n1.set_name(STR("n1"))); - - xml_node n2 = node.insert_child_before(node_element, child); - CHECK(n2 && n2 != node && n2 != child && n2 != n1); - CHECK(n2.set_name(STR("n2"))); - - xml_node n3 = node.insert_child_before(node_pcdata, n2); - CHECK(n3 && n3 != node && n3 != child && n3 != n1 && n3 != n2); - CHECK(n3.set_value(STR("n3"))); - - xml_node n4 = node.insert_child_before(node_pi, node.first_child()); - CHECK(n4 && n4 != node && n4 != child && n4 != n1 && n4 != n2 && n4 != n3); - CHECK(n4.set_name(STR("n4"))); - - CHECK(child.insert_child_before(node_element, n3) == xml_node()); - - CHECK_NODE(doc, STR("foon3")); -} - -TEST_XML(dom_node_remove_child, "") -{ - CHECK(!xml_node().remove_child(STR("a"))); - CHECK(!xml_node().remove_child(xml_node())); - - xml_node node = doc.child(STR("node")); - xml_node child = node.child(STR("child")); - - CHECK(!node.remove_child(STR("a"))); - CHECK(!node.remove_child(xml_node())); - CHECK(!node.remove_child(child.child(STR("n4")))); - - CHECK_NODE(doc, STR("")); - - CHECK(node.remove_child(STR("n1"))); - CHECK(node.remove_child(node.child(STR("n3")))); - CHECK(child.remove_child(STR("n4"))); - - CHECK_NODE(doc, STR("")); -} - -TEST_XML(dom_node_remove_child_complex, "") -{ - doc.child(STR("node")).remove_child(STR("n1")); - - CHECK_NODE(doc, STR("")); - - CHECK(doc.remove_child(STR("node"))); - - CHECK_NODE(doc, STR("")); -} - -TEST_XML(dom_node_remove_child_complex_allocated, "") -{ - doc.append_copy(doc.child(STR("node"))); - - CHECK(doc.remove_child(STR("node"))); - CHECK(doc.remove_child(STR("node"))); - - CHECK_NODE(doc, STR("")); -} - -TEST_XML(dom_node_append_copy, "foo") -{ - CHECK(xml_node().append_copy(xml_node()) == xml_node()); - CHECK(doc.child(STR("node")).first_child().append_copy(doc.child(STR("node"))) == xml_node()); - CHECK(doc.append_copy(doc) == xml_node()); - CHECK(doc.append_copy(xml_node()) == xml_node()); - - xml_node n1 = doc.child(STR("node")).append_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")).append_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")).append_copy(doc.child(STR("node")).first_child()); - CHECK(n3 && n3 != n1 && n3 != n2); - CHECK_STRING(n3.value(), STR("foo")); - CHECK_NODE(doc, STR("foofoofoo")); -} - -TEST_XML(dom_node_insert_copy_after, "foo") -{ - 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()); - - xml_node n1 = doc.child(STR("node")).insert_copy_after(doc.child(STR("node")).child(STR("child")), doc.child(STR("node")).first_child()); - CHECK(n1); - CHECK_STRING(n1.name(), STR("child")); - CHECK_NODE(doc, STR("foo")); - - xml_node n2 = doc.child(STR("node")).insert_copy_after(doc.child(STR("node")).first_child(), doc.child(STR("node")).last_child()); - CHECK(n2 && n2 != n1); - CHECK_STRING(n2.value(), STR("foo")); - CHECK_NODE(doc, STR("foofoo")); - - xml_node n3 = doc.child(STR("node")).insert_copy_after(doc.child(STR("node")).first_child(), doc.child(STR("node")).first_child()); - CHECK(n3 && n3 != n1 && n3 != n2); - CHECK_STRING(n3.value(), STR("foo")); - CHECK_NODE(doc, STR("foofoofoo")); -} - -TEST_XML(dom_node_insert_copy_before, "foo") -{ - 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()); - - xml_node n1 = doc.child(STR("node")).insert_copy_before(doc.child(STR("node")).child(STR("child")), doc.child(STR("node")).first_child()); - CHECK(n1); - CHECK_STRING(n1.name(), STR("child")); - CHECK_NODE(doc, STR("foo")); - - xml_node n2 = doc.child(STR("node")).insert_copy_before(doc.child(STR("node")).first_child(), doc.child(STR("node")).last_child()); - CHECK(n2 && n2 != n1); - CHECK_STRING(n2.name(), STR("child")); - CHECK_NODE(doc, STR("foo")); - - xml_node n3 = doc.child(STR("node")).insert_copy_before(doc.child(STR("node")).first_child().next_sibling(), doc.child(STR("node")).first_child()); - CHECK(n3 && n3 != n1 && n3 != n2); - CHECK_STRING(n3.value(), STR("foo")); - CHECK_NODE(doc, STR("foofoo")); -} - -TEST_XML(dom_node_copy_recursive, "foo") -{ - doc.child(STR("node")).append_copy(doc.child(STR("node"))); - CHECK_NODE(doc, STR("foofoo")); -} - -TEST_XML(dom_node_copy_crossdoc, "") -{ - xml_document newdoc; - newdoc.append_copy(doc.child(STR("node"))); - CHECK_NODE(doc, STR("")); - CHECK_NODE(newdoc, STR("")); -} - -TEST_XML_FLAGS(dom_node_copy_types, "pcdata", parse_default | parse_pi | parse_comments | parse_declaration) -{ - doc.append_copy(doc.child(STR("root"))); - CHECK_NODE(doc, STR("pcdatapcdata")); - - doc.insert_copy_before(doc.first_child(), doc.first_child()); - CHECK_NODE(doc, STR("pcdatapcdata")); -} - -TEST_XML(dom_attr_assign_large_number, "") -{ - xml_node node = doc.child(STR("node")); - - node.attribute(STR("attr1")) = FLT_MAX; - node.attribute(STR("attr2")) = DBL_MAX; - - 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("")); -} - -TEST(dom_string_out_of_memory) -{ - unsigned int length = 65536; - - char_t* string = new char_t[length + 1]; - for (unsigned int i = 0; i < length; ++i) string[i] = 'a'; - string[length] = 0; - - xml_document doc; - xml_node node = doc.append_child(); - xml_attribute attr = node.append_attribute(STR("a")); - xml_node text = node.append_child(node_pcdata); - - // no value => long value - test_runner::_memory_fail_threshold = 32; - - CHECK(!node.set_name(string)); - CHECK(!text.set_value(string)); - CHECK(!attr.set_name(string)); - CHECK(!attr.set_value(string)); - - // set some names/values - test_runner::_memory_fail_threshold = 0; - - node.set_name(STR("n")); - attr.set_value(STR("v")); - text.set_value(STR("t")); - - // some value => long value - test_runner::_memory_fail_threshold = 32; - - CHECK(!node.set_name(string)); - CHECK(!text.set_value(string)); - CHECK(!attr.set_name(string)); - CHECK(!attr.set_value(string)); - - // check that original state was preserved - test_runner::_memory_fail_threshold = 0; - - CHECK_NODE(doc, STR("t")); -} - -TEST(dom_node_out_of_memory) -{ - test_runner::_memory_fail_threshold = 65536; - - // exhaust memory limit - xml_document doc; - - xml_node n = doc.append_child(); - CHECK(n.set_name(STR("n"))); - - xml_attribute a = n.append_attribute(STR("a")); - CHECK(a); - - while (n.append_child(node_comment) || n.append_attribute(STR("b"))) - { - // nop - } - - // verify all node modification operations - CHECK(!n.append_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.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.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.insert_copy_after(a, a)); - CHECK(!n.insert_copy_before(a, a)); -} +#include "common.hpp" + +#include + +TEST_XML(dom_attr_assign, "") +{ + xml_node node = doc.child(STR("node")); + + node.append_attribute(STR("attr1")) = STR("v1"); + xml_attribute() = STR("v1"); + + node.append_attribute(STR("attr2")) = -2147483647; + node.append_attribute(STR("attr3")) = -2147483647 - 1; + xml_attribute() = -2147483647 - 1; + + node.append_attribute(STR("attr4")) = 4294967295u; + node.append_attribute(STR("attr5")) = 4294967294u; + xml_attribute() = 2147483647; + + node.append_attribute(STR("attr6")) = 0.5; + xml_attribute() = 0.5; + + node.append_attribute(STR("attr7")) = true; + xml_attribute() = true; + + CHECK_NODE(node, STR("")); +} + +TEST_XML(dom_attr_set_value, "") +{ + xml_node node = doc.child(STR("node")); + + CHECK(node.append_attribute(STR("attr1")).set_value(STR("v1"))); + CHECK(!xml_attribute().set_value(STR("v1"))); + + CHECK(node.append_attribute(STR("attr2")).set_value(-2147483647)); + CHECK(node.append_attribute(STR("attr3")).set_value(-2147483647 - 1)); + CHECK(!xml_attribute().set_value(-2147483647)); + + CHECK(node.append_attribute(STR("attr4")).set_value(4294967295u)); + CHECK(node.append_attribute(STR("attr5")).set_value(4294967294u)); + CHECK(!xml_attribute().set_value(4294967295u)); + + CHECK(node.append_attribute(STR("attr6")).set_value(0.5)); + CHECK(!xml_attribute().set_value(0.5)); + + CHECK(node.append_attribute(STR("attr7")).set_value(true)); + CHECK(!xml_attribute().set_value(true)); + + CHECK_NODE(node, STR("")); +} + +TEST_XML(dom_node_set_name, "text") +{ + CHECK(doc.child(STR("node")).set_name(STR("n"))); + CHECK(!doc.child(STR("node")).first_child().set_name(STR("n"))); + CHECK(!xml_node().set_name(STR("n"))); + + CHECK_NODE(doc, STR("text")); +} + +TEST_XML(dom_node_set_value, "text") +{ + CHECK(doc.child(STR("node")).first_child().set_value(STR("no text"))); + CHECK(!doc.child(STR("node")).set_value(STR("no text"))); + CHECK(!xml_node().set_value(STR("no text"))); + + CHECK_NODE(doc, STR("no text")); +} + +TEST_XML(dom_node_set_value_allocated, "text") +{ + CHECK(doc.child(STR("node")).first_child().set_value(STR("no text"))); + CHECK(!doc.child(STR("node")).set_value(STR("no text"))); + CHECK(!xml_node().set_value(STR("no text"))); + CHECK(doc.child(STR("node")).first_child().set_value(STR("no text at all"))); + + CHECK_NODE(doc, STR("no text at all")); +} + +TEST_XML(dom_node_append_attribute, "") +{ + CHECK(xml_node().append_attribute(STR("a")) == xml_attribute()); + CHECK(doc.append_attribute(STR("a")) == xml_attribute()); + + xml_attribute a1 = doc.child(STR("node")).append_attribute(STR("a1")); + CHECK(a1); + a1 = STR("v1"); + + xml_attribute a2 = doc.child(STR("node")).append_attribute(STR("a2")); + CHECK(a2 && a1 != a2); + a2 = STR("v2"); + + xml_attribute a3 = doc.child(STR("node")).child(STR("child")).append_attribute(STR("a3")); + CHECK(a3 && a1 != a3 && a2 != a3); + a3 = STR("v3"); + + CHECK_NODE(doc, STR("")); +} + +TEST_XML(dom_node_insert_attribute_after, "") +{ + CHECK(xml_node().insert_attribute_after(STR("a"), 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")); + + CHECK(node.insert_attribute_after(STR("a"), xml_attribute()) == xml_attribute()); + CHECK(node.insert_attribute_after(STR("a"), a2) == xml_attribute()); + + xml_attribute a3 = node.insert_attribute_after(STR("a3"), a1); + CHECK(a3 && a3 != a2 && a3 != a1); + a3 = STR("v3"); + + xml_attribute a4 = node.insert_attribute_after(STR("a4"), a1); + CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1); + a4 = STR("v4"); + + xml_attribute a5 = node.insert_attribute_after(STR("a5"), a3); + CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1); + a5 = STR("v5"); + + CHECK(child.insert_attribute_after(STR("a"), a4) == xml_attribute()); + + CHECK_NODE(doc, STR("")); +} + +TEST_XML(dom_node_insert_attribute_before, "") +{ + CHECK(xml_node().insert_attribute_before(STR("a"), 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")); + + CHECK(node.insert_attribute_before(STR("a"), xml_attribute()) == xml_attribute()); + CHECK(node.insert_attribute_before(STR("a"), a2) == xml_attribute()); + + xml_attribute a3 = node.insert_attribute_before(STR("a3"), a1); + CHECK(a3 && a3 != a2 && a3 != a1); + a3 = STR("v3"); + + xml_attribute a4 = node.insert_attribute_before(STR("a4"), a1); + CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1); + a4 = STR("v4"); + + xml_attribute a5 = node.insert_attribute_before(STR("a5"), a3); + CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1); + a5 = STR("v5"); + + CHECK(child.insert_attribute_before(STR("a"), a4) == xml_attribute()); + + CHECK_NODE(doc, STR("")); +} + +TEST_XML(dom_node_append_copy_attribute, "") +{ + CHECK(xml_node().append_copy(xml_attribute()) == xml_attribute()); + CHECK(xml_node().append_copy(doc.child(STR("node")).attribute(STR("a1"))) == xml_attribute()); + CHECK(doc.append_copy(doc.child(STR("node")).attribute(STR("a1"))) == 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.append_copy(a1); + CHECK(a3 && a3 != a2 && a3 != a1); + + xml_attribute a4 = node.append_copy(a2); + CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1); + + xml_attribute a5 = node.last_child().append_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_insert_copy_after_attribute, "") +{ + CHECK(xml_node().insert_copy_after(xml_attribute(), 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")); + + CHECK(node.insert_copy_after(a1, xml_attribute()) == xml_attribute()); + CHECK(node.insert_copy_after(xml_attribute(), a1) == xml_attribute()); + CHECK(node.insert_copy_after(a2, a2) == xml_attribute()); + + xml_attribute a3 = node.insert_copy_after(a1, a1); + CHECK(a3 && a3 != a2 && a3 != a1); + + xml_attribute a4 = node.insert_copy_after(a2, a1); + CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1); + + xml_attribute a5 = node.insert_copy_after(a4, a1); + CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1); + + CHECK(child.insert_copy_after(a4, a4) == xml_attribute()); + + 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_insert_copy_before_attribute, "") +{ + CHECK(xml_node().insert_copy_before(xml_attribute(), 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")); + + 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()); + + xml_attribute a3 = node.insert_copy_before(a1, a1); + CHECK(a3 && a3 != a2 && a3 != a1); + + xml_attribute a4 = node.insert_copy_before(a2, a1); + CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1); + + xml_attribute a5 = node.insert_copy_before(a4, a1); + CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1); + + CHECK(child.insert_copy_before(a4, a4) == xml_attribute()); + + 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_remove_attribute, "") +{ + CHECK(!xml_node().remove_attribute(STR("a"))); + CHECK(!xml_node().remove_attribute(xml_attribute())); + + xml_node node = doc.child(STR("node")); + xml_node child = node.child(STR("child")); + + CHECK(!node.remove_attribute(STR("a"))); + CHECK(!node.remove_attribute(xml_attribute())); + CHECK(!node.remove_attribute(child.attribute(STR("a4")))); + + CHECK_NODE(doc, STR("")); + + CHECK(node.remove_attribute(STR("a1"))); + CHECK(node.remove_attribute(node.attribute(STR("a3")))); + CHECK(child.remove_attribute(STR("a4"))); + + CHECK_NODE(doc, STR("")); +} + +TEST_XML(dom_node_append_child, "foo") +{ + CHECK(xml_node().append_child() == xml_node()); + CHECK(doc.child(STR("node")).first_child().append_child() == xml_node()); + CHECK(doc.append_child(node_document) == xml_node()); + CHECK(doc.append_child(node_null) == xml_node()); + + xml_node n1 = doc.child(STR("node")).append_child(); + CHECK(n1); + CHECK(n1.set_name(STR("n1"))); + + xml_node n2 = doc.child(STR("node")).append_child(); + CHECK(n2 && n1 != n2); + CHECK(n2.set_name(STR("n2"))); + + xml_node n3 = doc.child(STR("node")).child(STR("child")).append_child(node_pcdata); + CHECK(n3 && n1 != n3 && n2 != n3); + CHECK(n3.set_value(STR("n3"))); + + xml_node n4 = doc.append_child(node_comment); + CHECK(n4 && n1 != n4 && n2 != n4 && n3 != n4); + CHECK(n4.set_value(STR("n4"))); + + CHECK_NODE(doc, STR("foon3")); +} + +TEST_XML(dom_node_insert_child_after, "foo") +{ + CHECK(xml_node().insert_child_after(node_element, xml_node()) == xml_node()); + CHECK(doc.child(STR("node")).first_child().insert_child_after(node_element, xml_node()) == xml_node()); + CHECK(doc.insert_child_after(node_document, xml_node()) == xml_node()); + CHECK(doc.insert_child_after(node_null, xml_node()) == xml_node()); + + xml_node node = doc.child(STR("node")); + xml_node child = node.child(STR("child")); + + CHECK(node.insert_child_after(node_element, node) == xml_node()); + CHECK(child.insert_child_after(node_element, node) == xml_node()); + + xml_node n1 = node.insert_child_after(node_element, child); + CHECK(n1 && n1 != node && n1 != child); + CHECK(n1.set_name(STR("n1"))); + + xml_node n2 = node.insert_child_after(node_element, child); + CHECK(n2 && n2 != node && n2 != child && n2 != n1); + CHECK(n2.set_name(STR("n2"))); + + xml_node n3 = node.insert_child_after(node_pcdata, n2); + CHECK(n3 && n3 != node && n3 != child && n3 != n1 && n3 != n2); + CHECK(n3.set_value(STR("n3"))); + + xml_node n4 = node.insert_child_after(node_pi, node.first_child()); + CHECK(n4 && n4 != node && n4 != child && n4 != n1 && n4 != n2 && n4 != n3); + CHECK(n4.set_name(STR("n4"))); + + CHECK(child.insert_child_after(node_element, n3) == xml_node()); + + CHECK_NODE(doc, STR("foon3")); +} + +TEST_XML(dom_node_insert_child_before, "foo") +{ + CHECK(xml_node().insert_child_before(node_element, xml_node()) == xml_node()); + CHECK(doc.child(STR("node")).first_child().insert_child_before(node_element, xml_node()) == xml_node()); + CHECK(doc.insert_child_before(node_document, xml_node()) == xml_node()); + CHECK(doc.insert_child_before(node_null, xml_node()) == xml_node()); + + xml_node node = doc.child(STR("node")); + xml_node child = node.child(STR("child")); + + CHECK(node.insert_child_before(node_element, node) == xml_node()); + CHECK(child.insert_child_before(node_element, node) == xml_node()); + + xml_node n1 = node.insert_child_before(node_element, child); + CHECK(n1 && n1 != node && n1 != child); + CHECK(n1.set_name(STR("n1"))); + + xml_node n2 = node.insert_child_before(node_element, child); + CHECK(n2 && n2 != node && n2 != child && n2 != n1); + CHECK(n2.set_name(STR("n2"))); + + xml_node n3 = node.insert_child_before(node_pcdata, n2); + CHECK(n3 && n3 != node && n3 != child && n3 != n1 && n3 != n2); + CHECK(n3.set_value(STR("n3"))); + + xml_node n4 = node.insert_child_before(node_pi, node.first_child()); + CHECK(n4 && n4 != node && n4 != child && n4 != n1 && n4 != n2 && n4 != n3); + CHECK(n4.set_name(STR("n4"))); + + CHECK(child.insert_child_before(node_element, n3) == xml_node()); + + CHECK_NODE(doc, STR("foon3")); +} + +TEST_XML(dom_node_remove_child, "") +{ + CHECK(!xml_node().remove_child(STR("a"))); + CHECK(!xml_node().remove_child(xml_node())); + + xml_node node = doc.child(STR("node")); + xml_node child = node.child(STR("child")); + + CHECK(!node.remove_child(STR("a"))); + CHECK(!node.remove_child(xml_node())); + CHECK(!node.remove_child(child.child(STR("n4")))); + + CHECK_NODE(doc, STR("")); + + CHECK(node.remove_child(STR("n1"))); + CHECK(node.remove_child(node.child(STR("n3")))); + CHECK(child.remove_child(STR("n4"))); + + CHECK_NODE(doc, STR("")); +} + +TEST_XML(dom_node_remove_child_complex, "") +{ + doc.child(STR("node")).remove_child(STR("n1")); + + CHECK_NODE(doc, STR("")); + + CHECK(doc.remove_child(STR("node"))); + + CHECK_NODE(doc, STR("")); +} + +TEST_XML(dom_node_remove_child_complex_allocated, "") +{ + doc.append_copy(doc.child(STR("node"))); + + CHECK(doc.remove_child(STR("node"))); + CHECK(doc.remove_child(STR("node"))); + + CHECK_NODE(doc, STR("")); +} + +TEST_XML(dom_node_append_copy, "foo") +{ + CHECK(xml_node().append_copy(xml_node()) == xml_node()); + CHECK(doc.child(STR("node")).first_child().append_copy(doc.child(STR("node"))) == xml_node()); + CHECK(doc.append_copy(doc) == xml_node()); + CHECK(doc.append_copy(xml_node()) == xml_node()); + + xml_node n1 = doc.child(STR("node")).append_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")).append_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")).append_copy(doc.child(STR("node")).first_child()); + CHECK(n3 && n3 != n1 && n3 != n2); + CHECK_STRING(n3.value(), STR("foo")); + CHECK_NODE(doc, STR("foofoofoo")); +} + +TEST_XML(dom_node_insert_copy_after, "foo") +{ + 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()); + + xml_node n1 = doc.child(STR("node")).insert_copy_after(doc.child(STR("node")).child(STR("child")), doc.child(STR("node")).first_child()); + CHECK(n1); + CHECK_STRING(n1.name(), STR("child")); + CHECK_NODE(doc, STR("foo")); + + xml_node n2 = doc.child(STR("node")).insert_copy_after(doc.child(STR("node")).first_child(), doc.child(STR("node")).last_child()); + CHECK(n2 && n2 != n1); + CHECK_STRING(n2.value(), STR("foo")); + CHECK_NODE(doc, STR("foofoo")); + + xml_node n3 = doc.child(STR("node")).insert_copy_after(doc.child(STR("node")).first_child(), doc.child(STR("node")).first_child()); + CHECK(n3 && n3 != n1 && n3 != n2); + CHECK_STRING(n3.value(), STR("foo")); + CHECK_NODE(doc, STR("foofoofoo")); +} + +TEST_XML(dom_node_insert_copy_before, "foo") +{ + 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()); + + xml_node n1 = doc.child(STR("node")).insert_copy_before(doc.child(STR("node")).child(STR("child")), doc.child(STR("node")).first_child()); + CHECK(n1); + CHECK_STRING(n1.name(), STR("child")); + CHECK_NODE(doc, STR("foo")); + + xml_node n2 = doc.child(STR("node")).insert_copy_before(doc.child(STR("node")).first_child(), doc.child(STR("node")).last_child()); + CHECK(n2 && n2 != n1); + CHECK_STRING(n2.name(), STR("child")); + CHECK_NODE(doc, STR("foo")); + + xml_node n3 = doc.child(STR("node")).insert_copy_before(doc.child(STR("node")).first_child().next_sibling(), doc.child(STR("node")).first_child()); + CHECK(n3 && n3 != n1 && n3 != n2); + CHECK_STRING(n3.value(), STR("foo")); + CHECK_NODE(doc, STR("foofoo")); +} + +TEST_XML(dom_node_copy_recursive, "foo") +{ + doc.child(STR("node")).append_copy(doc.child(STR("node"))); + CHECK_NODE(doc, STR("foofoo")); +} + +TEST_XML(dom_node_copy_crossdoc, "") +{ + xml_document newdoc; + newdoc.append_copy(doc.child(STR("node"))); + CHECK_NODE(doc, STR("")); + CHECK_NODE(newdoc, STR("")); +} + +TEST_XML_FLAGS(dom_node_copy_types, "pcdata", parse_default | parse_pi | parse_comments | parse_declaration) +{ + doc.append_copy(doc.child(STR("root"))); + CHECK_NODE(doc, STR("pcdatapcdata")); + + doc.insert_copy_before(doc.first_child(), doc.first_child()); + CHECK_NODE(doc, STR("pcdatapcdata")); +} + +TEST_XML(dom_attr_assign_large_number, "") +{ + xml_node node = doc.child(STR("node")); + + node.attribute(STR("attr1")) = FLT_MAX; + node.attribute(STR("attr2")) = DBL_MAX; + + 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("")); +} + +TEST(dom_string_out_of_memory) +{ + unsigned int length = 65536; + + char_t* string = new char_t[length + 1]; + for (unsigned int i = 0; i < length; ++i) string[i] = 'a'; + string[length] = 0; + + xml_document doc; + xml_node node = doc.append_child(); + xml_attribute attr = node.append_attribute(STR("a")); + xml_node text = node.append_child(node_pcdata); + + // no value => long value + test_runner::_memory_fail_threshold = 32; + + CHECK(!node.set_name(string)); + CHECK(!text.set_value(string)); + CHECK(!attr.set_name(string)); + CHECK(!attr.set_value(string)); + + // set some names/values + test_runner::_memory_fail_threshold = 0; + + node.set_name(STR("n")); + attr.set_value(STR("v")); + text.set_value(STR("t")); + + // some value => long value + test_runner::_memory_fail_threshold = 32; + + CHECK(!node.set_name(string)); + CHECK(!text.set_value(string)); + CHECK(!attr.set_name(string)); + CHECK(!attr.set_value(string)); + + // check that original state was preserved + test_runner::_memory_fail_threshold = 0; + + CHECK_NODE(doc, STR("t")); +} + +TEST(dom_node_out_of_memory) +{ + test_runner::_memory_fail_threshold = 65536; + + // exhaust memory limit + xml_document doc; + + xml_node n = doc.append_child(); + CHECK(n.set_name(STR("n"))); + + xml_attribute a = n.append_attribute(STR("a")); + CHECK(a); + + while (n.append_child(node_comment) || n.append_attribute(STR("b"))) + { + // nop + } + + // verify all node modification operations + CHECK(!n.append_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.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.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.insert_copy_after(a, a)); + CHECK(!n.insert_copy_before(a, a)); +} -- cgit v1.2.3