From 5edeaf67658a3ab27e9ace87ccff37aba8352607 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 12 Apr 2015 21:27:12 -0700 Subject: tests: Add more out of memory tests Also add tests that verify save_file for absence of FILE leaks. --- tests/test_parse.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/test_parse.cpp') diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index 08ddee4..393e14c 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -935,6 +935,31 @@ TEST(parse_out_of_memory_conversion) CHECK(!doc.first_child()); } +TEST(parse_out_of_memory_allocator_state_sync) +{ + const unsigned int count = 10000; + static char_t text[count * 4]; + + for (unsigned int i = 0; i < count; ++i) + { + text[4*i + 0] = '<'; + text[4*i + 1] = 'n'; + text[4*i + 2] = '/'; + text[4*i + 3] = '>'; + } + + test_runner::_memory_fail_threshold = 65536; + + xml_document doc; + CHECK_ALLOC_FAIL(CHECK(doc.load_buffer_inplace(text, count * 4).status == status_out_of_memory)); + CHECK_NODE(doc.first_child(), STR("")); + + test_runner::_memory_fail_threshold = 0; + + for (unsigned int i = 0; i < count; ++i) + CHECK(doc.append_child(STR("n"))); +} + static bool test_offset(const char_t* contents, unsigned int options, pugi::xml_parse_status status, ptrdiff_t offset) { xml_document doc; -- cgit v1.2.3