From 02cee98492233f4ae91f025fc38f9df8b4bc0efe Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 30 Jan 2017 21:36:05 -0800 Subject: tests: Add more tests for branch coverage gcov -b surfaced many lines with partial coverage, where branch is only ever taken or not taken, or one of the expressions in a complex conditional is always either true or false. This change adds a series of tests (mostly focusing on XPath) to reduce the number of partially covered lines. --- tests/test_xpath.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/test_xpath.cpp') diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index 33c1696..ea77121 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -367,6 +367,32 @@ TEST(xpath_large_node_set) CHECK(ns.size() == 10001); } +TEST(xpath_out_of_memory_query) +{ + test_runner::_memory_fail_threshold = 1; + + CHECK_ALLOC_FAIL(xpath_query q(STR("node"))); +} + +TEST_XML(xpath_out_of_memory_evaluate, "") +{ + test_runner::_memory_fail_threshold = 4196 * sizeof(char_t) + 4096 * 2 + 32768; + + std::basic_string query = STR("*[concat(\"a\", \""); + + query.resize(4196, 'a'); + query += STR("\")]"); + + pugi::xpath_query q(query.c_str()); + + CHECK_ALLOC_FAIL(CHECK(q.evaluate_boolean(doc) == false)); + CHECK_ALLOC_FAIL(CHECK_DOUBLE_NAN(q.evaluate_number(doc))); + CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc).empty())); + CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, doc) == 1)); + CHECK_ALLOC_FAIL(CHECK(q.evaluate_node(doc) == xpath_node())); + CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc).empty())); +} + TEST(xpath_out_of_memory_evaluate_concat) { test_runner::_memory_fail_threshold = 4196 * sizeof(char_t) + 4096 * 2; @@ -612,4 +638,15 @@ TEST(xpath_remove_duplicates) tester % (2 + i); } } + +TEST(xpath_anonymous_nodes) +{ + xml_document doc; + doc.append_child(node_element); + doc.append_child(node_pi); + + CHECK_XPATH_NODESET(doc, STR("/name")); + CHECK_XPATH_NODESET(doc, STR("/processing-instruction('a')")); + CHECK_XPATH_NODESET(doc, STR("/ns:*")); +} #endif -- cgit v1.2.3 From 60d5688a87b03aa85b74026c1fb79fd0ca8903d7 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 30 Jan 2017 22:27:48 -0800 Subject: tests: Make predicate out-of-memory test less aggressive Currently this test has very large runtime and relies on the fact that the first memory allocation error causes the test to terminate. This does not work with new behavior of running the query through and reporting the error at the end, so make the runtime reasonable but still generate enough memory to blow past the budget. --- tests/test_xpath.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_xpath.cpp') diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index ea77121..8359f4f 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -430,11 +430,11 @@ TEST_XML(xpath_out_of_memory_evaluate_union, " CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc.child(STR("node"))).empty())); } -TEST_XML(xpath_out_of_memory_evaluate_predicate, "") +TEST_XML(xpath_out_of_memory_evaluate_predicate, "") { test_runner::_memory_fail_threshold = 32768 + 4096 * 2; - pugi::xpath_query q(STR("//a[//a[//a[//a[//a[//a[//a[//a[//a[//a[//a[//a[//a[//a[true()]]]]]]]]]]]]]]")); + pugi::xpath_query q(STR("//a[//a[//a[//a[true()]]]]")); CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc).empty())); } -- cgit v1.2.3 From a1bc15c8d525ff2cac165cc0e5d08b272d79fc33 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 30 Jan 2017 23:24:20 -0800 Subject: tests: Add more coverage tests Expand out of memory coverage during XPath parsing and evaluation and add some other small tests. --- tests/test_xpath.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests/test_xpath.cpp') diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index 8359f4f..f8a4b15 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -439,6 +439,42 @@ TEST_XML(xpath_out_of_memory_evaluate_predicate, " CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc).empty())); } +TEST_XML(xpath_out_of_memory_evaluate_normalize_space_0, " a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z ") +{ + test_runner::_memory_fail_threshold = 32768 + 4096 * 2; + + pugi::xpath_query q(STR("concat(normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space())")); + + CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc.first_child()).empty())); +} + +TEST_XML(xpath_out_of_memory_evaluate_normalize_space_1, " a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z ") +{ + test_runner::_memory_fail_threshold = 32768 + 4096 * 2; + + pugi::xpath_query q(STR("concat(normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node))")); + + CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc).empty())); +} + +TEST_XML(xpath_out_of_memory_evaluate_translate, " a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z ") +{ + test_runner::_memory_fail_threshold = 32768 + 4096 * 2; + + pugi::xpath_query q(STR("concat(translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'))")); + + CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc).empty())); +} + +TEST_XML(xpath_out_of_memory_evaluate_translate_table, " a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z ") +{ + test_runner::_memory_fail_threshold = 32768 + 4096 * 2; + + pugi::xpath_query q(STR("concat(translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'))")); + + CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc).empty())); +} + TEST(xpath_memory_concat_massive) { pugi::xml_document doc; -- cgit v1.2.3 From faadd460c4f578645bb7dc759d4e66e0db11a13c Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 2 Feb 2017 08:57:02 -0800 Subject: tests: Add more out of memory tests for XPath evaluation --- tests/test_xpath.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/test_xpath.cpp') diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index f8a4b15..9cf8bd5 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -475,6 +475,38 @@ TEST_XML(xpath_out_of_memory_evaluate_translate_table, " a b c d e f g h i CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc).empty())); } +TEST(xpath_out_of_memory_evaluate_string_append) +{ + test_runner::_memory_fail_threshold = 32768 + 4096 * 2; + + std::basic_string literal(5000, 'a'); + + std::basic_string buf; + buf += STR("text"); + buf += literal; + buf += STR(""); + + xml_document doc; + CHECK(doc.load_buffer_inplace(&buf[0], buf.size() * sizeof(char_t))); + + pugi::xpath_query q(STR("string(n)")); + CHECK(q); + + CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc).empty())); +} + +TEST(xpath_out_of_memory_evaluate_number_to_string) +{ + test_runner::_memory_fail_threshold = 4096 + 128; + + xpath_variable_set vars; + vars.set(STR("x"), 1e+308); + + xpath_query q(STR("concat($x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x)"), &vars); + + CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(xml_node()).empty())); +} + TEST(xpath_memory_concat_massive) { pugi::xml_document doc; -- cgit v1.2.3 From 10676b6b8548ddbf9458993062e6a27c2c233d48 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 4 Feb 2017 18:43:43 -0800 Subject: tests: Add more XPath sorting tests Cover empty node case - no XPath query can result in that but it's possible to create a node set with empty nodes manually. --- tests/test_xpath.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/test_xpath.cpp') diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index 9cf8bd5..6cae607 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -672,6 +672,17 @@ TEST(xpath_sort_crossdoc_different_depth) CHECK((ns[0] == ns1[0] && ns[1] == ns2[0]) || (ns[0] == ns2[0] && ns[1] == ns1[0])); } +TEST_XML(xpath_sort_empty_node, "") +{ + xml_node n = doc.child(STR("node")); + xpath_node nodes[] = { n.child(STR("child2")), xml_node(), n.child(STR("child1")), xml_node() }; + xpath_node_set ns(nodes, nodes + sizeof(nodes) / sizeof(nodes[0])); + + ns.sort(); + + CHECK(!ns[0] && !ns[1] && ns[2] == nodes[2] && ns[3] == nodes[0]); +} + TEST(xpath_allocate_string_out_of_memory) { std::basic_string query; -- cgit v1.2.3