From 814443b147e6159a0ad2842fabc1288ec6a0ee24 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 11 Apr 2015 22:37:38 -0700 Subject: Fix exception type for out-of-memory for XPath variables When parsing XPath variables, we need to perform a heap allocation; if it fails, an xpath_exception instead of bad_alloc used to be thrown. Now we throw the exception of a correct type so that xpath_exception means 'parsing error'. --- tests/test_xpath_variables.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_xpath_variables.cpp') diff --git a/tests/test_xpath_variables.cpp b/tests/test_xpath_variables.cpp index 53b40cf..7a099c4 100644 --- a/tests/test_xpath_variables.cpp +++ b/tests/test_xpath_variables.cpp @@ -293,7 +293,7 @@ TEST(xpath_variables_long_name_out_of_memory) CHECK_FORCE_FAIL("Expected exception"); } - catch (const xpath_exception&) + catch (const std::bad_alloc&) { } #endif -- cgit v1.2.3 From 4e004176bacb0160007102742ec62e79a9d958bb Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 11 Apr 2015 22:46:08 -0700 Subject: tests: Improve out-of-memory tests Previously there was no guarantee that the tests that check for out of memory handling behavior are actually correct - e.g. that they correctly simulate out of memory conditions. Now every simulated out of memory condition has to be "guarded" using CHECK_ALLOC_FAIL. It makes sure that every piece of code that is supposed to cause out-of-memory does so, and that no other code runs out of memory unnoticed. --- tests/test_xpath_variables.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'tests/test_xpath_variables.cpp') diff --git a/tests/test_xpath_variables.cpp b/tests/test_xpath_variables.cpp index 7a099c4..0d33312 100644 --- a/tests/test_xpath_variables.cpp +++ b/tests/test_xpath_variables.cpp @@ -177,7 +177,8 @@ TEST(xpath_variables_set_out_of_memory) xpath_variable_set set; - xpath_variable* var = set.add(STR("target"), xpath_type_number); + xpath_variable* var = 0; + CHECK_ALLOC_FAIL(var = set.add(STR("target"), xpath_type_number)); CHECK(!var); } @@ -190,7 +191,7 @@ TEST(xpath_variables_out_of_memory) xpath_variable* var = set.add(STR("target"), xpath_type_string); CHECK(var); - CHECK(!var->set(STR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))); + CHECK_ALLOC_FAIL(CHECK(!var->set(STR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")))); } TEST_XML(xpath_variables_evaluate, "") @@ -283,20 +284,7 @@ TEST(xpath_variables_long_name_out_of_memory) test_runner::_memory_fail_threshold = 4096 + 64 + 52 * sizeof(char_t); -#ifdef PUGIXML_NO_EXCEPTIONS - xpath_query q(STR("$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &set); - CHECK(!q); -#else - try - { - xpath_query q(STR("$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &set); - - CHECK_FORCE_FAIL("Expected exception"); - } - catch (const std::bad_alloc&) - { - } -#endif + CHECK_ALLOC_FAIL(CHECK(!xpath_query(STR("$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &set))); } TEST_XML(xpath_variables_select, "") -- cgit v1.2.3