]>
git.saurik.com Git - apple/xnu.git/blob - tests/intrusive_shared_ptr_src/swap.cpp
3 // void swap(intrusive_shared_ptr& a, intrusive_shared_ptr& b);
6 #include <libkern/c++/intrusive_shared_ptr.h>
7 #include <darwintest.h>
8 #include "test_policy.h"
19 // Swap non-null with non-null
21 tracked_shared_ptr
<T
> a(&obj1
, libkern::retain
);
22 tracked_shared_ptr
<T
> b(&obj2
, libkern::retain
);
25 tracking_policy::reset();
27 swap(a
, b
); // ADL call
29 CHECK(tracking_policy::retains
== 0);
30 CHECK(tracking_policy::releases
== 0);
31 CHECK(a
.get() == b_raw
);
32 CHECK(b
.get() == a_raw
);
35 // Swap non-null with null
37 tracked_shared_ptr
<T
> a(&obj1
, libkern::retain
);
38 tracked_shared_ptr
<T
> b
= nullptr;
40 tracking_policy::reset();
42 swap(a
, b
); // ADL call
44 CHECK(tracking_policy::retains
== 0);
45 CHECK(tracking_policy::releases
== 0);
46 CHECK(a
.get() == nullptr);
47 CHECK(b
.get() == a_raw
);
50 // Swap null with non-null
52 tracked_shared_ptr
<T
> a
= nullptr;
53 tracked_shared_ptr
<T
> b(&obj2
, libkern::retain
);
55 tracking_policy::reset();
57 swap(a
, b
); // ADL call
59 CHECK(tracking_policy::retains
== 0);
60 CHECK(tracking_policy::releases
== 0);
61 CHECK(a
.get() == b_raw
);
62 CHECK(b
.get() == nullptr);
65 // Swap null with null
67 tracked_shared_ptr
<T
> a
= nullptr;
68 tracked_shared_ptr
<T
> b
= nullptr;
69 tracking_policy::reset();
71 swap(a
, b
); // ADL call
73 CHECK(tracking_policy::retains
== 0);
74 CHECK(tracking_policy::releases
== 0);
75 CHECK(a
.get() == nullptr);
76 CHECK(b
.get() == nullptr);
81 tracked_shared_ptr
<T
> a(&obj1
, libkern::retain
);
83 tracking_policy::reset();
85 swap(a
, a
); // ADL call
87 CHECK(tracking_policy::retains
== 0);
88 CHECK(tracking_policy::releases
== 0);
89 CHECK(a
.get() == a_raw
);
93 T_DECL(swap
, "intrusive_shared_ptr.swap") {