From 903db8682a5f14b52adec996584c70ea072619ea Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 23 Oct 2014 07:41:07 +0000 Subject: tests: Add more tests for better coverage More tests for out-of-memory and other edge conditions git-svn-id: https://pugixml.googlecode.com/svn/trunk@1075 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_xpath.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/test_xpath.cpp') diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index 2143376..80115b8 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -606,4 +606,27 @@ TEST(xpath_sort_crossdoc_different_depth) CHECK(ns.size() == 2); CHECK((ns[0] == ns1[0] && ns[1] == ns2[0]) || (ns[0] == ns2[0] && ns[1] == ns1[0])); } + +TEST(xpath_allocate_string_out_of_memory) +{ + std::basic_string query; + + for (int i = 0; i < 1024; ++i) query += STR("abcdefgh"); + + test_runner::_memory_fail_threshold = 8*1024; + +#ifdef PUGIXML_NO_EXCEPTIONS + CHECK(!xpath_query(query.c_str())); +#else + try + { + xpath_query q(query.c_str()); + + CHECK_FORCE_FAIL("Expected out of memory exception"); + } + catch (const std::bad_alloc&) + { + } +#endif +} #endif -- cgit v1.2.3