From faba4786c077f32ca57d48895c058b6894836cfc Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 25 Sep 2017 22:38:30 -0700 Subject: tests: Add more document move tests Verify that move doesn't allocate and that it preserves structures required for tree memory management and append_buffer in tact. --- tests/test_document.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'tests') diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 43d3906..c2f55a7 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -1651,4 +1651,56 @@ TEST_XML(document_move_assign, "") CHECK_STRING(other.last_child().name(), STR("node2")); CHECK(other.last_child().parent() == other); } + +TEST_XML(document_move_zero_alloc, "") +{ + test_runner::_memory_fail_threshold = 1; + + xml_document other = std::move(doc); + + CHECK(doc.first_child().empty()); + + CHECK_STRING(other.first_child().name(), STR("node1")); + CHECK(other.first_child().parent() == other); + + CHECK_STRING(other.last_child().name(), STR("node2")); + CHECK(other.last_child().parent() == other); +} + +TEST(document_move_append_buffer) +{ + xml_document* doc = new xml_document(); + CHECK(doc->load_string(STR(""))); + CHECK(doc->child(STR("node1")).append_buffer("", 8)); + CHECK(doc->child(STR("node1")).append_buffer("", 8)); + + xml_document other = std::move(*doc); + delete doc; + + CHECK(other.child(STR("node1")).append_buffer("", 8)); + CHECK(other.child(STR("node1")).append_buffer("", 8)); + + CHECK_NODE(other, STR("")); +} + +TEST(document_move_append_child) +{ + xml_document* doc = new xml_document(); + CHECK(doc->load_string(STR(""))); + + xml_document other = std::move(*doc); + delete doc; + + for (int i = 0; i < 1000; ++i) + other.child(STR("node1")).append_child(STR("node")); + + for (int i = 0; i < 1000; ++i) + other.child(STR("node1")).remove_child(other.child(STR("node1")).last_child()); + + CHECK_NODE(other, STR("")); + + other.remove_child(other.first_child()); + + CHECK(!other.first_child()); +} #endif -- cgit v1.2.3