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