summaryrefslogtreecommitdiff
path: root/tests/test.hpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-11 22:46:08 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-11 22:46:08 -0700
commit4e004176bacb0160007102742ec62e79a9d958bb (patch)
treee903e77b67e3a24c50238b7b60b223340fc52b8e /tests/test.hpp
parent37467c13bfdfbdbee7cc5176a8755e04353a9deb (diff)
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.
Diffstat (limited to 'tests/test.hpp')
-rw-r--r--tests/test.hpp6
1 files changed, 6 insertions, 0 deletions
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__