summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-29 15:17:30 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-29 15:17:30 +0000
commit40e6900b0feec0a39f9b71f3e5bacb82b20d0259 (patch)
tree02dcddbbe06ea82c3b1dbb8f30b0b52398430b6b /tests
parent1f74bf1edcae00bd33a2ecbcd9838b4d98f810b2 (diff)
tests: Added more string allocation tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@652 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r--tests/test_memory.cpp111
1 files changed, 109 insertions, 2 deletions
diff --git a/tests/test_memory.cpp b/tests/test_memory.cpp
index 8b4b6bc..b7a5577 100644
--- a/tests/test_memory.cpp
+++ b/tests/test_memory.cpp
@@ -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");
+}