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