// // Tests for // template // intrusive_shared_ptr const_pointer_cast(intrusive_shared_ptr const& ptr) noexcept; // // template // intrusive_shared_ptr const_pointer_cast(intrusive_shared_ptr&& ptr) noexcept // #include #include #include #include "test_policy.h" struct T { int i; }; template static void tests() { Stored obj{3}; { tracked_shared_ptr const from(&obj, libkern::no_retain); tracking_policy::reset(); tracked_shared_ptr to = libkern::const_pointer_cast(from); CHECK(tracking_policy::retains == 1); CHECK(tracking_policy::releases == 0); CHECK(to.get() == const_cast(&obj)); CHECK(from.get() == &obj); } { tracked_shared_ptr from(&obj, libkern::no_retain); tracking_policy::reset(); tracked_shared_ptr to = libkern::const_pointer_cast(std::move(from)); CHECK(tracking_policy::retains == 0); CHECK(tracking_policy::releases == 0); CHECK(to.get() == const_cast(&obj)); CHECK(from.get() == nullptr); } // Test `const_pointer_cast`ing a null pointer { tracked_shared_ptr const from = nullptr; tracking_policy::reset(); tracked_shared_ptr to = libkern::const_pointer_cast(from); CHECK(tracking_policy::retains == 0); CHECK(tracking_policy::releases == 0); CHECK(to.get() == nullptr); CHECK(from.get() == nullptr); } { tracked_shared_ptr from = nullptr; tracking_policy::reset(); tracked_shared_ptr to = libkern::const_pointer_cast(std::move(from)); CHECK(tracking_policy::retains == 0); CHECK(tracking_policy::releases == 0); CHECK(to.get() == nullptr); CHECK(from.get() == nullptr); } } T_DECL(cast_const, "intrusive_shared_ptr.cast.const", T_META_TAG_VM_PREFERRED) { tests(); tests(); tests(); }