From 3fcc530b341709000b7acf4e8b85ad11cac0927d Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 2 Oct 2014 03:06:59 +0000 Subject: [PATCH] tests: Add missing tests to increase code coverage git-svn-id: https://pugixml.googlecode.com/svn/trunk@1038 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_dom_modify.cpp | 5 ++++- tests/test_dom_traverse.cpp | 27 +++++++++++++++++++++++++++ tests/test_parse.cpp | 3 ++- tests/test_xpath_functions.cpp | 14 ++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index a66f56a..cf202e0 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1180,8 +1180,9 @@ TEST_XML(dom_node_insert_move_before, "foobar") TEST_XML(dom_node_move_recursive, "foo") { xml_node root = doc.child(STR("root")); - xml_node node = doc.child(STR("node")); + xml_node node = root.child(STR("node")); xml_node foo = node.first_child(); + xml_node child = node.last_child(); CHECK(node.prepend_move(node) == xml_node()); CHECK(node.prepend_move(root) == xml_node()); @@ -1195,6 +1196,8 @@ TEST_XML(dom_node_move_recursive, "foo") CHECK(node.insert_move_after(node, foo) == xml_node()); CHECK(node.insert_move_after(root, foo) == xml_node()); + CHECK(child.append_move(node) == xml_node()); + CHECK_NODE(doc, STR("foo")); } diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index 43fec80..c2437ab 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -1015,4 +1015,31 @@ TEST_XML(dom_node_named_iterator, "< CHECK(itt-- == r1.end()); CHECK(itt == r1.begin()); + + CHECK(itt->offset_debug() == 14); +} + +TEST_XML(dom_node_children_attributes, "") +{ + xml_object_range r1 = doc.children(); + + CHECK(r1.begin() == doc.begin()); + CHECK(r1.end() == doc.end()); + + xml_object_range r2 = xml_node().children(); + + CHECK(r2.begin() == xml_node_iterator()); + CHECK(r2.end() == xml_node_iterator()); + + xml_node node = doc.child(STR("node1")); + + xml_object_range r3 = node.attributes(); + + CHECK(r3.begin() == node.attributes_begin()); + CHECK(r3.end() == node.attributes_end()); + + xml_object_range r4 = xml_node().attributes(); + + CHECK(r4.begin() == xml_attribute_iterator()); + CHECK(r4.end() == xml_attribute_iterator()); } diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index 38b09f5..2094ef9 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -451,7 +451,8 @@ TEST(parse_pcdata_trim) { STR("\r\n\t text \r\n\r\n\r\n\r\n\r\n\r\n\r\n more \r\n\t"), STR("text \n\n\n\n\n\n\n more"), parse_eol }, { STR(" test&&&&&&& "), STR("test&&&&&&&"), 0 }, { STR(" test&&&&&&& "), STR("test&&&&&&&"), parse_escapes }, - { STR(" test&&&&&&& "), STR("test&&&&&&&"), parse_fragment | parse_escapes } + { STR(" test&&&&&&& "), STR("test&&&&&&&"), parse_fragment | parse_escapes }, + { STR("\r\n\t text \t\n\r m&&e \r\n\t"), STR("text \t\n\n m&&e"), parse_eol | parse_escapes } }; for (size_t i = 0; i < sizeof(test_data) / sizeof(test_data[0]); ++i) diff --git a/tests/test_xpath_functions.cpp b/tests/test_xpath_functions.cpp index 7245bee..30ba218 100644 --- a/tests/test_xpath_functions.cpp +++ b/tests/test_xpath_functions.cpp @@ -414,6 +414,13 @@ TEST(xpath_string_substring_after) CHECK_XPATH_FAIL(STR("substring-after('a', 'b', 'c')")); } +TEST_XML(xpath_string_substring_after_heap, "foobar") +{ + CHECK_XPATH_STRING(doc, STR("substring-after(node, 'fo')"), STR("obar")); + CHECK_XPATH_STRING(doc, STR("substring-after(node, 'fooba')"), STR("r")); + CHECK_XPATH_STRING(doc, STR("substring-after(node, 'foobar')"), STR("")); +} + TEST(xpath_string_substring) { xml_node c; @@ -474,6 +481,13 @@ TEST(xpath_string_substring) CHECK_XPATH_FAIL(STR("substring('', 1, 2, 3)")); } +TEST_XML(xpath_string_substring_heap, "foobar") +{ + CHECK_XPATH_STRING(doc, STR("substring(node, 3)"), STR("obar")); + CHECK_XPATH_STRING(doc, STR("substring(node, 6)"), STR("r")); + CHECK_XPATH_STRING(doc, STR("substring(node, 7)"), STR("")); +} + TEST_XML(xpath_string_string_length, "123") { xml_node c;