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