1*1b191cb5SApple OSS Distributions // 2*1b191cb5SApple OSS Distributions // Tests for 3*1b191cb5SApple OSS Distributions // ~intrusive_shared_ptr(); 4*1b191cb5SApple OSS Distributions // 5*1b191cb5SApple OSS Distributions 6*1b191cb5SApple OSS Distributions #include <libkern/c++/intrusive_shared_ptr.h> 7*1b191cb5SApple OSS Distributions #include <darwintest.h> 8*1b191cb5SApple OSS Distributions #include <darwintest_utils.h> 9*1b191cb5SApple OSS Distributions #include "test_policy.h" 10*1b191cb5SApple OSS Distributions 11*1b191cb5SApple OSS Distributions struct T { int i; }; 12*1b191cb5SApple OSS Distributions 13*1b191cb5SApple OSS Distributions T_DECL(dtor, "intrusive_shared_ptr.dtor") { 14*1b191cb5SApple OSS Distributions // Destroy a non-null shared pointer 15*1b191cb5SApple OSS Distributions { 16*1b191cb5SApple OSS Distributions T obj{0}; 17*1b191cb5SApple OSS Distributions test_policy::retain_count = 3; 18*1b191cb5SApple OSS Distributions 19*1b191cb5SApple OSS Distributions { 20*1b191cb5SApple OSS Distributions libkern::intrusive_shared_ptr<T, test_policy> ptr(&obj, libkern::no_retain); 21*1b191cb5SApple OSS Distributions CHECK(test_policy::retain_count == 3); 22*1b191cb5SApple OSS Distributions } 23*1b191cb5SApple OSS Distributions 24*1b191cb5SApple OSS Distributions CHECK(test_policy::retain_count == 2); 25*1b191cb5SApple OSS Distributions } 26*1b191cb5SApple OSS Distributions 27*1b191cb5SApple OSS Distributions // Destroy a null shared pointer 28*1b191cb5SApple OSS Distributions { 29*1b191cb5SApple OSS Distributions test_policy::retain_count = 3; 30*1b191cb5SApple OSS Distributions 31*1b191cb5SApple OSS Distributions { 32*1b191cb5SApple OSS Distributions libkern::intrusive_shared_ptr<T, test_policy> ptr = nullptr; 33*1b191cb5SApple OSS Distributions CHECK(test_policy::retain_count == 3); 34*1b191cb5SApple OSS Distributions } 35*1b191cb5SApple OSS Distributions 36*1b191cb5SApple OSS Distributions CHECK(test_policy::retain_count == 3); // not decremented 37*1b191cb5SApple OSS Distributions } 38*1b191cb5SApple OSS Distributions } 39