diff options
author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-05-25 07:55:44 +0000 |
---|---|---|
committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-05-25 07:55:44 +0000 |
commit | ece914761160ed83f41e826443f96a5513eb2744 (patch) | |
tree | 2fa01adc0cd0dd6c632ab31490d72d244095b1cb /tests/test_memory.cpp | |
parent | 4e05568c4d6c2fb987a3a01020e3d450f891784e (diff) |
Changed memory management so that the document node lives inside document; this way a default-constructed document does not allocate any dynamic memory
git-svn-id: http://pugixml.googlecode.com/svn/trunk@445 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_memory.cpp')
-rw-r--r-- | tests/test_memory.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/tests/test_memory.cpp b/tests/test_memory.cpp index 269ad76..80e36c2 100644 --- a/tests/test_memory.cpp +++ b/tests/test_memory.cpp @@ -34,20 +34,31 @@ TEST(custom_memory_management) {
// parse document
xml_document doc;
+
+ CHECK(allocate_count == 0 && deallocate_count == 0);
+
CHECK(doc.load(STR("<node />")));
- CHECK(allocate_count == 2);
- CHECK(deallocate_count == 0);
+ CHECK(allocate_count == 2 && deallocate_count == 0);
+
+ // modify document (no new page)
+ CHECK(doc.first_child().set_name(STR("foobars")));
+ CHECK(allocate_count == 2 && deallocate_count == 0);
+
+ // modify document (new page)
+ std::basic_string<pugi::char_t> s(65536, 'x');
+
+ CHECK(doc.first_child().set_name(s.c_str()));
+ CHECK(allocate_count == 3 && deallocate_count == 0);
- // modify document
- doc.child(STR("node")).set_name(STR("foobars"));
+ // modify document (new page, old one should die)
+ s += s;
- CHECK(allocate_count == 2);
- CHECK(deallocate_count == 0);
+ CHECK(doc.first_child().set_name(s.c_str()));
+ CHECK(allocate_count == 4 && deallocate_count == 1);
}
- CHECK(allocate_count == 2);
- CHECK(deallocate_count == 2);
+ CHECK(allocate_count == 4 && deallocate_count == 4);
// restore old functions
set_memory_management_functions(old_allocate, old_deallocate);
@@ -67,7 +78,7 @@ TEST(large_allocations) {
xml_document doc;
- CHECK(allocate_count == 1 && deallocate_count == 0);
+ CHECK(allocate_count == 0 && deallocate_count == 0);
// initial fill
for (size_t i = 0; i < 128; ++i)
@@ -77,7 +88,7 @@ TEST(large_allocations) CHECK(doc.append_child(node_pcdata).set_value(s.c_str()));
}
- CHECK(allocate_count > 1 && deallocate_count == 0);
+ CHECK(allocate_count > 0 && deallocate_count == 0);
// grow-prune loop
while (doc.first_child())
@@ -103,12 +114,12 @@ TEST(large_allocations) }
}
- CHECK(allocate_count == deallocate_count + 2); // only two live pages left: one contains document node, another one waits for new allocations
+ CHECK(allocate_count == deallocate_count + 1); // only one live page left (it 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); // no live pages left
}
CHECK(allocate_count == deallocate_count); // everything is freed
|