]> git.saurik.com Git - apple/xnu.git/blame - tests/intrusive_shared_ptr_src/detach.cpp
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / intrusive_shared_ptr_src / detach.cpp
CommitLineData
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
10struct T {
11 int i;
12};
13
14template <typename T>
15static void
16tests()
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
29T_DECL(detach, "intrusive_shared_ptr.detach") {
30 tests<T>();
31 tests<T const>();
32}