1*2c2f96dcSApple OSS Distributions // 2*2c2f96dcSApple OSS Distributions // Tests for 3*2c2f96dcSApple OSS Distributions // intrusive_shared_ptr& operator=(std::nullptr_t); 4*2c2f96dcSApple OSS Distributions // 5*2c2f96dcSApple OSS Distributions 6*2c2f96dcSApple OSS Distributions #include <libkern/c++/intrusive_shared_ptr.h> 7*2c2f96dcSApple OSS Distributions #include <darwintest.h> 8*2c2f96dcSApple OSS Distributions #include "test_policy.h" 9*2c2f96dcSApple OSS Distributions 10*2c2f96dcSApple OSS Distributions struct T { 11*2c2f96dcSApple OSS Distributions int i; 12*2c2f96dcSApple OSS Distributions }; 13*2c2f96dcSApple OSS Distributions 14*2c2f96dcSApple OSS Distributions template <typename T> 15*2c2f96dcSApple OSS Distributions static void tests()16*2c2f96dcSApple OSS Distributionstests() 17*2c2f96dcSApple OSS Distributions { 18*2c2f96dcSApple OSS Distributions T obj{3}; 19*2c2f96dcSApple OSS Distributions 20*2c2f96dcSApple OSS Distributions // Assign nullptr to non-null 21*2c2f96dcSApple OSS Distributions { 22*2c2f96dcSApple OSS Distributions tracked_shared_ptr<T> ptr(&obj, libkern::retain); 23*2c2f96dcSApple OSS Distributions tracking_policy::reset(); 24*2c2f96dcSApple OSS Distributions tracked_shared_ptr<T>& ref = (ptr = nullptr); 25*2c2f96dcSApple OSS Distributions CHECK(tracking_policy::releases == 1); 26*2c2f96dcSApple OSS Distributions CHECK(tracking_policy::retains == 0); 27*2c2f96dcSApple OSS Distributions CHECK(&ref == &ptr); 28*2c2f96dcSApple OSS Distributions CHECK(ptr.get() == nullptr); 29*2c2f96dcSApple OSS Distributions } 30*2c2f96dcSApple OSS Distributions 31*2c2f96dcSApple OSS Distributions // Assign nullptr to null 32*2c2f96dcSApple OSS Distributions { 33*2c2f96dcSApple OSS Distributions tracked_shared_ptr<T> ptr = nullptr; 34*2c2f96dcSApple OSS Distributions tracking_policy::reset(); 35*2c2f96dcSApple OSS Distributions tracked_shared_ptr<T>& ref = (ptr = nullptr); 36*2c2f96dcSApple OSS Distributions CHECK(tracking_policy::releases == 0); 37*2c2f96dcSApple OSS Distributions CHECK(tracking_policy::retains == 0); 38*2c2f96dcSApple OSS Distributions CHECK(&ref == &ptr); 39*2c2f96dcSApple OSS Distributions CHECK(ptr.get() == nullptr); 40*2c2f96dcSApple OSS Distributions } 41*2c2f96dcSApple OSS Distributions } 42*2c2f96dcSApple OSS Distributions 43*2c2f96dcSApple OSS Distributions T_DECL(assign_nullptr, "intrusive_shared_ptr.assign.nullptr") { 44*2c2f96dcSApple OSS Distributions tests<T>(); 45*2c2f96dcSApple OSS Distributions tests<T const>(); 46*2c2f96dcSApple OSS Distributions } 47