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