Added test that checks for correct page deallocation policy
git-svn-id: http://pugixml.googlecode.com/svn/trunk@408 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
b47b4905a6
commit
55f3cba20c
@ -22,6 +22,8 @@ namespace
|
||||
|
||||
TEST(custom_memory_management)
|
||||
{
|
||||
allocate_count = deallocate_count = 0;
|
||||
|
||||
// remember old functions
|
||||
allocation_function old_allocate = get_memory_allocation_function();
|
||||
deallocation_function old_deallocate = get_memory_deallocation_function();
|
||||
@ -52,9 +54,21 @@ TEST(custom_memory_management)
|
||||
}
|
||||
|
||||
TEST(large_allocations)
|
||||
{
|
||||
allocate_count = deallocate_count = 0;
|
||||
|
||||
// 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);
|
||||
|
||||
{
|
||||
xml_document doc;
|
||||
|
||||
CHECK(allocate_count == 1 && deallocate_count == 0);
|
||||
|
||||
// initial fill
|
||||
for (size_t i = 0; i < 128; ++i)
|
||||
{
|
||||
@ -63,6 +77,8 @@ TEST(large_allocations)
|
||||
CHECK(doc.append_child(node_pcdata).set_value(s.c_str()));
|
||||
}
|
||||
|
||||
CHECK(allocate_count > 1 && deallocate_count == 0);
|
||||
|
||||
// grow-prune loop
|
||||
while (doc.first_child())
|
||||
{
|
||||
@ -86,4 +102,17 @@ TEST(large_allocations)
|
||||
node = next;
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(allocate_count == deallocate_count + 2); // only two live pages left: one contains document node, another one waits for new allocations
|
||||
|
||||
char buffer;
|
||||
CHECK(doc.load_buffer_inplace(&buffer, 0, parse_default, get_native_encoding()));
|
||||
|
||||
CHECK(allocate_count == deallocate_count + 1); // only one live page left (it contains document node)
|
||||
}
|
||||
|
||||
CHECK(allocate_count == deallocate_count); // everything is freed
|
||||
|
||||
// restore old functions
|
||||
set_memory_management_functions(old_allocate, old_deallocate);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user