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