summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_xpath.cpp16
-rw-r--r--tests/test_xpath_paths.cpp75
2 files changed, 91 insertions, 0 deletions
diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp
index 69513fc..3f5d084 100644
--- a/tests/test_xpath.cpp
+++ b/tests/test_xpath.cpp
@@ -407,6 +407,22 @@ TEST(xpath_out_of_memory_evaluate_concat)
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, xml_node()) == 1));
}
+TEST(xpath_out_of_memory_evaluate_concat_list)
+{
+ std::basic_string<char_t> query = STR("concat(");
+
+ for (size_t i = 0; i < 500; ++i)
+ query += STR("\"\",");
+
+ query += STR("\"\")");
+
+ pugi::xpath_query q(query.c_str());
+
+ test_runner::_memory_fail_threshold = 1;
+
+ CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, xml_node()) == 1));
+}
+
TEST(xpath_out_of_memory_evaluate_substring)
{
test_runner::_memory_fail_threshold = 4196 * sizeof(char_t) + 4096 * 2;
diff --git a/tests/test_xpath_paths.cpp b/tests/test_xpath_paths.cpp
index 7915df1..dd97019 100644
--- a/tests/test_xpath_paths.cpp
+++ b/tests/test_xpath_paths.cpp
@@ -703,4 +703,79 @@ TEST_XML(xpath_paths_null_nodeset_entries, "<node attr='value'/>")
CHECK(rs[0] == nodes[0]);
CHECK(rs[1] == nodes[2]);
}
+
+TEST_XML(xpath_paths_step_leaf_coverage, "<n><n1/><n2 a='v'><child/></n2><n3/></n>")
+{
+ xml_node n = doc.child(STR("n")).child(STR("n2"));
+
+ CHECK_XPATH_NODESET(n, STR("ancestor::node()")) % 2 % 1;
+ CHECK_XPATH_NODESET(n, STR("ancestor-or-self::node()")) % 4 % 2 % 1;
+ CHECK_XPATH_NODESET(n, STR("attribute::node()")) % 5;
+ CHECK_XPATH_NODESET(n, STR("child::node()")) % 6;
+ CHECK_XPATH_NODESET(n, STR("descendant::node()")) % 6;
+ CHECK_XPATH_NODESET(n, STR("descendant-or-self::node()")) % 4 % 6;
+ CHECK_XPATH_NODESET(n, STR("following::node()")) % 7;
+ CHECK_XPATH_NODESET(n, STR("following-sibling::node()")) % 7;
+ CHECK_XPATH_NODESET(n, STR("namespace::node()"));
+ CHECK_XPATH_NODESET(n, STR("parent::node()")) % 2;
+ CHECK_XPATH_NODESET(n, STR("preceding::node()")) % 3;
+ CHECK_XPATH_NODESET(n, STR("preceding-sibling::node()")) % 3;
+ CHECK_XPATH_NODESET(n, STR("self::node()")) % 4;
+}
+TEST_XML(xpath_paths_step_leaf_predicate_coverage, "<n><n1/><n2 a='v'><child/></n2><n3/></n>")
+{
+ xml_node n = doc.child(STR("n")).child(STR("n2"));
+
+ CHECK_XPATH_NODESET(n, STR("ancestor::node()[1]")) % 2;
+ CHECK_XPATH_NODESET(n, STR("ancestor-or-self::node()[1]")) % 4;
+ CHECK_XPATH_NODESET(n, STR("attribute::node()[1]")) % 5;
+ CHECK_XPATH_NODESET(n, STR("child::node()[1]")) % 6;
+ CHECK_XPATH_NODESET(n, STR("descendant::node()[1]")) % 6;
+ CHECK_XPATH_NODESET(n, STR("descendant-or-self::node()[1]")) % 4;
+ CHECK_XPATH_NODESET(n, STR("following::node()[1]")) % 7;
+ CHECK_XPATH_NODESET(n, STR("following-sibling::node()[1]")) % 7;
+ CHECK_XPATH_NODESET(n, STR("namespace::node()[1]"));
+ CHECK_XPATH_NODESET(n, STR("parent::node()[1]")) % 2;
+ CHECK_XPATH_NODESET(n, STR("preceding::node()[1]")) % 3;
+ CHECK_XPATH_NODESET(n, STR("preceding-sibling::node()[1]")) % 3;
+ CHECK_XPATH_NODESET(n, STR("self::node()[1]")) % 4;
+}
+
+TEST_XML(xpath_paths_step_step_coverage, "<n><n1/><n2 a='v'><child/></n2><n3/></n>")
+{
+ xml_node n = doc.child(STR("n")).child(STR("n2"));
+
+ CHECK_XPATH_NODESET(n, STR("./ancestor::node()")) % 2 % 1;
+ CHECK_XPATH_NODESET(n, STR("./ancestor-or-self::node()")) % 4 % 2 % 1;
+ CHECK_XPATH_NODESET(n, STR("./attribute::node()")) % 5;
+ CHECK_XPATH_NODESET(n, STR("./child::node()")) % 6;
+ CHECK_XPATH_NODESET(n, STR("./descendant::node()")) % 6;
+ CHECK_XPATH_NODESET(n, STR("./descendant-or-self::node()")) % 4 % 6;
+ CHECK_XPATH_NODESET(n, STR("./following::node()")) % 7;
+ CHECK_XPATH_NODESET(n, STR("./following-sibling::node()")) % 7;
+ CHECK_XPATH_NODESET(n, STR("./namespace::node()"));
+ CHECK_XPATH_NODESET(n, STR("./parent::node()")) % 2;
+ CHECK_XPATH_NODESET(n, STR("./preceding::node()")) % 3;
+ CHECK_XPATH_NODESET(n, STR("./preceding-sibling::node()")) % 3;
+ CHECK_XPATH_NODESET(n, STR("./self::node()")) % 4;
+}
+
+TEST_XML(xpath_paths_step_step_predicate_coverage, "<n><n1/><n2 a='v'><child/></n2><n3/></n>")
+{
+ xml_node n = doc.child(STR("n")).child(STR("n2"));
+
+ CHECK_XPATH_NODESET(n, STR("./ancestor::node()[1]")) % 2;
+ CHECK_XPATH_NODESET(n, STR("./ancestor-or-self::node()[1]")) % 4;
+ CHECK_XPATH_NODESET(n, STR("./attribute::node()[1]")) % 5;
+ CHECK_XPATH_NODESET(n, STR("./child::node()[1]")) % 6;
+ CHECK_XPATH_NODESET(n, STR("./descendant::node()[1]")) % 6;
+ CHECK_XPATH_NODESET(n, STR("./descendant-or-self::node()[1]")) % 4;
+ CHECK_XPATH_NODESET(n, STR("./following::node()[1]")) % 7;
+ CHECK_XPATH_NODESET(n, STR("./following-sibling::node()[1]")) % 7;
+ CHECK_XPATH_NODESET(n, STR("./namespace::node()[1]"));
+ CHECK_XPATH_NODESET(n, STR("./parent::node()[1]")) % 2;
+ CHECK_XPATH_NODESET(n, STR("./preceding::node()[1]")) % 3;
+ CHECK_XPATH_NODESET(n, STR("./preceding-sibling::node()[1]")) % 3;
+ CHECK_XPATH_NODESET(n, STR("./self::node()[1]")) % 4;
+}
#endif