summaryrefslogtreecommitdiff
path: root/tests/test_xpath.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2017-01-30 21:36:05 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2017-01-30 21:58:48 -0800
commit02cee98492233f4ae91f025fc38f9df8b4bc0efe (patch)
treed862fa9912ff932b4b4b52a7932d6ae1c814979b /tests/test_xpath.cpp
parentcac1d8ad9f602e74841acb05596396ee00994ebb (diff)
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.
Diffstat (limited to 'tests/test_xpath.cpp')
-rw-r--r--tests/test_xpath.cpp37
1 files changed, 37 insertions, 0 deletions
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, "<n/>")
+{
+ test_runner::_memory_fail_threshold = 4196 * sizeof(char_t) + 4096 * 2 + 32768;
+
+ std::basic_string<char_t> 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