2009-10-20 21:39:43 +00:00
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2010-05-06 20:28:36 +00:00
|
|
|
pugi::char_t buffer[8];
|
2009-10-20 21:39:43 +00:00
|
|
|
int allocate_count = 0;
|
|
|
|
int deallocate_count = 0;
|
|
|
|
|
|
|
|
void* allocate(size_t size)
|
|
|
|
{
|
2010-05-06 20:28:36 +00:00
|
|
|
CHECK(size == sizeof(pugi::char_t) * 8);
|
2009-10-20 21:39:43 +00:00
|
|
|
++allocate_count;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void deallocate(void* ptr)
|
|
|
|
{
|
|
|
|
CHECK(ptr == buffer);
|
|
|
|
++deallocate_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(custom_memory_management)
|
|
|
|
{
|
|
|
|
// remember old functions
|
|
|
|
allocation_function old_allocate = get_memory_allocation_function();
|
|
|
|
deallocation_function old_deallocate = get_memory_deallocation_function();
|
|
|
|
|
|
|
|
// replace functions
|
|
|
|
set_memory_management_functions(allocate, deallocate);
|
|
|
|
|
|
|
|
{
|
2009-10-29 08:11:22 +00:00
|
|
|
// parse document
|
|
|
|
xml_document doc;
|
2010-05-06 20:28:36 +00:00
|
|
|
CHECK(doc.load(STR("<node />")));
|
2009-10-20 21:39:43 +00:00
|
|
|
|
2009-10-29 08:11:22 +00:00
|
|
|
CHECK(allocate_count == 1);
|
|
|
|
CHECK(deallocate_count == 0);
|
2010-05-06 20:28:36 +00:00
|
|
|
CHECK_STRING(buffer, STR("<node"));
|
2009-10-20 21:39:43 +00:00
|
|
|
|
2009-10-29 08:11:22 +00:00
|
|
|
// modify document
|
2010-05-06 20:28:36 +00:00
|
|
|
doc.child(STR("node")).set_name(STR("foobars"));
|
2009-10-20 21:39:43 +00:00
|
|
|
|
|
|
|
CHECK(allocate_count == 2);
|
2009-10-29 08:11:22 +00:00
|
|
|
CHECK(deallocate_count == 0);
|
2010-05-06 20:28:36 +00:00
|
|
|
CHECK_STRING(buffer, STR("foobars"));
|
2009-10-20 21:39:43 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 08:11:22 +00:00
|
|
|
CHECK(allocate_count == 2);
|
|
|
|
CHECK(deallocate_count == 2);
|
2010-05-06 20:28:36 +00:00
|
|
|
CHECK_STRING(buffer, STR("foobars"));
|
2009-10-29 08:11:22 +00:00
|
|
|
|
|
|
|
// restore old functions
|
|
|
|
set_memory_management_functions(old_allocate, old_deallocate);
|
2009-10-20 21:39:43 +00:00
|
|
|
}
|