1bb611c8fSApple OSS Distributions //
2bb611c8fSApple OSS Distributions // Tests for
3bb611c8fSApple OSS Distributions // template <typename T, typename U, typename R>
4bb611c8fSApple OSS Distributions // bool operator==(intrusive_shared_ptr<T, R> const& x, U* y);
5bb611c8fSApple OSS Distributions //
6bb611c8fSApple OSS Distributions // template <typename T, typename U, typename R>
7bb611c8fSApple OSS Distributions // bool operator!=(intrusive_shared_ptr<T, R> const& x, U* y);
8bb611c8fSApple OSS Distributions //
9bb611c8fSApple OSS Distributions // template <typename T, typename U, typename R>
10bb611c8fSApple OSS Distributions // bool operator==(T* x, intrusive_shared_ptr<U, R> const& y);
11bb611c8fSApple OSS Distributions //
12bb611c8fSApple OSS Distributions // template <typename T, typename U, typename R>
13bb611c8fSApple OSS Distributions // bool operator!=(T* x, intrusive_shared_ptr<U, R> const& y);
14bb611c8fSApple OSS Distributions //
15bb611c8fSApple OSS Distributions
16bb611c8fSApple OSS Distributions #include <libkern/c++/intrusive_shared_ptr.h>
17bb611c8fSApple OSS Distributions #include <darwintest.h>
18bb611c8fSApple OSS Distributions #include "test_policy.h"
19bb611c8fSApple OSS Distributions
20bb611c8fSApple OSS Distributions struct Base { int i; };
21bb611c8fSApple OSS Distributions struct Derived : Base { };
22bb611c8fSApple OSS Distributions
23bb611c8fSApple OSS Distributions struct T { int i; };
24bb611c8fSApple OSS Distributions
25bb611c8fSApple OSS Distributions template <typename T, typename U>
26bb611c8fSApple OSS Distributions static void
check_eq(T t,U u)27bb611c8fSApple OSS Distributions check_eq(T t, U u)
28bb611c8fSApple OSS Distributions {
29bb611c8fSApple OSS Distributions CHECK(t == u);
30bb611c8fSApple OSS Distributions CHECK(u == t);
31bb611c8fSApple OSS Distributions CHECK(!(t != u));
32bb611c8fSApple OSS Distributions CHECK(!(u != t));
33bb611c8fSApple OSS Distributions }
34bb611c8fSApple OSS Distributions
35bb611c8fSApple OSS Distributions template <typename T, typename U>
36bb611c8fSApple OSS Distributions static void
check_ne(T t,U u)37bb611c8fSApple OSS Distributions check_ne(T t, U u)
38bb611c8fSApple OSS Distributions {
39bb611c8fSApple OSS Distributions CHECK(!(t == u));
40bb611c8fSApple OSS Distributions CHECK(!(u == t));
41bb611c8fSApple OSS Distributions CHECK(t != u);
42bb611c8fSApple OSS Distributions CHECK(u != t);
43bb611c8fSApple OSS Distributions }
44bb611c8fSApple OSS Distributions
45bb611c8fSApple OSS Distributions template <typename T, typename TQual>
46bb611c8fSApple OSS Distributions static void
tests()47bb611c8fSApple OSS Distributions tests()
48bb611c8fSApple OSS Distributions {
49bb611c8fSApple OSS Distributions T obj1{1};
50bb611c8fSApple OSS Distributions T obj2{2};
51bb611c8fSApple OSS Distributions
52bb611c8fSApple OSS Distributions {
53bb611c8fSApple OSS Distributions test_shared_ptr<TQual> const a(&obj1, libkern::no_retain);
54bb611c8fSApple OSS Distributions TQual* b = &obj2;
55bb611c8fSApple OSS Distributions check_ne(a, b);
56bb611c8fSApple OSS Distributions }
57bb611c8fSApple OSS Distributions
58bb611c8fSApple OSS Distributions {
59bb611c8fSApple OSS Distributions test_shared_ptr<TQual> const a(&obj1, libkern::no_retain);
60bb611c8fSApple OSS Distributions TQual* b = &obj1;
61bb611c8fSApple OSS Distributions check_eq(a, b);
62bb611c8fSApple OSS Distributions }
63bb611c8fSApple OSS Distributions
64bb611c8fSApple OSS Distributions {
65bb611c8fSApple OSS Distributions test_shared_ptr<TQual> const a = nullptr;
66bb611c8fSApple OSS Distributions TQual* b = &obj2;
67bb611c8fSApple OSS Distributions check_ne(a, b);
68bb611c8fSApple OSS Distributions }
69bb611c8fSApple OSS Distributions
70bb611c8fSApple OSS Distributions {
71bb611c8fSApple OSS Distributions test_shared_ptr<TQual> const a(&obj1, libkern::no_retain);
72bb611c8fSApple OSS Distributions TQual* b = nullptr;
73bb611c8fSApple OSS Distributions check_ne(a, b);
74bb611c8fSApple OSS Distributions }
75bb611c8fSApple OSS Distributions
76bb611c8fSApple OSS Distributions {
77bb611c8fSApple OSS Distributions test_shared_ptr<TQual> const a = nullptr;
78bb611c8fSApple OSS Distributions TQual* b = nullptr;
79bb611c8fSApple OSS Distributions check_eq(a, b);
80bb611c8fSApple OSS Distributions }
81bb611c8fSApple OSS Distributions }
82bb611c8fSApple OSS Distributions
83bb611c8fSApple OSS Distributions template <typename T, typename RelatedT>
84bb611c8fSApple OSS Distributions static void
tests_convert()85bb611c8fSApple OSS Distributions tests_convert()
86bb611c8fSApple OSS Distributions {
87bb611c8fSApple OSS Distributions T obj{1};
88bb611c8fSApple OSS Distributions
89bb611c8fSApple OSS Distributions {
90bb611c8fSApple OSS Distributions test_shared_ptr<T> const a(&obj, libkern::no_retain);
91bb611c8fSApple OSS Distributions RelatedT* b = &obj;
92bb611c8fSApple OSS Distributions check_eq(a, b);
93bb611c8fSApple OSS Distributions }
94bb611c8fSApple OSS Distributions
95bb611c8fSApple OSS Distributions {
96bb611c8fSApple OSS Distributions test_shared_ptr<RelatedT> const a(&obj, libkern::no_retain);
97bb611c8fSApple OSS Distributions T* b = &obj;
98bb611c8fSApple OSS Distributions check_eq(a, b);
99bb611c8fSApple OSS Distributions }
100bb611c8fSApple OSS Distributions }
101bb611c8fSApple OSS Distributions
102*8d741a5dSApple OSS Distributions T_DECL(compare_equal_raw, "intrusive_shared_ptr.compare.equal.raw", T_META_TAG_VM_PREFERRED) {
103bb611c8fSApple OSS Distributions tests<T, T>();
104bb611c8fSApple OSS Distributions tests<T, T const>();
105bb611c8fSApple OSS Distributions tests_convert<Derived, Base>();
106bb611c8fSApple OSS Distributions tests_convert<Derived, Base const>();
107bb611c8fSApple OSS Distributions }
108