summaryrefslogtreecommitdiff
path: root/tests/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/main.cpp')
-rw-r--r--tests/main.cpp35
1 files changed, 16 insertions, 19 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index f283dcf..1aeafd2 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -1,33 +1,26 @@
#include "test.hpp"
+#include "allocator.hpp"
#include <exception>
#include <stdio.h>
-
-#include <stdlib.h>
-#include <malloc.h>
+#include <float.h>
test_runner* test_runner::_tests = 0;
size_t test_runner::_memory_fail_threshold = 0;
-jmp_buf test_runner::_failure;
+jmp_buf test_runner::_failure_buffer;
+const char* test_runner::_failure_message;
static size_t g_memory_total_size = 0;
-#ifdef __linux
-size_t _msize(void* ptr)
-{
- return malloc_usable_size(ptr);
-}
-#endif
-
static void* custom_allocate(size_t size)
{
if (test_runner::_memory_fail_threshold > 0 && test_runner::_memory_fail_threshold < size)
return 0;
else
{
- void* ptr = malloc(size);
+ void* ptr = memory_allocate(size);
- g_memory_total_size += _msize(ptr);
+ g_memory_total_size += memory_size(ptr);
return ptr;
}
@@ -37,9 +30,9 @@ static void custom_deallocate(void* ptr)
{
if (ptr)
{
- g_memory_total_size -= _msize(ptr);
+ g_memory_total_size -= memory_size(ptr);
- free(ptr);
+ memory_deallocate(ptr);
}
}
@@ -48,7 +41,7 @@ static void replace_memory_management()
// create some document to touch original functions
{
pugi::xml_document doc;
- doc.append_child().set_name("node");
+ doc.append_child().set_name(STR("node"));
}
// replace functions
@@ -77,7 +70,7 @@ static bool run_test(test_runner* test)
# pragma warning(disable: 4611) // interaction between _setjmp and C++ object destruction is non-portable
#endif
- volatile int result = setjmp(test_runner::_failure);
+ volatile int result = setjmp(test_runner::_failure_buffer);
#ifdef _MSC_VER
# pragma warning(pop)
@@ -85,13 +78,17 @@ static bool run_test(test_runner* test)
if (result)
{
- printf("Test %s failed: %s\n", test->_name, (const char*)(intptr_t)result);
+ printf("Test %s failed: %s\n", test->_name, test_runner::_failure_message);
return false;
}
test->run();
- if (g_memory_total_size != 0) longjmp(test_runner::_failure, (int)(intptr_t)"Memory leaks found");
+ if (g_memory_total_size != 0)
+ {
+ printf("Test %s failed: memory leaks found (%u bytes)\n", test->_name, (unsigned int)g_memory_total_size);
+ return false;
+ }
return true;
#ifndef PUGIXML_NO_EXCEPTIONS