summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-03 12:19:13 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-03 12:19:13 +0000
commit724cb46a72f6a7b3bf972aa360229adde66ea7f2 (patch)
treeb22662b62d9a8100d17d268ec6fe7fe65758de11 /tests
parent1b4123af9e105f430b45bca09749cb5fb998e929 (diff)
tests: New and delete operators now use test allocator and thus are subject to leak detection and memory threshold failure
git-svn-id: http://pugixml.googlecode.com/svn/trunk@624 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r--tests/main.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index 021c253..03ad2f5 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -1,6 +1,7 @@
#include "test.hpp"
#include "allocator.hpp"
+#include <new>
#include <exception>
#include <stdio.h>
#include <float.h>
@@ -51,6 +52,60 @@ static void replace_memory_management()
pugi::set_memory_management_functions(custom_allocate, custom_deallocate);
}
+#ifdef __GNUC__
+#define DECL_THROW(e) throw(e)
+#define DECL_NOTHROW() throw()
+#else
+#define DECL_THROW(e)
+#define DECL_NOTHROW()
+#endif
+
+void* operator new(size_t size) DECL_THROW(std::bad_alloc)
+{
+ void* result = custom_allocate(size);
+
+#ifndef PUGIXML_NO_EXCEPTIONS
+ if (!result) throw std::bad_alloc();
+#endif
+
+ return result;
+}
+
+void* operator new[](size_t size) DECL_THROW(std::bad_alloc)
+{
+ return operator new(size);
+}
+
+void* operator new(size_t size, const std::nothrow_t&) throw()
+{
+ return custom_allocate(size);
+}
+
+void* operator new[](size_t size, const std::nothrow_t&) throw()
+{
+ return custom_allocate(size);
+}
+
+void operator delete(void* ptr) DECL_NOTHROW()
+{
+ custom_deallocate(ptr);
+}
+
+void operator delete[](void* ptr) DECL_NOTHROW()
+{
+ custom_deallocate(ptr);
+}
+
+void operator delete(void* ptr, const std::nothrow_t&) throw()
+{
+ custom_deallocate(ptr);
+}
+
+void operator delete[](void* ptr, const std::nothrow_t&) throw()
+{
+ custom_deallocate(ptr);
+}
+
#if defined(_MSC_VER) && _MSC_VER > 1200 && _MSC_VER < 1400 && !defined(__INTEL_COMPILER) && !defined(__DMC__)
namespace std
{