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