summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_dom_modify.cpp36
-rw-r--r--tests/test_parse.cpp9
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp
index fa50112..8610a74 100644
--- a/tests/test_dom_modify.cpp
+++ b/tests/test_dom_modify.cpp
@@ -1100,6 +1100,42 @@ TEST(dom_node_append_buffer_out_of_memory_buffer)
CHECK(!doc.first_child());
}
+TEST(dom_node_append_buffer_out_of_memory_nodes)
+{
+ unsigned int count = 4000;
+ std::basic_string<char_t> data;
+
+ for (unsigned int i = 0; i < count; ++i)
+ data += STR("<a/>");
+
+ test_runner::_memory_fail_threshold = 32768 + 128 + data.length() * sizeof(wchar_t) + 32;
+
+ xml_document doc;
+ CHECK(doc.append_buffer(data.c_str(), data.length() * sizeof(wchar_t), parse_fragment).status == status_out_of_memory);
+
+ unsigned int valid = 0;
+
+ for (xml_node n = doc.first_child(); n; n = n.next_sibling())
+ {
+ CHECK_STRING(n.name(), STR("a"));
+ valid++;
+ }
+
+ CHECK(valid > 0 && valid < count);
+}
+
+TEST(dom_node_append_buffer_out_of_memory_name)
+{
+ test_runner::_memory_fail_threshold = 32768 + 128;
+
+ char data[128] = {0};
+
+ xml_document doc;
+ CHECK(doc.append_child(STR("root")));
+ CHECK(doc.first_child().append_buffer(data, sizeof(data)).status == status_out_of_memory);
+ CHECK_STRING(doc.first_child().name(), STR("root"));
+}
+
TEST_XML(dom_node_append_buffer_fragment, "<node />")
{
xml_node node = doc.child(STR("node"));
diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp
index 7bb2663..3ae96d1 100644
--- a/tests/test_parse.cpp
+++ b/tests/test_parse.cpp
@@ -926,6 +926,15 @@ TEST(parse_out_of_memory_halfway_attr)
CHECK_STRING(doc.first_child().last_attribute().name(), STR("a"));
}
+TEST(parse_out_of_memory_conversion)
+{
+ test_runner::_memory_fail_threshold = 256;
+
+ xml_document doc;
+ CHECK(doc.load_buffer("<foo\x90/>", 7, parse_default, encoding_latin1).status == status_out_of_memory);
+ CHECK(!doc.first_child());
+}
+
static bool test_offset(const char_t* contents, unsigned int options, pugi::xml_parse_status status, ptrdiff_t offset)
{
xml_document doc;