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 
11 struct T {
12 	int i;
13 };
14 
15 template <typename T>
16 static constexpr auto
can_call_get_on_temporary(int)17 can_call_get_on_temporary(int)->decltype(std::declval<test_shared_ptr<T> >().get(), bool ())
18 {
19 	return true;
20 }
21 
22 template <typename T>
23 static constexpr auto
can_call_get_on_temporary(...)24 can_call_get_on_temporary(...)->bool
25 {
26 	return false;
27 }
28 
29 template <typename T>
30 static void
tests()31 tests()
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 
47 T_DECL(get, "intrusive_shared_ptr.get", T_META_TAG_VM_PREFERRED) {
48 	tests<T>();
49 	tests<T const>();
50 }
51