]> git.saurik.com Git - apple/xnu.git/blob - tests/intrusive_shared_ptr_src/dtor.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / intrusive_shared_ptr_src / dtor.cpp
1 //
2 // Tests for
3 // ~intrusive_shared_ptr();
4 //
5
6 #include <libkern/c++/intrusive_shared_ptr.h>
7 #include <darwintest.h>
8 #include <darwintest_utils.h>
9 #include "test_policy.h"
10
11 struct T { int i; };
12
13 T_DECL(dtor, "intrusive_shared_ptr.dtor") {
14 // Destroy a non-null shared pointer
15 {
16 T obj{0};
17 test_policy::retain_count = 3;
18
19 {
20 libkern::intrusive_shared_ptr<T, test_policy> ptr(&obj, libkern::no_retain);
21 CHECK(test_policy::retain_count == 3);
22 }
23
24 CHECK(test_policy::retain_count == 2);
25 }
26
27 // Destroy a null shared pointer
28 {
29 test_policy::retain_count = 3;
30
31 {
32 libkern::intrusive_shared_ptr<T, test_policy> ptr = nullptr;
33 CHECK(test_policy::retain_count == 3);
34 }
35
36 CHECK(test_policy::retain_count == 3); // not decremented
37 }
38 }