]> git.saurik.com Git - apple/xnu.git/blame - tests/intrusive_shared_ptr_src/deref.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / intrusive_shared_ptr_src / deref.cpp
CommitLineData
f427ee49
A
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
11struct T {
12 int i;
13};
14
15template <typename T>
16static void
17tests()
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
35T_DECL(deref, "intrusive_shared_ptr.deref") {
36 tests<T>();
37 tests<T const>();
38}