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