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