1*bb611c8fSApple OSS Distributions //
2*bb611c8fSApple OSS Distributions // Tests for
3*bb611c8fSApple OSS Distributions //  template <typename T, typename Policy>
4*bb611c8fSApple OSS Distributions //  bool operator==(std::nullptr_t, bounded_ptr<T, Policy> const& p);
5*bb611c8fSApple OSS Distributions //
6*bb611c8fSApple OSS Distributions //  template <typename T, typename Policy>
7*bb611c8fSApple OSS Distributions //  bool operator!=(std::nullptr_t, bounded_ptr<T, Policy> const& p);
8*bb611c8fSApple OSS Distributions //
9*bb611c8fSApple OSS Distributions //  template <typename T, typename Policy>
10*bb611c8fSApple OSS Distributions //  bool operator==(bounded_ptr<T, Policy> const& p, std::nullptr_t);
11*bb611c8fSApple OSS Distributions //
12*bb611c8fSApple OSS Distributions //  template <typename T, typename Policy>
13*bb611c8fSApple OSS Distributions //  bool operator!=(bounded_ptr<T, Policy> const& p, std::nullptr_t);
14*bb611c8fSApple OSS Distributions //
15*bb611c8fSApple OSS Distributions 
16*bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_ptr.h>
17*bb611c8fSApple OSS Distributions #include <darwintest.h>
18*bb611c8fSApple OSS Distributions #include <darwintest_utils.h>
19*bb611c8fSApple OSS Distributions #include "test_utils.h"
20*bb611c8fSApple OSS Distributions 
21*bb611c8fSApple OSS Distributions #define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
22*bb611c8fSApple OSS Distributions 
23*bb611c8fSApple OSS Distributions struct T { };
24*bb611c8fSApple OSS Distributions 
25*bb611c8fSApple OSS Distributions struct non_default_policy {
26*bb611c8fSApple OSS Distributions 	static constexpr void
27*bb611c8fSApple OSS Distributions 	trap(char const*)
28*bb611c8fSApple OSS Distributions 	{
29*bb611c8fSApple OSS Distributions 	}
30*bb611c8fSApple OSS Distributions };
31*bb611c8fSApple OSS Distributions 
32*bb611c8fSApple OSS Distributions template <typename T, typename QualT>
33*bb611c8fSApple OSS Distributions static void
34*bb611c8fSApple OSS Distributions tests()
35*bb611c8fSApple OSS Distributions {
36*bb611c8fSApple OSS Distributions 	T t;
37*bb611c8fSApple OSS Distributions 
38*bb611c8fSApple OSS Distributions 	{
39*bb611c8fSApple OSS Distributions 		test_bounded_ptr<QualT> const ptr(&t, &t, &t + 1);
40*bb611c8fSApple OSS Distributions 		_assert(!(ptr == nullptr));
41*bb611c8fSApple OSS Distributions 		_assert(!(nullptr == ptr));
42*bb611c8fSApple OSS Distributions 		_assert(ptr != nullptr);
43*bb611c8fSApple OSS Distributions 		_assert(nullptr != ptr);
44*bb611c8fSApple OSS Distributions 	}
45*bb611c8fSApple OSS Distributions 	{
46*bb611c8fSApple OSS Distributions 		test_bounded_ptr<QualT> const ptr = nullptr;
47*bb611c8fSApple OSS Distributions 		_assert(ptr == nullptr);
48*bb611c8fSApple OSS Distributions 		_assert(nullptr == ptr);
49*bb611c8fSApple OSS Distributions 		_assert(!(ptr != nullptr));
50*bb611c8fSApple OSS Distributions 		_assert(!(nullptr != ptr));
51*bb611c8fSApple OSS Distributions 	}
52*bb611c8fSApple OSS Distributions 
53*bb611c8fSApple OSS Distributions 	// Test with a custom policy
54*bb611c8fSApple OSS Distributions 	{
55*bb611c8fSApple OSS Distributions 		libkern::bounded_ptr<QualT, non_default_policy> const ptr = nullptr;
56*bb611c8fSApple OSS Distributions 		_assert(ptr == nullptr);
57*bb611c8fSApple OSS Distributions 		_assert(nullptr == ptr);
58*bb611c8fSApple OSS Distributions 		_assert(!(ptr != nullptr));
59*bb611c8fSApple OSS Distributions 		_assert(!(nullptr != ptr));
60*bb611c8fSApple OSS Distributions 	}
61*bb611c8fSApple OSS Distributions }
62*bb611c8fSApple OSS Distributions 
63*bb611c8fSApple OSS Distributions T_DECL(compare_equal_nullptr, "bounded_ptr.compare.equal.nullptr") {
64*bb611c8fSApple OSS Distributions 	tests<T, T>();
65*bb611c8fSApple OSS Distributions 	tests<T, T const>();
66*bb611c8fSApple OSS Distributions 	tests<T, T volatile>();
67*bb611c8fSApple OSS Distributions 	tests<T, T const volatile>();
68*bb611c8fSApple OSS Distributions }
69