summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2017-02-02 08:57:02 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2017-02-02 08:57:02 -0800
commitfaadd460c4f578645bb7dc759d4e66e0db11a13c (patch)
tree7ec65aad53e0a3e4ab8f41487b62d3b21dcf1edc /tests
parentc28ff128d862ace16b7377dd943a8ca8f7bcfcb0 (diff)
tests: Add more out of memory tests for XPath evaluation
Diffstat (limited to 'tests')
-rw-r--r--tests/test_xpath.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp
index f8a4b15..9cf8bd5 100644
--- a/tests/test_xpath.cpp
+++ b/tests/test_xpath.cpp
@@ -475,6 +475,38 @@ TEST_XML(xpath_out_of_memory_evaluate_translate_table, "<node> a b c d e f g h i
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc).empty()));
}
+TEST(xpath_out_of_memory_evaluate_string_append)
+{
+ test_runner::_memory_fail_threshold = 32768 + 4096 * 2;
+
+ std::basic_string<char_t> literal(5000, 'a');
+
+ std::basic_string<char_t> buf;
+ buf += STR("<n><c>text</c><c>");
+ buf += literal;
+ buf += STR("</c></n>");
+
+ xml_document doc;
+ CHECK(doc.load_buffer_inplace(&buf[0], buf.size() * sizeof(char_t)));
+
+ pugi::xpath_query q(STR("string(n)"));
+ CHECK(q);
+
+ CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc).empty()));
+}
+
+TEST(xpath_out_of_memory_evaluate_number_to_string)
+{
+ test_runner::_memory_fail_threshold = 4096 + 128;
+
+ xpath_variable_set vars;
+ vars.set(STR("x"), 1e+308);
+
+ xpath_query q(STR("concat($x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x)"), &vars);
+
+ CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(xml_node()).empty()));
+}
+
TEST(xpath_memory_concat_massive)
{
pugi::xml_document doc;