// // Tests for // template // intrusive_shared_ptr(intrusive_shared_ptr const& other); // // intrusive_shared_ptr(intrusive_shared_ptr const& other); // #include #include #include #include #include "test_policy.h" struct Base { int i; }; struct Derived : Base { }; struct Base1 { int i; }; struct Base2 { long l; }; struct DerivedMultiple : Base1, Base2 { DerivedMultiple(int i) : Base1{i}, Base2{i + 10} { } }; struct Unrelated { }; template static void tests() { Stored obj{3}; // Test with non-null pointers { test_policy::retain_count = 0; libkern::intrusive_shared_ptr const from(&obj, libkern::retain); libkern::intrusive_shared_ptr to(from); // explicit CHECK(test_policy::retain_count == 2); CHECK(to.get() == &obj); } { test_policy::retain_count = 0; libkern::intrusive_shared_ptr const from(&obj, libkern::retain); libkern::intrusive_shared_ptr to{from}; // explicit CHECK(test_policy::retain_count == 2); CHECK(to.get() == &obj); } { test_policy::retain_count = 0; libkern::intrusive_shared_ptr const from(&obj, libkern::retain); libkern::intrusive_shared_ptr to = from; // implicit CHECK(test_policy::retain_count == 2); CHECK(to.get() == &obj); } // Test with a null pointer { test_policy::retain_count = 0; libkern::intrusive_shared_ptr const from = nullptr; libkern::intrusive_shared_ptr to = from; CHECK(test_policy::retain_count == 0); CHECK(to.get() == nullptr); } } T_DECL(ctor_copy, "intrusive_shared_ptr.ctor.copy", T_META_TAG_VM_PREFERRED) { tests(); tests(); tests(); tests(); tests(); tests(); tests(); tests(); tests(); tests(); // Make sure basic trait querying works static_assert(std::is_copy_constructible_v >); // Make sure downcasts are disabled static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr const&>); static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr const&>); static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr const&>); static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr const&>); // Make sure const-casting away doesn't work static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr const&>); // Make sure casting to unrelated types doesn't work static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr const&>); static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr const&>); static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr const&>); // Make sure constructing with different policies doesn't work static_assert(!std::is_constructible_v >, /*from*/ libkern::intrusive_shared_ptr > const &>); }