summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_document.cpp34
-rw-r--r--tests/test_dom_modify.cpp35
-rw-r--r--tests/test_parse.cpp31
-rw-r--r--tests/test_xpath_paths.cpp3
4 files changed, 102 insertions, 1 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp
index c75ed8f..c76f671 100644
--- a/tests/test_document.cpp
+++ b/tests/test_document.cpp
@@ -1235,3 +1235,37 @@ TEST(document_alignment)
doc->~xml_document();
}
}
+
+TEST(document_convert_out_of_memory)
+{
+ file_data_t files[] =
+ {
+ {"tests/data/utftest_utf16_be_clean.xml", encoding_utf16_be, 0, 0},
+ {"tests/data/utftest_utf16_le_clean.xml", encoding_utf16_le, 0, 0},
+ {"tests/data/utftest_utf32_be_clean.xml", encoding_utf32_be, 0, 0},
+ {"tests/data/utftest_utf32_le_clean.xml", encoding_utf32_le, 0, 0},
+ {"tests/data/utftest_utf8_clean.xml", encoding_utf8, 0, 0},
+ {"tests/data/latintest_latin1.xml", encoding_latin1, 0, 0}
+ };
+
+ // load files in memory
+ for (unsigned int i = 0; i < sizeof(files) / sizeof(files[0]); ++i)
+ {
+ CHECK(load_file_in_memory(files[i].path, files[i].data, files[i].size));
+ }
+
+ // disallow allocations
+ test_runner::_memory_fail_threshold = 1;
+
+ for (unsigned int src = 0; src < sizeof(files) / sizeof(files[0]); ++src)
+ {
+ xml_document doc;
+ CHECK(doc.load_buffer(files[src].data, files[src].size, parse_default, files[src].encoding).status == status_out_of_memory);
+ }
+
+ // cleanup
+ for (unsigned int j = 0; j < sizeof(files) / sizeof(files[0]); ++j)
+ {
+ delete[] files[j].data;
+ }
+}
diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp
index 612b017..5f4e26c 100644
--- a/tests/test_dom_modify.cpp
+++ b/tests/test_dom_modify.cpp
@@ -1354,3 +1354,38 @@ TEST_XML(dom_node_copy_out_of_memory, "<node><child1 attr1='value1' attr2='value
for (int i = 0; i < 100; ++i)
copy.append_copy(doc.first_child());
}
+
+TEST_XML(dom_node_remove_deallocate, "<node attr='value'>text</node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ xml_attribute attr = node.attribute(STR("attr"));
+ attr.set_name(STR("longattr"));
+ attr.set_value(STR("longvalue"));
+
+ node.set_name(STR("longnode"));
+ node.text().set(STR("longtext"));
+
+ node.remove_attribute(attr);
+ doc.remove_child(node);
+
+ CHECK_NODE(doc, STR(""));
+}
+
+TEST_XML(dom_node_set_deallocate, "<node attr='value'>text</node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ xml_attribute attr = node.attribute(STR("attr"));
+
+ attr.set_name(STR("longattr"));
+ attr.set_value(STR("longvalue"));
+ node.set_name(STR("longnode"));
+
+ attr.set_name(STR(""));
+ attr.set_value(STR(""));
+ node.set_name(STR(""));
+ node.text().set(STR(""));
+
+ CHECK_NODE(doc, STR("<:anonymous :anonymous=\"\"></:anonymous>"));
+}
diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp
index 2094ef9..444a0fb 100644
--- a/tests/test_parse.cpp
+++ b/tests/test_parse.cpp
@@ -876,7 +876,7 @@ TEST(parse_out_of_memory)
CHECK(!doc.first_child());
}
-TEST(parse_out_of_memory_halfway)
+TEST(parse_out_of_memory_halfway_node)
{
const unsigned int count = 10000;
static char_t text[count * 4];
@@ -896,6 +896,35 @@ TEST(parse_out_of_memory_halfway)
CHECK_NODE(doc.first_child(), STR("<n />"));
}
+TEST(parse_out_of_memory_halfway_attr)
+{
+ const unsigned int count = 10000;
+ static char_t text[count * 5 + 4];
+
+ text[0] = '<';
+ text[1] = 'n';
+
+ for (unsigned int i = 0; i < count; ++i)
+ {
+ text[5*i + 2] = ' ';
+ text[5*i + 3] = 'a';
+ text[5*i + 4] = '=';
+ text[5*i + 5] = '"';
+ text[5*i + 6] = '"';
+ }
+
+ text[5 * count + 2] = '/';
+ text[5 * count + 3] = '>';
+
+ test_runner::_memory_fail_threshold = 65536;
+
+ xml_document doc;
+ CHECK(doc.load_buffer_inplace(text, count * 5 + 4).status == status_out_of_memory);
+ CHECK_STRING(doc.first_child().name(), STR("n"));
+ CHECK_STRING(doc.first_child().first_attribute().name(), STR("a"));
+ CHECK_STRING(doc.first_child().last_attribute().name(), STR("a"));
+}
+
static bool test_offset(const char_t* contents, unsigned int options, pugi::xml_parse_status status, ptrdiff_t offset)
{
xml_document doc;
diff --git a/tests/test_xpath_paths.cpp b/tests/test_xpath_paths.cpp
index da8811d..ee2401a 100644
--- a/tests/test_xpath_paths.cpp
+++ b/tests/test_xpath_paths.cpp
@@ -615,6 +615,9 @@ TEST_XML(xpath_paths_optimize_step_once, "<node><para1><para2/><para3/><para4><p
CHECK_XPATH_BOOLEAN(doc, STR("//@attr5/following::para6"), true);
CHECK_XPATH_STRING(doc, STR("name(//@attr5/following::para6)"), STR("para6"));
+
+ CHECK_XPATH_BOOLEAN(doc, STR("//para5/ancestor-or-self::*"), true);
+ CHECK_XPATH_BOOLEAN(doc, STR("//para5/ancestor::*"), true);
}
TEST_XML(xpath_paths_null_nodeset_entries, "<node attr='value'/>")