tests: Improve test coverage
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1074 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
4a7762af9d
commit
bbd75fda46
@ -1235,3 +1235,37 @@ TEST(document_alignment)
|
|||||||
doc->~xml_document();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -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)
|
for (int i = 0; i < 100; ++i)
|
||||||
copy.append_copy(doc.first_child());
|
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>"));
|
||||||
|
}
|
||||||
|
|||||||
@ -876,7 +876,7 @@ TEST(parse_out_of_memory)
|
|||||||
CHECK(!doc.first_child());
|
CHECK(!doc.first_child());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(parse_out_of_memory_halfway)
|
TEST(parse_out_of_memory_halfway_node)
|
||||||
{
|
{
|
||||||
const unsigned int count = 10000;
|
const unsigned int count = 10000;
|
||||||
static char_t text[count * 4];
|
static char_t text[count * 4];
|
||||||
@ -896,6 +896,35 @@ TEST(parse_out_of_memory_halfway)
|
|||||||
CHECK_NODE(doc.first_child(), STR("<n />"));
|
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)
|
static bool test_offset(const char_t* contents, unsigned int options, pugi::xml_parse_status status, ptrdiff_t offset)
|
||||||
{
|
{
|
||||||
xml_document doc;
|
xml_document doc;
|
||||||
|
|||||||
@ -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_BOOLEAN(doc, STR("//@attr5/following::para6"), true);
|
||||||
CHECK_XPATH_STRING(doc, STR("name(//@attr5/following::para6)"), STR("para6"));
|
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'/>")
|
TEST_XML(xpath_paths_null_nodeset_entries, "<node attr='value'/>")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user