]>
git.saurik.com Git - apple/xnu.git/blob - tests/intrusive_shared_ptr_src/reset.cpp
3 // void reset() noexcept;
6 #include <libkern/c++/intrusive_shared_ptr.h>
7 #include <darwintest.h>
8 #include "test_policy.h"
20 // reset() on a non-null shared pointer
22 tracked_shared_ptr
<T
> ptr(&obj
, libkern::retain
);
23 tracking_policy::reset();
25 CHECK(tracking_policy::releases
== 1);
26 CHECK(tracking_policy::retains
== 0);
27 CHECK(ptr
.get() == nullptr);
30 // reset() on a null shared pointer
32 tracked_shared_ptr
<T
> ptr
= nullptr;
33 tracking_policy::reset();
35 CHECK(tracking_policy::releases
== 0);
36 CHECK(tracking_policy::retains
== 0);
37 CHECK(ptr
.get() == nullptr);
40 // reset() as a self-reference
42 tracked_shared_ptr
<T
> ptr(&obj
, libkern::retain
);
43 tracked_shared_ptr
<T
> ptr2(&obj
, libkern::retain
);
46 CHECK(&ptr
.reset() == &ptr
);
48 // check short-circuiting
49 bool ok
= (ptr
.reset() && !ptr2
.reset());
50 CHECK(ptr2
.get() != nullptr);
54 T_DECL(reset
, "intrusive_shared_ptr.reset") {