tests: Add a way for tests to verify allocation failure
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1081 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
0b7964917c
commit
0e59ea8234
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
test_runner* test_runner::_tests = 0;
|
test_runner* test_runner::_tests = 0;
|
||||||
size_t test_runner::_memory_fail_threshold = 0;
|
size_t test_runner::_memory_fail_threshold = 0;
|
||||||
|
bool test_runner::_memory_fail_triggered = false;
|
||||||
jmp_buf test_runner::_failure_buffer;
|
jmp_buf test_runner::_failure_buffer;
|
||||||
const char* test_runner::_failure_message;
|
const char* test_runner::_failure_message;
|
||||||
const char* test_runner::_temp_path;
|
const char* test_runner::_temp_path;
|
||||||
@ -30,7 +31,11 @@ static size_t g_memory_total_count = 0;
|
|||||||
static void* custom_allocate(size_t size)
|
static void* custom_allocate(size_t size)
|
||||||
{
|
{
|
||||||
if (test_runner::_memory_fail_threshold > 0 && test_runner::_memory_fail_threshold < g_memory_total_size + size)
|
if (test_runner::_memory_fail_threshold > 0 && test_runner::_memory_fail_threshold < g_memory_total_size + size)
|
||||||
|
{
|
||||||
|
test_runner::_memory_fail_triggered = true;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
void* ptr = memory_allocate(size);
|
void* ptr = memory_allocate(size);
|
||||||
@ -84,6 +89,7 @@ static bool run_test(test_runner* test)
|
|||||||
g_memory_total_size = 0;
|
g_memory_total_size = 0;
|
||||||
g_memory_total_count = 0;
|
g_memory_total_count = 0;
|
||||||
test_runner::_memory_fail_threshold = 0;
|
test_runner::_memory_fail_threshold = 0;
|
||||||
|
test_runner::_memory_fail_triggered = false;
|
||||||
|
|
||||||
pugi::set_memory_management_functions(custom_allocate, custom_deallocate);
|
pugi::set_memory_management_functions(custom_allocate, custom_deallocate);
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ struct test_runner
|
|||||||
|
|
||||||
static test_runner* _tests;
|
static test_runner* _tests;
|
||||||
static size_t _memory_fail_threshold;
|
static size_t _memory_fail_threshold;
|
||||||
|
static bool _memory_fail_triggered;
|
||||||
static jmp_buf _failure_buffer;
|
static jmp_buf _failure_buffer;
|
||||||
static const char* _failure_message;
|
static const char* _failure_message;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user