]> git.saurik.com Git - apple/xnu.git/blame - tests/intrusive_shared_ptr_src/get.cpp
xnu-7195.81.3.tar.gz
[apple/xnu.git] / tests / intrusive_shared_ptr_src / get.cpp
CommitLineData
f427ee49
A
1//
2// Tests for
3// pointer get() const noexcept;
4//
5
6#include <libkern/c++/intrusive_shared_ptr.h>
7#include "test_policy.h"
8#include <darwintest.h>
9#include <utility>
10
11struct T {
12 int i;
13};
14
15template <typename T>
16static constexpr auto
17can_call_get_on_temporary(int)->decltype(std::declval<test_shared_ptr<T> >().get(), bool ())
18{
19 return true;
20}
21
22template <typename T>
23static constexpr auto
24can_call_get_on_temporary(...)->bool
25{
26 return false;
27}
28
29template <typename T>
30static void
31tests()
32{
33 {
34 T obj{3};
35 tracking_policy::reset();
36 tracked_shared_ptr<T> const ptr(&obj, libkern::retain);
37 T* raw = ptr.get();
38 CHECK(raw == &obj);
39 CHECK(ptr.get() == raw); // ptr didn't change
40 CHECK(tracking_policy::retains == 1);
41 CHECK(tracking_policy::releases == 0);
42 }
43
44 static_assert(!can_call_get_on_temporary<T>(int{}), "");
45}
46
47T_DECL(get, "intrusive_shared_ptr.get") {
48 tests<T>();
49 tests<T const>();
50}