]>
Commit | Line | Data |
---|---|---|
f427ee49 A |
1 | // |
2 | // Tests for | |
3 | // intrusive_shared_ptr& operator=(std::nullptr_t); | |
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 | // Assign nullptr to non-null | |
21 | { | |
22 | tracked_shared_ptr<T> ptr(&obj, libkern::retain); | |
23 | tracking_policy::reset(); | |
24 | tracked_shared_ptr<T>& ref = (ptr = nullptr); | |
25 | CHECK(tracking_policy::releases == 1); | |
26 | CHECK(tracking_policy::retains == 0); | |
27 | CHECK(&ref == &ptr); | |
28 | CHECK(ptr.get() == nullptr); | |
29 | } | |
30 | ||
31 | // Assign nullptr to null | |
32 | { | |
33 | tracked_shared_ptr<T> ptr = nullptr; | |
34 | tracking_policy::reset(); | |
35 | tracked_shared_ptr<T>& ref = (ptr = nullptr); | |
36 | CHECK(tracking_policy::releases == 0); | |
37 | CHECK(tracking_policy::retains == 0); | |
38 | CHECK(&ref == &ptr); | |
39 | CHECK(ptr.get() == nullptr); | |
40 | } | |
41 | } | |
42 | ||
43 | T_DECL(assign_nullptr, "intrusive_shared_ptr.assign.nullptr") { | |
44 | tests<T>(); | |
45 | tests<T const>(); | |
46 | } |