From f542c5ebb8068ccd4f9176684eb62183afbe7e5c Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Thu, 6 May 2010 20:28:36 +0000 Subject: Integrated changes from unicode branch to trunk git-svn-id: http://pugixml.googlecode.com/svn/trunk@383 99668b35-9821-0410-8761-19e4c4f06640 --- tests/main.cpp | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'tests/main.cpp') 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 #include - -#include -#include +#include 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 -- cgit v1.2.3