]> git.saurik.com Git - apple/xnu.git/blob - tests/intrusive_shared_ptr_src/deref.cpp
xnu-7195.81.3.tar.gz
[apple/xnu.git] / tests / intrusive_shared_ptr_src / deref.cpp
1 //
2 // Tests for
3 // T& operator*() const noexcept;
4 // T* operator->() const noexcept;
5 //
6
7 #include <libkern/c++/intrusive_shared_ptr.h>
8 #include <darwintest.h>
9 #include "test_policy.h"
10
11 struct T {
12 int i;
13 };
14
15 template <typename T>
16 static void
17 tests()
18 {
19 T obj{3};
20 tracked_shared_ptr<T> ptr(&obj, libkern::no_retain);
21
22 {
23 T& ref = *ptr;
24 CHECK(&ref == &obj);
25 CHECK(ref.i == 3);
26 }
27
28 {
29 int const& ref = ptr->i;
30 CHECK(&ref == &obj.i);
31 CHECK(ref == 3);
32 }
33 }
34
35 T_DECL(deref, "intrusive_shared_ptr.deref") {
36 tests<T>();
37 tests<T const>();
38 }