From 00d4994f2458bec4216a9bfe1ca17ce723c605f3 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine@gmail.com" Date: Fri, 7 Dec 2012 04:49:51 +0000 Subject: tests: Added append_buffer tests git-svn-id: http://pugixml.googlecode.com/svn/trunk@937 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_dom_modify.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index a63435c..8295c4c 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -913,3 +913,115 @@ TEST(dom_node_doctype_value) CHECK(node.set_value(STR("id [ foo ]"))); CHECK_NODE(node, STR("")); } + +TEST_XML(dom_node_append_buffer_native, "test") +{ + xml_node node = doc.child(STR("node")); + + const char_t data1[] = STR("text"); + const char_t data2[] = STR(""); + + CHECK(node.append_buffer(data1, sizeof(data1))); + CHECK(node.append_buffer(data2, sizeof(data2))); + CHECK(node.append_buffer(data1, sizeof(data1))); + CHECK(node.append_buffer(data2, sizeof(data2))); + CHECK(node.append_buffer(data2, sizeof(data2))); + + CHECK_NODE(doc, STR("testtexttext")); +} + +TEST_XML(dom_node_append_buffer_convert, "test") +{ + xml_node node = doc.child(STR("node")); + + const char data[] = {0, 0, 0, '<', 0, 0, 0, 'n', 0, 0, 0, '/', 0, 0, 0, '>'}; + + CHECK(node.append_buffer(data, sizeof(data))); + CHECK(node.append_buffer(data, sizeof(data), parse_default, encoding_utf32_be)); + + CHECK_NODE(doc, STR("test")); +} + + +TEST_XML(dom_node_append_buffer_remove, "test") +{ + xml_node node = doc.child(STR("node")); + + const char data1[] = "text"; + const char data2[] = ""; + + CHECK(node.append_buffer(data1, sizeof(data1))); + CHECK(node.append_buffer(data2, sizeof(data2))); + CHECK(node.append_buffer(data1, sizeof(data1))); + CHECK(node.append_buffer(data2, sizeof(data2))); + + CHECK_NODE(doc, STR("testtexttext")); + + while (node.remove_child(STR("child2"))) {} + + CHECK_NODE(doc, STR("test")); + + while (node.remove_child(STR("child1"))) {} + + CHECK_NODE(doc, STR("test")); + + while (node.remove_child(STR("child3"))) {} + + CHECK_NODE(doc, STR("test")); + + doc.remove_child(STR("node")); + + CHECK(!doc.first_child()); +} + +TEST(dom_node_append_buffer_empty_document) +{ + xml_document doc; + + const char data[] = "text"; + + doc.append_buffer(data, sizeof(data)); + + CHECK_NODE(doc, STR("text")); +} + +TEST_XML(dom_node_append_buffer_invalid_type, "test") +{ + const char data[] = "text"; + + CHECK(xml_node().append_buffer(data, sizeof(data)).status == status_append_invalid_root); + CHECK(doc.first_child().first_child().append_buffer(data, sizeof(data)).status == status_append_invalid_root); +} + +TEST_XML(dom_node_append_buffer_close_external, "") +{ + xml_node node = doc.child(STR("node")); + + const char data[] = ""; + + CHECK(node.append_buffer(data, sizeof(data)).status == status_end_element_mismatch); + CHECK_NODE(doc, STR("")); + + CHECK(node.append_buffer(data, sizeof(data)).status == status_end_element_mismatch); + CHECK_NODE(doc, STR("")); +} + +TEST(dom_node_append_buffer_out_of_memory_extra) +{ + test_runner::_memory_fail_threshold = 1; + + xml_document doc; + CHECK(doc.append_buffer("", 4).status == status_out_of_memory); + CHECK(!doc.first_child()); +} + +TEST(dom_node_append_buffer_out_of_memory_buffer) +{ + test_runner::_memory_fail_threshold = 32768 + 128; + + const char data[128] = {}; + + xml_document doc; + CHECK(doc.append_buffer(data, sizeof(data)).status == status_out_of_memory); + CHECK(!doc.first_child()); +} -- cgit v1.2.3