From 58611c87026699c6fdc4b2d2a2057b594985282c Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 13 Nov 2017 08:59:16 -0800 Subject: tests: Add compact move tests This helps make sure our error handling logic works and is exercised. --- tests/test_document.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 8b2573b..08d836c 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -1751,7 +1751,6 @@ TEST_XML(document_move_append_child_zero_alloc, "") CHECK_NODE(other, STR("")); } -#ifndef PUGIXML_COMPACT TEST(document_move_empty_zero_alloc) { xml_document* docs = new xml_document[32]; @@ -1764,9 +1763,10 @@ TEST(document_move_empty_zero_alloc) delete[] docs; } +#ifndef PUGIXML_COMPACT TEST(document_move_repeated_zero_alloc) { - xml_document* docs = new xml_document[32]; + xml_document docs[32]; CHECK(docs[0].load_string(STR(""))); @@ -1779,8 +1779,30 @@ TEST(document_move_repeated_zero_alloc) CHECK(!docs[i].first_child()); CHECK_NODE(docs[31], STR("")); +} +#endif - delete[] docs; +#ifdef PUGIXML_COMPACT +TEST(document_move_compact_fail) +{ + xml_document docs[32]; + + CHECK(docs[0].load_string(STR(""))); + + test_runner::_memory_fail_threshold = 1; + + int safe_count = 21; + + for (int i = 1; i <= safe_count; ++i) + docs[i] = std::move(docs[i-1]); + + CHECK_ALLOC_FAIL(docs[safe_count+1] = std::move(docs[safe_count])); + + for (int i = 0; i < safe_count; ++i) + CHECK(!docs[i].first_child()); + + CHECK_NODE(docs[safe_count], STR("")); + CHECK(!docs[safe_count+1].first_child()); } #endif #endif -- cgit v1.2.3