xref: /xnu-12377.61.12/tests/safe_allocation_src/compare.equal.nullptr.cpp (revision 4d495c6e23c53686cf65f45067f79024cf5dcee8)
1*4d495c6eSApple OSS Distributions //
2*4d495c6eSApple OSS Distributions // Tests for
3*4d495c6eSApple OSS Distributions //  template <typename T, typename Alloc, typename TrappingPolicy>
4*4d495c6eSApple OSS Distributions //  bool operator==(std::nullptr_t, safe_allocation<T, Alloc, TrappingPolicy> const& x);
5*4d495c6eSApple OSS Distributions //
6*4d495c6eSApple OSS Distributions //  template <typename T, typename Alloc, typename TrappingPolicy>
7*4d495c6eSApple OSS Distributions //  bool operator!=(std::nullptr_t, safe_allocation<T, Alloc, TrappingPolicy> const& x);
8*4d495c6eSApple OSS Distributions //
9*4d495c6eSApple OSS Distributions //  template <typename T, typename Alloc, typename TrappingPolicy>
10*4d495c6eSApple OSS Distributions //  bool operator==(safe_allocation<T, Alloc, TrappingPolicy> const& x, std::nullptr_t);
11*4d495c6eSApple OSS Distributions //
12*4d495c6eSApple OSS Distributions //  template <typename T, typename Alloc, typename TrappingPolicy>
13*4d495c6eSApple OSS Distributions //  bool operator!=(safe_allocation<T, Alloc, TrappingPolicy> const& x, std::nullptr_t);
14*4d495c6eSApple OSS Distributions //
15*4d495c6eSApple OSS Distributions 
16*4d495c6eSApple OSS Distributions #include <libkern/c++/safe_allocation.h>
17*4d495c6eSApple OSS Distributions #include <darwintest.h>
18*4d495c6eSApple OSS Distributions #include "test_utils.h"
19*4d495c6eSApple OSS Distributions 
20*4d495c6eSApple OSS Distributions struct T { };
21*4d495c6eSApple OSS Distributions 
22*4d495c6eSApple OSS Distributions template <typename T>
23*4d495c6eSApple OSS Distributions static void
tests()24*4d495c6eSApple OSS Distributions tests()
25*4d495c6eSApple OSS Distributions {
26*4d495c6eSApple OSS Distributions 	{
27*4d495c6eSApple OSS Distributions 		test_safe_allocation<T> const array(10, libkern::allocate_memory);
28*4d495c6eSApple OSS Distributions 		CHECK(!(array == nullptr));
29*4d495c6eSApple OSS Distributions 		CHECK(!(nullptr == array));
30*4d495c6eSApple OSS Distributions 		CHECK(array != nullptr);
31*4d495c6eSApple OSS Distributions 		CHECK(nullptr != array);
32*4d495c6eSApple OSS Distributions 	}
33*4d495c6eSApple OSS Distributions 	{
34*4d495c6eSApple OSS Distributions 		test_safe_allocation<T> const array = nullptr;
35*4d495c6eSApple OSS Distributions 		CHECK(array == nullptr);
36*4d495c6eSApple OSS Distributions 		CHECK(nullptr == array);
37*4d495c6eSApple OSS Distributions 		CHECK(!(array != nullptr));
38*4d495c6eSApple OSS Distributions 		CHECK(!(nullptr != array));
39*4d495c6eSApple OSS Distributions 	}
40*4d495c6eSApple OSS Distributions }
41*4d495c6eSApple OSS Distributions 
42*4d495c6eSApple OSS Distributions T_DECL(compare_equal_nullptr, "safe_allocation.compare.equal.nullptr", T_META_TAG_VM_PREFERRED) {
43*4d495c6eSApple OSS Distributions 	tests<T>();
44*4d495c6eSApple OSS Distributions 	tests<T const>();
45*4d495c6eSApple OSS Distributions }
46