0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-27 13:33:17 +08:00

tests: Improve XPath coverage

Add memory allocation failure test for concact with a very large list
and make sure we have every single axis covered with and without a
predicate, with and without a previous step.
This commit is contained in:
Arseny Kapoulkine 2017-06-16 22:42:40 -07:00
parent 08f102f14c
commit 0027b6ac79
2 changed files with 91 additions and 0 deletions

View File

@ -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;

View File

@ -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