mirror of
https://github.com/zeux/pugixml.git
synced 2024-12-26 21:04:25 +08:00
tests: Add more out of memory tests
This provides more coverage for #17.
This commit is contained in:
parent
405fefc877
commit
29fef9aca2
@ -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"));
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user