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.hpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/test.hpp') diff --git a/tests/test.hpp b/tests/test.hpp index 4222638..46c3330 100644 --- a/tests/test.hpp +++ b/tests/test.hpp @@ -142,6 +142,12 @@ struct dummy_fixture {}; #define CHECK_XPATH_FAIL(query) CHECK_XPATH_FAIL_VAR(query, 0) #endif +#ifdef PUGIXML_NO_EXCEPTIONS +#define CHECK_ALLOC_FAIL(code) CHECK(!test_runner::_memory_fail_triggered); code; CHECK(test_runner::_memory_fail_triggered); test_runner::_memory_fail_triggered = false +#else +#define CHECK_ALLOC_FAIL(code) CHECK(!test_runner::_memory_fail_triggered); try { code; } catch (std::bad_alloc&) {} CHECK(test_runner::_memory_fail_triggered); test_runner::_memory_fail_triggered = false +#endif + #define STR(text) PUGIXML_TEXT(text) #ifdef __DMC__ -- cgit v1.2.3