1*bb611c8fSApple OSS Distributions //
2*bb611c8fSApple OSS Distributions // Tests for
3*bb611c8fSApple OSS Distributions //  template <typename T, typename R>
4*bb611c8fSApple OSS Distributions //  bool operator==(intrusive_shared_ptr<T, R> const& x, std::nullptr_t);
5*bb611c8fSApple OSS Distributions //
6*bb611c8fSApple OSS Distributions //  template <typename T, typename R>
7*bb611c8fSApple OSS Distributions //  bool operator!=(intrusive_shared_ptr<T, R> const& x, std::nullptr_t);
8*bb611c8fSApple OSS Distributions //
9*bb611c8fSApple OSS Distributions //  template <typename T, typename R>
10*bb611c8fSApple OSS Distributions //  bool operator==(std::nullptr_t, intrusive_shared_ptr<T, R> const& x);
11*bb611c8fSApple OSS Distributions //
12*bb611c8fSApple OSS Distributions //  template <typename T, typename R>
13*bb611c8fSApple OSS Distributions //  bool operator!=(std::nullptr_t, intrusive_shared_ptr<T, R> const& x);
14*bb611c8fSApple OSS Distributions //
15*bb611c8fSApple OSS Distributions 
16*bb611c8fSApple OSS Distributions #include <libkern/c++/intrusive_shared_ptr.h>
17*bb611c8fSApple OSS Distributions #include <darwintest.h>
18*bb611c8fSApple OSS Distributions #include "test_policy.h"
19*bb611c8fSApple OSS Distributions 
20*bb611c8fSApple OSS Distributions struct T { int i; };
21*bb611c8fSApple OSS Distributions 
22*bb611c8fSApple OSS Distributions template <typename T, typename U>
23*bb611c8fSApple OSS Distributions static void
24*bb611c8fSApple OSS Distributions check_eq(T t, U u)
25*bb611c8fSApple OSS Distributions {
26*bb611c8fSApple OSS Distributions 	CHECK(t == u);
27*bb611c8fSApple OSS Distributions 	CHECK(u == t);
28*bb611c8fSApple OSS Distributions 	CHECK(!(t != u));
29*bb611c8fSApple OSS Distributions 	CHECK(!(u != t));
30*bb611c8fSApple OSS Distributions }
31*bb611c8fSApple OSS Distributions 
32*bb611c8fSApple OSS Distributions template <typename T, typename U>
33*bb611c8fSApple OSS Distributions static void
34*bb611c8fSApple OSS Distributions check_ne(T t, U u)
35*bb611c8fSApple OSS Distributions {
36*bb611c8fSApple OSS Distributions 	CHECK(!(t == u));
37*bb611c8fSApple OSS Distributions 	CHECK(!(u == t));
38*bb611c8fSApple OSS Distributions 	CHECK(t != u);
39*bb611c8fSApple OSS Distributions 	CHECK(u != t);
40*bb611c8fSApple OSS Distributions }
41*bb611c8fSApple OSS Distributions 
42*bb611c8fSApple OSS Distributions template <typename T, typename TQual>
43*bb611c8fSApple OSS Distributions static void
44*bb611c8fSApple OSS Distributions tests()
45*bb611c8fSApple OSS Distributions {
46*bb611c8fSApple OSS Distributions 	T obj{3};
47*bb611c8fSApple OSS Distributions 
48*bb611c8fSApple OSS Distributions 	{
49*bb611c8fSApple OSS Distributions 		test_shared_ptr<TQual> const a(&obj, libkern::no_retain);
50*bb611c8fSApple OSS Distributions 		check_ne(a, nullptr);
51*bb611c8fSApple OSS Distributions 	}
52*bb611c8fSApple OSS Distributions 
53*bb611c8fSApple OSS Distributions 	{
54*bb611c8fSApple OSS Distributions 		test_shared_ptr<TQual> const a = nullptr;
55*bb611c8fSApple OSS Distributions 		check_eq(a, nullptr);
56*bb611c8fSApple OSS Distributions 	}
57*bb611c8fSApple OSS Distributions }
58*bb611c8fSApple OSS Distributions 
59*bb611c8fSApple OSS Distributions T_DECL(compare_equal_nullptr, "intrusive_shared_ptr.compare.equal.nullptr") {
60*bb611c8fSApple OSS Distributions 	tests<T, T>();
61*bb611c8fSApple OSS Distributions 	tests<T, T const>();
62*bb611c8fSApple OSS Distributions }
63