From faadd460c4f578645bb7dc759d4e66e0db11a13c Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 2 Feb 2017 08:57:02 -0800 Subject: tests: Add more out of memory tests for XPath evaluation --- tests/test_xpath.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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, " 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 literal(5000, 'a'); + + std::basic_string buf; + buf += STR("text"); + buf += literal; + buf += STR(""); + + 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; -- cgit v1.2.3