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