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_document.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'tests/test_document.cpp') diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 1545e19..9c8c860 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -319,9 +319,7 @@ TEST(document_load_file_out_of_memory_file_leak) pugi::xml_document doc; for (int i = 0; i < 256; ++i) - { CHECK_ALLOC_FAIL(CHECK(doc.load_file("tests/data/small.xml").status == status_out_of_memory)); - } test_runner::_memory_fail_threshold = 0; @@ -329,6 +327,21 @@ TEST(document_load_file_out_of_memory_file_leak) CHECK_NODE(doc, STR("")); } +TEST(document_load_file_wide_out_of_memory_file_leak) +{ + test_runner::_memory_fail_threshold = 256; + + pugi::xml_document doc; + + for (int i = 0; i < 256; ++i) + CHECK_ALLOC_FAIL(CHECK(doc.load_file(L"tests/data/small.xml").status == status_out_of_memory)); + + test_runner::_memory_fail_threshold = 0; + + CHECK(doc.load_file(L"tests/data/small.xml")); + CHECK_NODE(doc, STR("")); +} + TEST(document_load_file_error_previous) { pugi::xml_document doc; @@ -556,6 +569,26 @@ TEST_XML(document_save_file_wide_text, "") CHECK(test_file_contents(f.path, "\n", 9)); } +TEST_XML(document_save_file_leak, "") +{ + temp_file f; + + for (int i = 0; i < 256; ++i) + CHECK(doc.save_file(f.path)); +} + +TEST_XML(document_save_file_wide_leak, "") +{ + temp_file f; + + // widen the path + wchar_t wpath[sizeof(f.path)]; + std::copy(f.path, f.path + strlen(f.path) + 1, wpath + 0); + + for (int i = 0; i < 256; ++i) + CHECK(doc.save_file(wpath)); +} + TEST(document_load_buffer) { const pugi::char_t text[] = STR(""); -- cgit v1.2.3