]>
git.saurik.com Git - apple/xnu.git/blob - tests/intrusive_shared_ptr_src/reset.no_retain.cpp
3 // void reset(pointer p, no_retain_t) noexcept;
6 #include <libkern/c++/intrusive_shared_ptr.h>
7 #include <darwintest.h>
8 #include "test_policy.h"
21 // reset() non-null shared pointer to non-null raw pointer
23 tracked_shared_ptr
<T
> ptr(&obj1
, libkern::retain
);
24 tracking_policy::reset();
25 ptr
.reset(&obj2
, libkern::no_retain
);
26 CHECK(tracking_policy::releases
== 1);
27 CHECK(tracking_policy::retains
== 0);
28 CHECK(ptr
.get() == &obj2
);
31 // reset() null shared pointer to non-null raw pointer
33 tracked_shared_ptr
<T
> ptr
= nullptr;
34 tracking_policy::reset();
35 ptr
.reset(&obj2
, libkern::no_retain
);
36 CHECK(tracking_policy::releases
== 0);
37 CHECK(tracking_policy::retains
== 0);
38 CHECK(ptr
.get() == &obj2
);
41 // reset() non-null shared pointer to null raw pointer
43 tracked_shared_ptr
<T
> ptr(&obj1
, libkern::retain
);
44 tracking_policy::reset();
45 ptr
.reset(nullptr, libkern::no_retain
);
46 CHECK(tracking_policy::releases
== 1);
47 CHECK(tracking_policy::retains
== 0);
48 CHECK(ptr
.get() == nullptr);
51 // reset() null shared pointer to null raw pointer
53 tracked_shared_ptr
<T
> ptr
= nullptr;
54 tracking_policy::reset();
55 ptr
.reset(nullptr, libkern::no_retain
);
56 CHECK(tracking_policy::releases
== 0);
57 CHECK(tracking_policy::retains
== 0);
58 CHECK(ptr
.get() == nullptr);
61 // reset() as a self-reference
63 tracked_shared_ptr
<T
> ptr
;
64 tracked_shared_ptr
<T
> ptr2
;
65 CHECK(ptr
.reset(&obj2
, libkern::no_retain
));
67 // check short-circuiting
68 bool ok
= (ptr
.reset() && ptr2
.reset(&obj1
, libkern::no_retain
));
69 CHECK(ptr2
.get() == nullptr);
73 T_DECL(reset_no_retain
, "intrusive_shared_ptr.reset.no_retain") {