]>
Commit | Line | Data |
---|---|---|
f427ee49 A |
1 | // |
2 | // Tests for | |
3 | // pointer detach() noexcept; | |
4 | // | |
5 | ||
6 | #include <libkern/c++/intrusive_shared_ptr.h> | |
7 | #include <darwintest.h> | |
8 | #include "test_policy.h" | |
9 | ||
10 | struct T { | |
11 | int i; | |
12 | }; | |
13 | ||
14 | template <typename T> | |
15 | static void | |
16 | tests() | |
17 | { | |
18 | T obj{3}; | |
19 | ||
20 | tracking_policy::reset(); | |
21 | tracked_shared_ptr<T> ptr(&obj, libkern::retain); | |
22 | T* raw = ptr.detach(); | |
23 | CHECK(raw == &obj); | |
24 | CHECK(ptr.get() == nullptr); // ptr was set to null | |
25 | CHECK(tracking_policy::retains == 1); | |
26 | CHECK(tracking_policy::releases == 0); | |
27 | } | |
28 | ||
29 | T_DECL(detach, "intrusive_shared_ptr.detach") { | |
30 | tests<T>(); | |
31 | tests<T const>(); | |
32 | } |