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, intrusive_shared_ptr<U, R> const& 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, intrusive_shared_ptr<U, R> const& y);
8bb611c8fSApple OSS Distributions //
9bb611c8fSApple OSS Distributions 
10bb611c8fSApple OSS Distributions #include <libkern/c++/intrusive_shared_ptr.h>
11bb611c8fSApple OSS Distributions #include <darwintest.h>
12bb611c8fSApple OSS Distributions #include "test_policy.h"
13bb611c8fSApple OSS Distributions 
14bb611c8fSApple OSS Distributions struct Base { int i; };
15bb611c8fSApple OSS Distributions struct Derived : Base { };
16bb611c8fSApple OSS Distributions 
17bb611c8fSApple OSS Distributions struct T { int i; };
18bb611c8fSApple OSS Distributions 
19bb611c8fSApple OSS Distributions template <typename T, typename U>
20bb611c8fSApple OSS Distributions static void
check_eq(T t,U u)21bb611c8fSApple OSS Distributions check_eq(T t, U u)
22bb611c8fSApple OSS Distributions {
23bb611c8fSApple OSS Distributions 	CHECK(t == u);
24bb611c8fSApple OSS Distributions 	CHECK(u == t);
25bb611c8fSApple OSS Distributions 	CHECK(!(t != u));
26bb611c8fSApple OSS Distributions 	CHECK(!(u != t));
27bb611c8fSApple OSS Distributions }
28bb611c8fSApple OSS Distributions 
29bb611c8fSApple OSS Distributions template <typename T, typename U>
30bb611c8fSApple OSS Distributions static void
check_ne(T t,U u)31bb611c8fSApple OSS Distributions check_ne(T t, U u)
32bb611c8fSApple OSS Distributions {
33bb611c8fSApple OSS Distributions 	CHECK(!(t == u));
34bb611c8fSApple OSS Distributions 	CHECK(!(u == t));
35bb611c8fSApple OSS Distributions 	CHECK(t != u);
36bb611c8fSApple OSS Distributions 	CHECK(u != t);
37bb611c8fSApple OSS Distributions }
38bb611c8fSApple OSS Distributions 
39bb611c8fSApple OSS Distributions template <typename T, typename TQual>
40bb611c8fSApple OSS Distributions static void
tests()41bb611c8fSApple OSS Distributions tests()
42bb611c8fSApple OSS Distributions {
43bb611c8fSApple OSS Distributions 	T obj1{1};
44bb611c8fSApple OSS Distributions 	T obj2{2};
45bb611c8fSApple OSS Distributions 
46bb611c8fSApple OSS Distributions 	{
47bb611c8fSApple OSS Distributions 		test_shared_ptr<TQual> const a(&obj1, libkern::no_retain);
48bb611c8fSApple OSS Distributions 		test_shared_ptr<TQual> const b(&obj2, libkern::no_retain);
49bb611c8fSApple OSS Distributions 		check_ne(a, b);
50bb611c8fSApple OSS Distributions 	}
51bb611c8fSApple OSS Distributions 
52bb611c8fSApple OSS Distributions 	{
53bb611c8fSApple OSS Distributions 		test_shared_ptr<TQual> const a(&obj1, libkern::no_retain);
54bb611c8fSApple OSS Distributions 		test_shared_ptr<TQual> const b(&obj1, libkern::no_retain);
55bb611c8fSApple OSS Distributions 		check_eq(a, b);
56bb611c8fSApple OSS Distributions 	}
57bb611c8fSApple OSS Distributions 
58bb611c8fSApple OSS Distributions 	{
59bb611c8fSApple OSS Distributions 		test_shared_ptr<TQual> const a = nullptr;
60bb611c8fSApple OSS Distributions 		test_shared_ptr<TQual> const b(&obj2, libkern::no_retain);
61bb611c8fSApple OSS Distributions 		check_ne(a, b);
62bb611c8fSApple OSS Distributions 	}
63bb611c8fSApple OSS Distributions 
64bb611c8fSApple OSS Distributions 	{
65bb611c8fSApple OSS Distributions 		test_shared_ptr<TQual> const a = nullptr;
66bb611c8fSApple OSS Distributions 		test_shared_ptr<TQual> const b = nullptr;
67bb611c8fSApple OSS Distributions 		check_eq(a, b);
68bb611c8fSApple OSS Distributions 	}
69bb611c8fSApple OSS Distributions }
70bb611c8fSApple OSS Distributions 
71bb611c8fSApple OSS Distributions template <typename T, typename RelatedT>
72bb611c8fSApple OSS Distributions static void
tests_convert()73bb611c8fSApple OSS Distributions tests_convert()
74bb611c8fSApple OSS Distributions {
75bb611c8fSApple OSS Distributions 	T obj{1};
76bb611c8fSApple OSS Distributions 	test_shared_ptr<T> const a(&obj, libkern::no_retain);
77bb611c8fSApple OSS Distributions 	test_shared_ptr<RelatedT> const b(&obj, libkern::no_retain);
78bb611c8fSApple OSS Distributions 	check_eq(a, b);
79bb611c8fSApple OSS Distributions }
80bb611c8fSApple OSS Distributions 
81*8d741a5dSApple OSS Distributions T_DECL(compare_equal, "intrusive_shared_ptr.compare.equal", T_META_TAG_VM_PREFERRED) {
82bb611c8fSApple OSS Distributions 	tests<T, T>();
83bb611c8fSApple OSS Distributions 	tests<T, T const>();
84bb611c8fSApple OSS Distributions 	tests_convert<Derived, Base>();
85bb611c8fSApple OSS Distributions 	tests_convert<Derived, Base const>();
86bb611c8fSApple OSS Distributions }
87