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