diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-10-23 07:41:07 +0000 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-10-23 07:41:07 +0000 |
commit | 903db8682a5f14b52adec996584c70ea072619ea (patch) | |
tree | b65c4c8bb68d7d0d77a204ca850c2d85bf7a5a6e /tests/test_document.cpp | |
parent | bbd75fda4618dcbef272c8e5432153992c392588 (diff) |
tests: Add more tests for better coverage
More tests for out-of-memory and other edge conditions
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1075 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_document.cpp')
-rw-r--r-- | tests/test_document.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp index c76f671..2cc39a6 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -227,6 +227,34 @@ TEST(document_load_stream_nonseekable_large) CHECK(doc.load(in)); CHECK_NODE(doc, str.c_str()); } + +TEST(document_load_stream_nonseekable_out_of_memory) +{ + char contents[] = "<node />"; + char_array_buffer<char> buffer(contents, contents + sizeof(contents) / sizeof(contents[0])); + std::istream in(&buffer); + + test_runner::_memory_fail_threshold = 1; + + pugi::xml_document doc; + CHECK(doc.load(in).status == status_out_of_memory); +} + +TEST(document_load_stream_nonseekable_out_of_memory_large) +{ + std::basic_string<pugi::char_t> str; + str += STR("<node>"); + for (int i = 0; i < 10000; ++i) str += STR("<node />"); + str += STR("</node>"); + + char_array_buffer<pugi::char_t> buffer(&str[0], &str[0] + str.length()); + std::basic_istream<pugi::char_t> in(&buffer); + + test_runner::_memory_fail_threshold = 10000 * 8 * 3 / 2; + + pugi::xml_document doc; + CHECK(doc.load(in).status == status_out_of_memory); +} #endif TEST(document_load_string) @@ -295,6 +323,17 @@ TEST(document_load_file_wide_ascii) CHECK_NODE(doc, STR("<node />")); } +TEST(document_load_file_wide_out_of_memory) +{ + test_runner::_memory_fail_threshold = 1; + + pugi::xml_document doc; + + pugi::xml_parse_result result = doc.load_file(L"tests/data/small.xml"); + + CHECK(result.status == status_out_of_memory || result.status == status_file_not_found); +} + TEST_XML(document_save, "<node/>") { xml_writer_string writer; |