summaryrefslogtreecommitdiff
path: root/tests/test_xpath.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-09-14 05:29:16 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-09-14 05:29:16 +0000
commit521384bd21b6321368b4094677d482698fe5c5a5 (patch)
tree4f0df4dbae8537cdb333eee944f268e03277c9a1 /tests/test_xpath.cpp
parent7b1560f4b292090a71cbbc8d3f9cc5a69a19ad09 (diff)
tests: Added XPath out of memory tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@728 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_xpath.cpp')
-rw-r--r--tests/test_xpath.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp
index 0f8149f..1c1629f 100644
--- a/tests/test_xpath.cpp
+++ b/tests/test_xpath.cpp
@@ -294,4 +294,99 @@ TEST(xpath_large_node_set)
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