summaryrefslogtreecommitdiff
path: root/tests/main.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-05-09 18:23:50 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-05-09 18:23:50 +0000
commit57702ccba3d2a844adb6745458208a81e628c01e (patch)
treee1c3839ee7feba76270ce570ffb2d0958eb2acd6 /tests/main.cpp
parent464d0f4ff9e6d30be6a5ccf9da571ce8596840fd (diff)
Improved memory leak detection
git-svn-id: http://pugixml.googlecode.com/svn/trunk@398 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/main.cpp')
-rw-r--r--tests/main.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index 1aeafd2..444b188 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -11,6 +11,7 @@ jmp_buf test_runner::_failure_buffer;
const char* test_runner::_failure_message;
static size_t g_memory_total_size = 0;
+static size_t g_memory_total_count = 0;
static void* custom_allocate(size_t size)
{
@@ -21,6 +22,7 @@ static void* custom_allocate(size_t size)
void* ptr = memory_allocate(size);
g_memory_total_size += memory_size(ptr);
+ g_memory_total_count++;
return ptr;
}
@@ -31,6 +33,7 @@ static void custom_deallocate(void* ptr)
if (ptr)
{
g_memory_total_size -= memory_size(ptr);
+ g_memory_total_count--;
memory_deallocate(ptr);
}
@@ -63,6 +66,7 @@ static bool run_test(test_runner* test)
{
#endif
g_memory_total_size = 0;
+ g_memory_total_count = 0;
test_runner::_memory_fail_threshold = 0;
#ifdef _MSC_VER
@@ -84,9 +88,9 @@ static bool run_test(test_runner* test)
test->run();
- if (g_memory_total_size != 0)
+ if (g_memory_total_size != 0 || g_memory_total_count != 0)
{
- printf("Test %s failed: memory leaks found (%u bytes)\n", test->_name, (unsigned int)g_memory_total_size);
+ printf("Test %s failed: memory leaks found (%u bytes in %u allocations)\n", test->_name, (unsigned int)g_memory_total_size, (unsigned int)g_memory_total_count);
return false;
}