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