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