#include #include "weak_ptr.h" Y_UNIT_TEST_SUITE(TWeakPtrTest) { struct TWeakPtrTester: public TWeakRefCounted { int* const CounterPtr; TWeakPtrTester(int* counterPtr) : CounterPtr(counterPtr) { } ~TWeakPtrTester() { ++*CounterPtr; } }; Y_UNIT_TEST(Simple) { int destroyCount = 0; TIntrusivePtr p(new TWeakPtrTester(&destroyCount)); UNIT_ASSERT(!!p); UNIT_ASSERT_VALUES_EQUAL(1u, p->RefCount()); TWeakPtr p2(p); UNIT_ASSERT_VALUES_EQUAL(1u, p->RefCount()); { TIntrusivePtr p3 = p2.Get(); UNIT_ASSERT(!!p3); UNIT_ASSERT_VALUES_EQUAL(2u, p->RefCount()); } p.Drop(); UNIT_ASSERT_VALUES_EQUAL(1, destroyCount); { TIntrusivePtr p3 = p2.Get(); UNIT_ASSERT(!p3); } UNIT_ASSERT_VALUES_EQUAL(1, destroyCount); } }