tests: Added XPath out of memory tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@728 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
7b1560f4b2
commit
521384bd21
@ -294,4 +294,99 @@ TEST(xpath_large_node_set)
|
|||||||
|
|
||||||
CHECK(ns.size() == 10001);
|
CHECK(ns.size() == 10001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(xpath_out_of_memory_evaluate_concat)
|
||||||
|
{
|
||||||
|
test_runner::_memory_fail_threshold = 4096 * 2 * sizeof(char_t) + 4096 * 2;
|
||||||
|
|
||||||
|
std::basic_string<char_t> query = STR("concat(\"a\", \"");
|
||||||
|
|
||||||
|
query.resize(4196, 'a');
|
||||||
|
query += STR("\")");
|
||||||
|
|
||||||
|
pugi::xpath_query q(query.c_str());
|
||||||
|
|
||||||
|
#ifdef PUGIXML_NO_EXCEPTIONS
|
||||||
|
CHECK(q.evaluate_string(0, 0, xml_node()) == 1);
|
||||||
|
#else
|
||||||
|
try
|
||||||
|
{
|
||||||
|
q.evaluate_string(0, 0, xml_node());
|
||||||
|
|
||||||
|
CHECK_FORCE_FAIL("Expected out of memory exception");
|
||||||
|
}
|
||||||
|
catch (const std::bad_alloc&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(xpath_out_of_memory_evaluate_substring)
|
||||||
|
{
|
||||||
|
test_runner::_memory_fail_threshold = 4096 * 2 * sizeof(char_t) + 4096 * 2;
|
||||||
|
|
||||||
|
std::basic_string<char_t> query = STR("substring(\"");
|
||||||
|
|
||||||
|
query.resize(4196, 'a');
|
||||||
|
query += STR("\", 1, 4097)");
|
||||||
|
|
||||||
|
pugi::xpath_query q(query.c_str());
|
||||||
|
|
||||||
|
#ifdef PUGIXML_NO_EXCEPTIONS
|
||||||
|
CHECK(q.evaluate_string(0, 0, xml_node()) == 1);
|
||||||
|
#else
|
||||||
|
try
|
||||||
|
{
|
||||||
|
q.evaluate_string(0, 0, xml_node());
|
||||||
|
|
||||||
|
CHECK_FORCE_FAIL("Expected out of memory exception");
|
||||||
|
}
|
||||||
|
catch (const std::bad_alloc&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_XML(xpath_out_of_memory_evaluate_union, "<node><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/></node>")
|
||||||
|
{
|
||||||
|
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|a|a|a|a|a|a|a"));
|
||||||
|
|
||||||
|
#ifdef PUGIXML_NO_EXCEPTIONS
|
||||||
|
CHECK(q.evaluate_node_set(doc.child(STR("node"))).empty());
|
||||||
|
#else
|
||||||
|
try
|
||||||
|
{
|
||||||
|
q.evaluate_node_set(doc.child(STR("node")));
|
||||||
|
|
||||||
|
CHECK_FORCE_FAIL("Expected out of memory exception");
|
||||||
|
}
|
||||||
|
catch (const std::bad_alloc&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_XML(xpath_out_of_memory_evaluate_predicate, "<node><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/></node>")
|
||||||
|
{
|
||||||
|
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()]]]]]]]]]]]]]]"));
|
||||||
|
|
||||||
|
#ifdef PUGIXML_NO_EXCEPTIONS
|
||||||
|
CHECK(q.evaluate_node_set(doc).empty());
|
||||||
|
#else
|
||||||
|
try
|
||||||
|
{
|
||||||
|
q.evaluate_node_set(doc);
|
||||||
|
|
||||||
|
CHECK_FORCE_FAIL("Expected out of memory exception");
|
||||||
|
}
|
||||||
|
catch (const std::bad_alloc&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -314,6 +314,64 @@ TEST(xpath_api_exception_what)
|
|||||||
CHECK(e.what()[0] != 0);
|
CHECK(e.what()[0] != 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(xpath_api_node_set_ctor_out_of_memory)
|
||||||
|
{
|
||||||
|
test_runner::_memory_fail_threshold = 1;
|
||||||
|
|
||||||
|
xpath_node data[2];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
xpath_node_set ns(data, data + 2);
|
||||||
|
|
||||||
|
CHECK_FORCE_FAIL("Expected out of memory exception");
|
||||||
|
}
|
||||||
|
catch (const std::bad_alloc&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(xpath_api_node_set_copy_ctor_out_of_memory)
|
||||||
|
{
|
||||||
|
xpath_node data[2];
|
||||||
|
xpath_node_set ns(data, data + 2);
|
||||||
|
|
||||||
|
test_runner::_memory_fail_threshold = 1;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
xpath_node_set copy = ns;
|
||||||
|
|
||||||
|
CHECK_FORCE_FAIL("Expected out of memory exception");
|
||||||
|
}
|
||||||
|
catch (const std::bad_alloc&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_XML(xpath_api_node_set_assign_out_of_memory_preserve, "<node><a/><b/></node>")
|
||||||
|
{
|
||||||
|
xpath_node_set ns = doc.select_nodes(STR("node/*"));
|
||||||
|
CHECK(ns.size() == 2);
|
||||||
|
|
||||||
|
xpath_node_set nsall = doc.select_nodes(STR("//*"));
|
||||||
|
CHECK(nsall.size() == 3);
|
||||||
|
|
||||||
|
test_runner::_memory_fail_threshold = 1;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ns = nsall;
|
||||||
|
|
||||||
|
CHECK_FORCE_FAIL("Expected out of memory exception");
|
||||||
|
}
|
||||||
|
catch (const std::bad_alloc&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(ns.size() == 2 && ns[0] == doc.child(STR("node")).child(STR("a")) && ns[1] == doc.child(STR("node")).child(STR("b")));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user