summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2017-11-13 08:59:16 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2017-11-13 08:59:16 -0800
commit58611c87026699c6fdc4b2d2a2057b594985282c (patch)
treeb1d0cd46b09de6c920eabfe8d5efb2a23f775bc5
parent4bd8771c2fffe6d81ae053e9570b0b53033b0c82 (diff)
tests: Add compact move tests
This helps make sure our error handling logic works and is exercised.
-rw-r--r--tests/test_document.cpp28
1 files changed, 25 insertions, 3 deletions
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, "<node1/><node2/>")
CHECK_NODE(other, STR("<node1/><node2/><node3/>"));
}
-#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("<node><child/></node>")));
@@ -1779,8 +1779,30 @@ TEST(document_move_repeated_zero_alloc)
CHECK(!docs[i].first_child());
CHECK_NODE(docs[31], STR("<node><child/></node>"));
+}
+#endif
- delete[] docs;
+#ifdef PUGIXML_COMPACT
+TEST(document_move_compact_fail)
+{
+ xml_document docs[32];
+
+ CHECK(docs[0].load_string(STR("<node><child/></node>")));
+
+ 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("<node><child/></node>"));
+ CHECK(!docs[safe_count+1].first_child());
}
#endif
#endif