tests: Added more string allocation tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@652 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
1f74bf1edc
commit
40e6900b0f
@ -1,5 +1,7 @@
|
||||
#include "common.hpp"
|
||||
|
||||
#include "writer_string.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
@ -20,7 +22,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
TEST(custom_memory_management)
|
||||
TEST(memory_custom_memory_management)
|
||||
{
|
||||
allocate_count = deallocate_count = 0;
|
||||
|
||||
@ -64,7 +66,7 @@ TEST(custom_memory_management)
|
||||
set_memory_management_functions(old_allocate, old_deallocate);
|
||||
}
|
||||
|
||||
TEST(large_allocations)
|
||||
TEST(memory_large_allocations)
|
||||
{
|
||||
allocate_count = deallocate_count = 0;
|
||||
|
||||
@ -127,3 +129,108 @@ TEST(large_allocations)
|
||||
// restore old functions
|
||||
set_memory_management_functions(old_allocate, old_deallocate);
|
||||
}
|
||||
|
||||
TEST(memory_string_allocate_increasing)
|
||||
{
|
||||
xml_document doc;
|
||||
|
||||
doc.append_child(node_pcdata).set_value(STR("x"));
|
||||
|
||||
std::basic_string<char_t> s = STR("ab");
|
||||
|
||||
for (int i = 0; i < 17; ++i)
|
||||
{
|
||||
doc.append_child(node_pcdata).set_value(s.c_str());
|
||||
|
||||
s += s;
|
||||
}
|
||||
|
||||
std::string result = save_narrow(doc, format_no_declaration | format_raw, encoding_utf8);
|
||||
|
||||
CHECK(result.size() == 262143);
|
||||
CHECK(result[0] == 'x');
|
||||
|
||||
for (size_t j = 1; j < result.size(); ++j)
|
||||
{
|
||||
CHECK(result[j] == (j % 2 ? 'a' : 'b'));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(memory_string_allocate_decreasing)
|
||||
{
|
||||
xml_document doc;
|
||||
|
||||
std::basic_string<char_t> s = STR("ab");
|
||||
|
||||
for (int i = 0; i < 17; ++i) s += s;
|
||||
|
||||
for (int i = 0; i < 17; ++i)
|
||||
{
|
||||
s.resize(s.size() / 2);
|
||||
|
||||
doc.append_child(node_pcdata).set_value(s.c_str());
|
||||
}
|
||||
|
||||
doc.append_child(node_pcdata).set_value(STR("x"));
|
||||
|
||||
std::string result = save_narrow(doc, format_no_declaration | format_raw, encoding_utf8);
|
||||
|
||||
CHECK(result.size() == 262143);
|
||||
CHECK(result[result.size() - 1] == 'x');
|
||||
|
||||
for (size_t j = 0; j + 1 < result.size(); ++j)
|
||||
{
|
||||
CHECK(result[j] == (j % 2 ? 'b' : 'a'));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(memory_string_allocate_increasing_inplace)
|
||||
{
|
||||
xml_document doc;
|
||||
|
||||
xml_node node = doc.append_child(node_pcdata);
|
||||
|
||||
node.set_value(STR("x"));
|
||||
|
||||
std::basic_string<char_t> s = STR("ab");
|
||||
|
||||
for (int i = 0; i < 17; ++i)
|
||||
{
|
||||
node.set_value(s.c_str());
|
||||
|
||||
s += s;
|
||||
}
|
||||
|
||||
std::string result = save_narrow(doc, format_no_declaration | format_raw, encoding_utf8);
|
||||
|
||||
CHECK(result.size() == 131072);
|
||||
|
||||
for (size_t j = 0; j < result.size(); ++j)
|
||||
{
|
||||
CHECK(result[j] == (j % 2 ? 'b' : 'a'));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(memory_string_allocate_decreasing_inplace)
|
||||
{
|
||||
xml_document doc;
|
||||
|
||||
xml_node node = doc.append_child(node_pcdata);
|
||||
|
||||
std::basic_string<char_t> s = STR("ab");
|
||||
|
||||
for (int i = 0; i < 17; ++i) s += s;
|
||||
|
||||
for (int i = 0; i < 17; ++i)
|
||||
{
|
||||
s.resize(s.size() / 2);
|
||||
|
||||
node.set_value(s.c_str());
|
||||
}
|
||||
|
||||
node.set_value(STR("x"));
|
||||
|
||||
std::string result = save_narrow(doc, format_no_declaration | format_raw, encoding_utf8);
|
||||
|
||||
CHECK(result == "x");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user