// // Tests for // safe_allocation(safe_allocation&& other); // #include #include #include "test_utils.h" #include struct T { int i; }; template static void tests() { // Move-construct from a non-null allocation (with different syntaxes) { { tracked_safe_allocation from(10, libkern::allocate_memory); tracking_allocator::reset(); T* memory = from.data(); { tracked_safe_allocation to(std::move(from)); CHECK(!tracking_allocator::did_allocate); CHECK(to.data() == memory); CHECK(to.size() == 10); CHECK(from.data() == nullptr); CHECK(from.size() == 0); } CHECK(tracking_allocator::did_deallocate); tracking_allocator::reset(); } CHECK(!tracking_allocator::did_deallocate); } { { tracked_safe_allocation from(10, libkern::allocate_memory); tracking_allocator::reset(); T* memory = from.data(); { tracked_safe_allocation to{std::move(from)}; CHECK(!tracking_allocator::did_allocate); CHECK(to.data() == memory); CHECK(to.size() == 10); CHECK(from.data() == nullptr); CHECK(from.size() == 0); } CHECK(tracking_allocator::did_deallocate); tracking_allocator::reset(); } CHECK(!tracking_allocator::did_deallocate); } { { tracked_safe_allocation from(10, libkern::allocate_memory); tracking_allocator::reset(); T* memory = from.data(); { tracked_safe_allocation to = std::move(from); CHECK(!tracking_allocator::did_allocate); CHECK(to.data() == memory); CHECK(to.size() == 10); CHECK(from.data() == nullptr); CHECK(from.size() == 0); } CHECK(tracking_allocator::did_deallocate); tracking_allocator::reset(); } CHECK(!tracking_allocator::did_deallocate); } // Move-construct from a null allocation { { tracked_safe_allocation from = nullptr; tracking_allocator::reset(); { tracked_safe_allocation to(std::move(from)); CHECK(!tracking_allocator::did_allocate); CHECK(to.data() == nullptr); CHECK(to.size() == 0); CHECK(from.data() == nullptr); CHECK(from.size() == 0); } CHECK(!tracking_allocator::did_deallocate); tracking_allocator::reset(); } CHECK(!tracking_allocator::did_deallocate); } } T_DECL(ctor_move, "safe_allocation.ctor.move", T_META_TAG_VM_PREFERRED) { tests(); tests(); }